Trouble decoding python gstreamer messages
Thomas Purchas
thomas at thirdeye.io
Mon Oct 31 19:12:29 UTC 2016
Hey Everyone,
I'm trying to use the Python 3 gstreamer bindings (using python-gi) to grab
and pre-process an RTSP stream. It's a pretty simple script (below) that
puts together a pipeline and tries to listen to messages from the pipeline.
When I read messages of the pipeline bus using bus = pipeline.get_bus()and
bus.timed_pop_filtered(100000, Gst.MessageType.ANY)I'm finding that the
message type is changing while I try to evaluate it. At the start of my if
block the message type == 0, but by the time I get to the else statement
the message type as changed to something else.
Code:
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstBase', '1.0')
import os
import time
from gi.repository import GObject, Gst, GstBase, GLib
Gst.init(None)
pipeline = Gst.Pipeline.new("mypipeline")
rtspsrc = Gst.ElementFactory.make('rtspsrc', 'rtsp')
rtspsrc.set_property("location",
"rtsp://mpv.cdn3.bigCDN.com:554/bigCDN/definst/mp4:bigbuckbunnyiphone_400.mp4")
pipeline.add(rtspsrc)
decodebin = Gst.ElementFactory.make('decodebin', None)
pipeline.add(decodebin)
decodebin.link(rtspsrc)
jpegencode = Gst.ElementFactory.make('jpegenc', None)
pipeline.add(jpegencode)
jpegencode.link(decodebin)
multifilesink = Gst.ElementFactory.make('multifilesink', None)
multifilesink.set_property("location", "/share/%06d.jpg")
pipeline.add(multifilesink)
multifilesink.link(jpegencode)
ret = pipeline.set_state(Gst.State.PLAYING)
if ret == Gst.StateChangeReturn.FAILURE:
print("Unable to set the pipeline to the playing state.")
bus = pipeline.get_bus()
# Parse message
while True:
message = bus.timed_pop_filtered(100000, Gst.MessageType.ANY)
# print "image_arr: ", image_arr
# time.sleep(1)
if message:
if message.type == Gst.MessageType.ERROR:
err, debug = message.parse_error()
print("Error received from element %s: %s" % (
message.src.get_name(), err))
print("Debugging information: %s" % debug)
break
elif message.type == Gst.MessageType.EOS:
print("End-Of-Stream reached.")
break
elif message.type == Gst.MessageType.STATE_CHANGED:
if isinstance(message.src, Gst.Pipeline):
old_state, new_state, pending_state =
message.parse_state_changed()
print("Pipeline state changed from %s to %s." %
(old_state.value_nick, new_state.value_nick))
else:
print(str(message.type))
Thanks
--
Thomas Purchas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20161031/486a9122/attachment-0001.html>
More information about the gstreamer-devel
mailing list