Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display image without gtk

I would like to display an image in Python using gstreamer bindings, but without using GTK+ (I'm on ARM).

I know how to listen to music with python and 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)    

I know how to display an image with gstreamer in command line :

gst-launch-0.10 filesrc location=image.jpeg ! jpegdec ! freeze ! videoscale ! ffmpegcolorspace ! autovideosink

What I would want is the exact same thing, but using Python.

I tried some things, the code runs without errors, but nothing shows on screen.

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)

Would you have any idea that could help me?

Thanks by advance !

By the way, I also have audiotest and videotest working. Here is an example that runs fine :

# 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)
like image 796
jlengrand Avatar asked Jan 09 '12 14:01

jlengrand


1 Answers

Try with:

filepath = "/home/image.jpeg"

The location property of filesrc takes a file path, not an URI. You should check for error messages on the pipeline bus. Or run your code with GST_DEBUG=*:3 yourapp.py to see if there problems/errors.

Also, you can do

pipeline = gst.parse_launch("filesrc location=/home/foo/image.jpg ! jpegdec ! .... ")

instead of building the pipeline yourself (for simple things, anyway, parse_launch is a bit limited).

like image 94
Tim Avatar answered Oct 01 '22 11:10

Tim