I could not seem to link more than 3 elements in a gst pipeline in Python. For example, I try to implement the following cli command in Python.
gst-launch-1.0 filesrc location=cooldance.ogg ! oggdemux ! theoradec ! videoconvert ! autovideosink
Since there is no Python equivalence for the C function gst_element_link_many(), I try to connect them one by one:
import sys, os
import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst
class TestPlayer(object):
def __init__(self):
self.player = Gst.Pipeline.new("player")
source = Gst.ElementFactory.make("filesrc", "file-source")
demux = Gst.ElementFactory.make("oggdemux", "demux1")
decode = Gst.ElementFactory.make("theoradec", "decode1")
sink = Gst.ElementFactory.make("autovideosink", "sink1")
source.set_property("location", "/ione/gsttest/sample.ogg")
# Try to implement this pipeline using multiple links.
#self.player = Gst.parse_launch ("filesrc location=sample.ogg ! oggdemux ! theoradec ! autovideosink")
self.player.add(source)
self.player.add(demux)
self.player.add(decode)
self.player.add(sink)
# link elements one by one.
source.link(demux)
demux.link(decode)
decode.link(sink)
ret = self.player.set_state(Gst.State.PLAYING)
if ret == Gst.StateChangeReturn.FAILURE:
print("ERROR: Unable to set the pipeline to the playing state")
sys.exit(1)
bus = self.player.get_bus()
terminate = False
while True:
msg = bus.timed_pop_filtered(
Gst.CLOCK_TIME_NONE,
Gst.MessageType.EOS | Gst.MessageType.ERROR) # listen on these types,.
if not msg:
continue
t = msg.type
if t == Gst.MessageType.ERROR: # exit if error.
err, dbg = msg.parse_error()
print("ERROR:", msg.src.get_name(), " ", err.message)
if dbg:
print("debugging info:", dbg)
terminate = True
elif t == Gst.MessageType.EOS: # exit if EOS
print("End-Of-Stream reached")
terminate = True
if terminate:
break
self.player.set_state(Gst.State.NULL)
if __name__ == '__main__':
Gst.init(None)
p = TestPlayer()
But the script fails with the following error messages:
ERROR: demux1 Internal data stream error.
debugging info: gstoggdemux.c(4961): gst_ogg_demux_loop (): /GstPipeline:player/GstOggDemux:demux1:
streaming stopped, reason not-linked (-1)
I found a few samples on github, but they all fail with similar error. Please advice.