<div dir="ltr">Hey Everyone,<div><br></div><div>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.</div><div><br></div><div>When I read messages of the pipeline bus usingĀ <span style="color:rgb(88,110,117);font-family:"dejavu sans mono";font-size:9pt;background-color:rgb(238,232,213)">bus</span><span style="color:rgb(88,110,117);font-family:"dejavu sans mono";font-size:9pt;background-color:rgb(253,246,227)"> = pipeline.get_bus()</span>and <span style="color:rgb(88,110,117);font-family:"dejavu sans mono";font-size:9pt;background-color:rgb(253,246,227)">bus.timed_pop_filtered(</span><span style="font-family:"dejavu sans mono";font-size:9pt;color:rgb(108,113,196)">100000</span><span style="color:rgb(88,110,117);font-family:"dejavu sans mono";font-size:9pt;background-color:rgb(253,246,227)">, Gst.MessageType.ANY)</span>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.</div><div><br></div><div>Code:</div><div><br></div><div><pre style="color:rgb(88,110,117);font-family:"dejavu sans mono";font-size:9pt;background-color:rgb(253,246,227)"><span style="color:rgb(211,54,130);font-weight:bold">import </span>gi<br>gi.require_version(<span style="color:rgb(0,128,128);font-weight:bold">'Gst'</span>, <span style="color:rgb(0,128,128);font-weight:bold">'1.0'</span>)<br>gi.require_version(<span style="color:rgb(0,128,128);font-weight:bold">'GstBase'</span>, <span style="color:rgb(0,128,128);font-weight:bold">'1.0'</span>)<br><br><span style="color:rgb(211,54,130);font-weight:bold">import </span>os<br><span style="color:rgb(211,54,130);font-weight:bold">import </span>time<br><br><span style="color:rgb(211,54,130);font-weight:bold">from </span>gi.repository <span style="color:rgb(211,54,130);font-weight:bold">import </span>GObject, Gst, GstBase, GLib<br><br>Gst.init(<span style="color:rgb(211,54,130);font-weight:bold">None</span>)<br><br>pipeline = Gst.Pipeline.new(<span style="color:rgb(0,128,128);font-weight:bold">"mypipeline"</span>)<br><br>rtspsrc = Gst.ElementFactory.make(<span style="color:rgb(0,128,128);font-weight:bold">'rtspsrc'</span>, <span style="color:rgb(0,128,128);font-weight:bold">'rtsp'</span>)<br>rtspsrc.set_property(<span style="color:rgb(0,128,128);font-weight:bold">"location"</span>, <span style="color:rgb(0,128,128);font-weight:bold">"rtsp://<a href="http://mpv.cdn3.bigCDN.com:554/bigCDN/definst/mp4:bigbuckbunnyiphone_400.mp4">mpv.cdn3.bigCDN.com:554/bigCDN/definst/mp4:bigbuckbunnyiphone_400.mp4</a>"</span>)<br>pipeline.add(rtspsrc)<br><br>decodebin = Gst.ElementFactory.make(<span style="color:rgb(0,128,128);font-weight:bold">'decodebin'</span>, <span style="color:rgb(211,54,130);font-weight:bold">None</span>)<br>pipeline.add(decodebin)<br>decodebin.link(rtspsrc)<br><br>jpegencode = Gst.ElementFactory.make(<span style="color:rgb(0,128,128);font-weight:bold">'jpegenc'</span>, <span style="color:rgb(211,54,130);font-weight:bold">None</span>)<br>pipeline.add(jpegencode)<br>jpegencode.link(decodebin)<br><br>multifilesink = Gst.ElementFactory.make(<span style="color:rgb(0,128,128);font-weight:bold">'multifilesink'</span>, <span style="color:rgb(211,54,130);font-weight:bold">None</span>)<br>multifilesink.set_property(<span style="color:rgb(0,128,128);font-weight:bold">"location"</span>, <span style="color:rgb(0,128,128);font-weight:bold">"/share/%06d.jpg"</span>)<br>pipeline.add(multifilesink)<br>multifilesink.link(jpegencode)<br><br>ret = pipeline.set_state(Gst.State.PLAYING)<br><span style="color:rgb(211,54,130);font-weight:bold">if </span>ret == Gst.StateChangeReturn.FAILURE:<br>    <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">"Unable to set the pipeline to the playing state."</span>)<br><br><br>bus = pipeline.get_bus()<br><span style="color:rgb(147,161,161);font-style:italic"># Parse message<br></span><span style="color:rgb(211,54,130);font-weight:bold">while True</span>:<br>    message = bus.timed_pop_filtered(<span style="color:rgb(108,113,196)">100000</span>, Gst.MessageType.ANY)<br>    <span style="color:rgb(147,161,161);font-style:italic"># print "image_arr: ", image_arr<br></span><span style="color:rgb(147,161,161);font-style:italic">    # time.sleep(1)<br></span><span style="color:rgb(147,161,161);font-style:italic">    </span><span style="color:rgb(211,54,130);font-weight:bold">if </span>message:<br>        <span style="color:rgb(211,54,130);font-weight:bold">if </span>message.type == Gst.MessageType.ERROR:<br>            err, debug = message.parse_error()<br>            <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">"Error received from element %s: %s" </span>% (<br>                message.src.get_name(), err))<br>            <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">"Debugging information: %s" </span>% debug)<br>            <span style="color:rgb(211,54,130);font-weight:bold">break<br></span><span style="color:rgb(211,54,130);font-weight:bold">        elif </span>message.type == Gst.MessageType.EOS:<br>            <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">"End-Of-Stream reached."</span>)<br>            <span style="color:rgb(211,54,130);font-weight:bold">break<br></span><span style="color:rgb(211,54,130);font-weight:bold">        elif </span>message.type == Gst.MessageType.STATE_CHANGED:<br>            <span style="color:rgb(211,54,130);font-weight:bold">if </span><span style="color:rgb(0,0,128)">isinstance</span>(message.src, Gst.Pipeline):<br>                old_state, new_state, pending_state = message.parse_state_changed()<br>                <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">"Pipeline state changed from %s to %s." </span>%<br>                       (old_state.value_nick, new_state.value_nick))<br>        <span style="color:rgb(211,54,130);font-weight:bold">else</span>:<br>            <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,0,128)">str</span>(message.type))</pre></div><div>Thanks<br><div><div class="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><span><div><span style="color:rgb(0,0,0)"></span></div><div><span style="color:rgb(0,0,0)">--<br>Thomas Purchas</span></div></span></div></div></div></div></div>
</div></div>