How to use splitmuxsink in deepstream pipeline

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU): GPU
• DeepStream Version: 6.1
• JetPack Version (valid for Jetson only)
• TensorRT Version
• NVIDIA GPU Driver Version (valid for GPU only): 525.60.13
• Issue Type( questions, new requirements, bugs): question
• How to reproduce the issue ? (This is for bugs. Including which sample app is using, the configuration files content, the command line used and other details for reproducing)


def main(args):
    # Check input arguments
    if len(args) != 2:
        sys.stderr.write("usage: %s <media file or uri>\n" % args[0])
        sys.exit(1)

    # Standard GStreamer initialization
    Gst.init(None)

    # Create gstreamer elements
    # Create Pipeline element that will form a connection of other elements
    print("Creating Pipeline \n ")
    pipeline = Gst.Pipeline()

    if not pipeline:
        sys.stderr.write(" Unable to create Pipeline \n")

    # Source element for reading from the file
    print("Creating Source \n ")
    source = Gst.ElementFactory.make("filesrc", "file-source")
    if not source:
        sys.stderr.write(" Unable to create Source \n")

    # Since the data format in the input file is elementary h264 stream,
    # we need a h264parser
    print("Creating H264Parser \n")
    h264parser = Gst.ElementFactory.make("h264parse", "h264-parser")
    if not h264parser:
        sys.stderr.write(" Unable to create h264 parser \n")

    tee = Gst.ElementFactory.make("tee", "nvsink-tee")
    if not tee:
        sys.stderr.write(" Unable to create tee \n")

    queue1 = Gst.ElementFactory.make("queue", "nvtee-que1")
    if not queue1:
        sys.stderr.write(" Unable to create queue1 \n")

    queue2 = Gst.ElementFactory.make("queue", "nvtee-que2")
    if not queue2:
        sys.stderr.write(" Unable to create queue2 \n")

    splitmuxsink = Gst.ElementFactory.make("splitmuxsink", "split-mux-sink")
    if not splitmuxsink:
        sys.stderr.write("Unable to create splitmuxsink \n")
    splitmuxsink.set_property('location', './segment_%09d.mp4')
    splitmuxsink.set_property('max-size-time', 5000000000) # 5s

    filesink = Gst.ElementFactory.make("filesink", "filesink")
    filesink.set_property('location', './output.mp4')

    # Use nvdec_h264 for hardware accelerated decode on GPU
    print("Creating Decoder \n")
    decoder = Gst.ElementFactory.make("nvv4l2decoder", "nvv4l2-decoder")
    if not decoder:
        sys.stderr.write(" Unable to create Nvv4l2 Decoder \n")

    # Create nvstreammux instance to form batches from one or more sources.
    streammux = Gst.ElementFactory.make("nvstreammux", "Stream-muxer")
    if not streammux:
        sys.stderr.write(" Unable to create NvStreamMux \n")

    # Use nvinfer to run inferencing on decoder's output,
    # behaviour of inferencing is set through config file
    pgie = Gst.ElementFactory.make("nvinfer", "primary-inference")
    if not pgie:
        sys.stderr.write(" Unable to create pgie \n")

    # Use convertor to convert from NV12 to RGBA as required by nvosd
    nvvidconv = Gst.ElementFactory.make("nvvideoconvert", "convertor")
    if not nvvidconv:
        sys.stderr.write(" Unable to create nvvidconv \n")


    # Create OSD to draw on the converted RGBA buffer
    nvosd = Gst.ElementFactory.make("nvdsosd", "onscreendisplay")

    if not nvosd:
        sys.stderr.write(" Unable to create nvosd \n")

    # Finally render the osd output
    if is_aarch64():
        transform = Gst.ElementFactory.make("nvegltransform", "nvegl-transform")

    print("Creating EGLSink \n")
    sink = Gst.ElementFactory.make("fakesink", "fakesink")
    if not sink:
        sys.stderr.write(" Unable to create egl sink \n")

    print("Playing file %s " %args[1])
    source.set_property('location', args[1])
    streammux.set_property('width', 1920)
    streammux.set_property('height', 1080)
    streammux.set_property('batch-size', 1)
    streammux.set_property('batched-push-timeout', 4000000)
    pgie.set_property('config-file-path', "dstest1_pgie_config.txt")

    print("Adding elements to Pipeline \n")
    pipeline.add(source)
    pipeline.add(h264parser)
    pipeline.add(tee)
    pipeline.add(queue1)
    pipeline.add(queue2)
    pipeline.add(splitmuxsink)
    pipeline.add(decoder)
    pipeline.add(streammux)
    pipeline.add(pgie)
    pipeline.add(nvvidconv)
    pipeline.add(nvosd)
    pipeline.add(sink)
    if is_aarch64():
        pipeline.add(transform)

    # we link the elements together
    # file-source -> h264-parser -> nvh264-decoder ->
    # nvinfer -> nvvidconv -> nvosd -> video-renderer
    print("Linking elements in the Pipeline \n")
    source.link(h264parser)
    h264parser.link(tee)
    queue1.link(decoder)
    queue2.link(splitmuxsink)

    sink_pad = queue1.get_static_pad("sink")
    tee_decoder_pad = tee.get_request_pad('src_0')
    tee_splitmux_pad = tee.get_request_pad('src_1')
    if not tee_decoder_pad or not tee_splitmux_pad:
        sys.stderr.write("Unable to get request pads\n")
    tee_decoder_pad.link(sink_pad)
    sink_pad = queue2.get_static_pad("sink")
    tee_splitmux_pad.link(sink_pad)
    
    sinkpad = streammux.get_request_pad("sink_0")
    if not sinkpad:
        sys.stderr.write(" Unable to get the sink pad of streammux \n")
    srcpad = decoder.get_static_pad("src")
    if not srcpad:
        sys.stderr.write(" Unable to get source pad of decoder \n")
    srcpad.link(sinkpad)
    streammux.link(pgie)
    pgie.link(nvvidconv)
    nvvidconv.link(nvosd)
    if is_aarch64():
        nvosd.link(transform)
        transform.link(sink)
    else:
        nvosd.link(sink)

    # create an event loop and feed gstreamer bus mesages to it
    loop = GLib.MainLoop()
    bus = pipeline.get_bus()
    bus.add_signal_watch()
    bus.connect ("message", bus_call, loop)

    # Lets add probe to get informed of the meta data generated, we add probe to
    # the sink pad of the osd element, since by that time, the buffer would have
    # had got all the metadata.
    osdsinkpad = nvosd.get_static_pad("sink")
    if not osdsinkpad:
        sys.stderr.write(" Unable to get sink pad of nvosd \n")

    osdsinkpad.add_probe(Gst.PadProbeType.BUFFER, osd_sink_pad_buffer_probe, 0)

    # start play back and listen to events
    print("Starting pipeline \n")
    pipeline.set_state(Gst.State.PLAYING)
    try:
        loop.run()
    except:
        pass
    # cleanup
    pipeline.set_state(Gst.State.NULL)

if __name__ == '__main__':
    sys.exit(main(sys.argv))

I made a modification in which I added a tee to split the source and then 2 queues one for inference and one for splitmuxsink because I wanted to save the input video in smaller parts without having detections drawn on it.

This is the log:

Creating Pipeline

Creating Source

Creating H264Parser

Creating Decoder

Creating EGLSink

Playing file /opt/nvidia/deepstream/deepstream-6.1/samples/streams/sample_720p.h264
Adding elements to Pipeline

Linking elements in the Pipeline

Starting pipeline

0:00:00.281893181  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.281923494  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2942:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe minimum capture size for pixelformat MJPG
0:00:00.281934808  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.281945640  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2948:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe maximum capture size for pixelformat MJPG
0:00:00.281970520  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.281983153  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2942:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe minimum capture size for pixelformat AV10
0:00:00.281993869  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.282011434  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2948:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe maximum capture size for pixelformat AV10
0:00:00.282030428  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.282041976  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2942:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe minimum capture size for pixelformat DVX5
0:00:00.282051621  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.282062857  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2948:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe maximum capture size for pixelformat DVX5
0:00:00.282079938  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.282090997  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2942:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe minimum capture size for pixelformat DVX4
0:00:00.282101483  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.282111463  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2948:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe maximum capture size for pixelformat DVX4
0:00:00.282129399  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.282140920  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2942:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe minimum capture size for pixelformat MPG4
0:00:00.282152598  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.282183189  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2948:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe maximum capture size for pixelformat MPG4
0:00:00.282201553  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.282218339  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2942:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe minimum capture size for pixelformat MPG2
0:00:00.282230366  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.282241484  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2948:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe maximum capture size for pixelformat MPG2
0:00:00.282262446  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.282280379  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2942:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe minimum capture size for pixelformat H265
0:00:00.282291771  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.282303306  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2948:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe maximum capture size for pixelformat H265
0:00:00.282320372  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.282354166  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2942:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe minimum capture size for pixelformat VP90
0:00:00.282366832  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.282378611  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2948:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe maximum capture size for pixelformat VP90
0:00:00.282402384  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.282414037  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2942:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe minimum capture size for pixelformat VP80
0:00:00.282421293  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.282433002  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2948:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe maximum capture size for pixelformat VP80
0:00:00.282449561  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.282466005  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2942:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe minimum capture size for pixelformat H264
0:00:00.282477465  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:sink> Unable to try format: Unknown error -1
0:00:00.282485042  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2948:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:sink> Could not probe maximum capture size for pixelformat H264
0:00:00.282887412  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:src> Unable to try format: Unknown error -1
0:00:00.282900686  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2942:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:src> Could not probe minimum capture size for pixelformat NM12
0:00:00.282911686  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:3057:gst_v4l2_object_get_nearest_size:<nvv4l2-decoder:src> Unable to try format: Unknown error -1
0:00:00.282922399  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2948:gst_v4l2_object_probe_caps_for_format:<nvv4l2-decoder:src> Could not probe maximum capture size for pixelformat NM12
0:00:00.282943267  1468      0x1ca7a40 WARN                    v4l2 gstv4l2object.c:2395:gst_v4l2_object_add_interlace_mode:0x145b8d0 Failed to determine interlace mode
0:00:00.284124624  1468      0x1ca7a40 WARN                 nvinfer gstnvinfer.cpp:643:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Warning from NvDsInferContextImpl::initialize() <nvdsinfer_context_impl.cpp:1170> [UID = 1]: Warning, OpenCV has been deprecated. Using NMS for clustering instead of cv::groupRectangles with topK = 20 and NMS Threshold = 0.5
0:00:01.844642824  1468      0x1ca7a40 INFO                 nvinfer gstnvinfer.cpp:646:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Info from NvDsInferContextImpl::deserializeEngineAndBackend() <nvdsinfer_context_impl.cpp:1909> [UID = 1]: deserialized trt engine from :/opt/nvidia/deepstream/deepstream-6.1/samples/models/Primary_Detector/resnet10.caffemodel_b1_gpu0_int8.engine
INFO: ../nvdsinfer/nvdsinfer_model_builder.cpp:610 [Implicit Engine Info]: layers num: 3
0   INPUT  kFLOAT input_1         3x368x640
1   OUTPUT kFLOAT conv2d_bbox     16x23x40
2   OUTPUT kFLOAT conv2d_cov/Sigmoid 4x23x40

0:00:01.884199650  1468      0x1ca7a40 INFO                 nvinfer gstnvinfer.cpp:646:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Info from NvDsInferContextImpl::generateBackendContext() <nvdsinfer_context_impl.cpp:2012> [UID = 1]: Use deserialized engine model: /opt/nvidia/deepstream/deepstream-6.1/samples/models/Primary_Detector/resnet10.caffemodel_b1_gpu0_int8.engine
0:00:01.885788078  1468      0x1ca7a40 INFO                 nvinfer gstnvinfer_impl.cpp:328:notifyLoadModelStatus:<primary-inference> [UID 1]: Load new model:dstest1_pgie_config.txt sucessfully
0:00:01.886861348  1468      0x1ca7a40 WARN                 basesrc gstbasesrc.c:3600:gst_base_src_start_complete:<file-source> pad not activated yet
0:00:01.888253884  1468      0x1449f60 WARN               baseparse gstbaseparse.c:3666:gst_base_parse_loop:<h264-parser> error: Internal data stream error.
0:00:01.888275163  1468      0x1449f60 WARN               baseparse gstbaseparse.c:3666:gst_base_parse_loop:<h264-parser> error: streaming stopped, reason not-negotiated (-4)
Error: gst-stream-error-quark: Internal data stream error. (1): gstbaseparse.c(3666): gst_base_parse_loop (): /GstPipeline:pipeline0/GstH264Parse:h264-parser:
streaming stopped, reason not-negotiated (-4)

If I change splitmuxsink with filesink everything works fine, but I need to analyze a rtsp stream which will run non-stop and I want to save it in smaller videos

There is no update from you for a period, assuming this is not an issue anymore. Hence we are closing this topic. If need further support, please open a new one. Thanks

Could you use gst-launch-1 .0 command to run your pipeline first? It is better to write code after running it successfully.
You also can set some other paras for splitmuxsink, like iframeinterval and insert-sps-pps.
You can use GST_DEBUG=3 python3 ... command when you want to attach log.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.