不使用gtk显示图像
我想在Python中使用gstreamer库显示一张图片,但不想用GTK+(我在用ARM)。
我知道怎么用Python和gstreamer听音乐:
#!/usr/bin/python
# Simply initiates a gstreamer pipeline without gtk
import gst
import gobject
import sys
mainloop = gobject.MainLoop()
my_bin = gst.element_factory_make("playbin")
my_bin.set_property("uri", "file:///home/Lumme-Badloop.ogg")
my_bin.set_state(gst.STATE_PLAYING)
try:
mainloop.run()
except KeyboardInterrupt:
sys.exit(0)
我也知道怎么在命令行中用gstreamer显示一张图片:
gst-launch-0.10 filesrc location=image.jpeg ! jpegdec ! freeze ! videoscale ! ffmpegcolorspace ! autovideosink
我想要的就是用Python做同样的事情。
我试过一些方法,代码运行没有错误,但屏幕上什么也不显示。
pipe = gst.Pipeline("mypipe")
source = gst.element_factory_make("filesrc", "filesource")
demuxer = gst.element_factory_make("jpegdec", "demuxer")
freeze = gst.element_factory_make("freeze", "freeze")
video = gst.element_factory_make("videoscale", "scaling")
ffm = gst.element_factory_make("ffmpegcolorspace", "muxer")
sink = gst.element_factory_make("autovideosink", "output")
pipe.add(source, demuxer, freeze, video, ffm, sink)
filepath = "file:///home/image.jpeg"
pipe.get_by_name("filesource").set_property("location", filepath)
pipe.set_state(gst.STATE_PLAYING)
你有没有什么建议可以帮我?
谢谢你!
顺便说一下,我也能让音频测试和视频测试正常工作。这是一个运行良好的例子:
# Create GStreamer pipeline
pipeline = gst.Pipeline("mypipeline")
# Set up our video test source
videotestsrc = gst.element_factory_make("videotestsrc", "video")
# Add it to the pipeline
pipeline.add(videotestsrc)
# Now we need somewhere to send the video
sink = gst.element_factory_make("xvimagesink", "sink")
# Add it to the pipeline
pipeline.add(sink)
# Link the video source to the sink-xv
videotestsrc.link(sink)
pipeline.set_state(gst.STATE_PLAYING)
1 个回答
2
试试这个:
filepath = "/home/image.jpeg"
filesrc的location属性需要的是文件路径,而不是URI。你应该检查一下管道总线上的错误信息。或者可以用GST_DEBUG=*:3 yourapp.py来运行你的代码,这样可以查看是否有问题或错误。
另外,你也可以这样做:
pipeline = gst.parse_launch("filesrc location=/home/foo/image.jpg ! jpegdec ! .... ")
这样就不需要自己搭建管道了(对于简单的情况来说,parse_launch还是有点限制的)。