Linking splitmuxsrc element in GStreamer using Python

49 Views Asked by At

Hello I am trying to use following GStreamer pipeline in Python3.6

splitmuxsrc location=clip000*.mp4 ! video/x-h264,alignment=au ! h264parse ! avdec_h264 ! videoconvert ! xvimagesink

The pipeline itself is working, however when I translate it into python it gives following error:

Error: gst-stream-error-quark: Internal data stream error. (1), gstsplitmuxsrc.c(598): gst_splitmux_pad_loop (): /GstPipeline:pipeline0/GstSplitMuxSrc:muxsrc: streaming stopped, reason not-linked (-1)

It appears that linking splitmuxsrc to h264parse does not do anything.

import gi

gi.require_version('Gst', '1.0')
from gi.repository import Gst, GObject

# Initialize GStreamer
Gst.init(None)

# Create GStreamer pipeline
pipeline = Gst.Pipeline()

# Create elements
muxsrc = Gst.ElementFactory.make("splitmuxsrc", "muxsrc")
h264parse = Gst.ElementFactory.make("h264parse", "h264parse")
avdec_h264 = Gst.ElementFactory.make("avdec_h264", "avdec_h264")
videoconvert = Gst.ElementFactory.make("videoconvert", "videoconvert")
xvimagesink = Gst.ElementFactory.make("xvimagesink", "xvimagesink")

# Add elements to the pipeline
pipeline.add(muxsrc)
pipeline.add(h264parse)
pipeline.add(avdec_h264)
pipeline.add(videoconvert)
pipeline.add(xvimagesink)

# Link elements
muxsrc.link(h264parse)
h264parse.link(avdec_h264)
avdec_h264.link(videoconvert)
videoconvert.link(xvimagesink)

# Set properties if needed
muxsrc.set_property("location", "clip000*.mp4")

# Set up the main loop
loop = GObject.MainLoop()


# Bus callback function
def bus_callback(bus, message, loop):
    t = message.type
    if t == Gst.MessageType.EOS:
        print("End of Stream")
        loop.quit()
    elif t == Gst.MessageType.ERROR:
        err, debug = message.parse_error()
        print("Error: {}, {}".format(err, debug))
        loop.quit()
    return True


# Create and set up the bus
bus = pipeline.get_bus()
bus.add_signal_watch()
bus.connect("message", bus_callback, loop)

# Start the pipeline
pipeline.set_state(Gst.State.PLAYING)

# Run the main loop
try:
    loop.run()
except KeyboardInterrupt:
    pass

# Stop the pipeline
pipeline.set_state(Gst.State.NULL)

I have been trying to get and link src of splitmuxsrc with sink of h264parse however it appears that splitmuxsrc does not have static src pad. And also when I try to get request pads of splitmuxsrc (video) I get none.

1

There are 1 best solutions below

0
On BEST ANSWER

In case anyone comes across this issue I have managed to get this running. It appears that src pad for splitmuxsrc is only available once pipeline starts running and element loads clips. You need to add handler for this event like this muxsrc.connect('pad-added', self.on_pad_added, h264parse) and then in handler link newly added src pad to the rest of the pipeline, in my case to sink of h264parse element that I have passed as data for the handler.

# on pad added handler
def on_pad_added(element, pad, data):
    pad.link(data.get_static_sink())