Adding NVstreamdemux to the pipeline

• Hardware Platform : DGPU
• DeepStream Version : 6.2.0 **
• TensorRT Version : 8.5.2.2

• NVIDIA GPU Driver Version : 530.30.02
• Issue Type
Not able to include Nvstreamdemux into the python pipeline

•Requirement :
write the python implementation of the command line

Reference command line in gstreamer:

gst-launch-1.0 -e filesrc location=$file_path ! qtdemux ! h264parse ! nvv4l2decoder ! m.sink_0 nvstreammux batch-size=1 width=1280 height=720 name=m ! nvstreamdemux name=d d.src_0 ! nvv4l2h264enc ! h264parse ! qtmux ! filesink location=$output_file enable-last-sample=0

Equivalent python implementation

import time
import sys
import os
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GLib, Gst
from common.bus_call import bus_call
import time
import pyds


def  cb_new_pad(qtdemux, pad, data):
     h264parser = data
    name = pad.get_name()
    if "video_0" in  name and pad.link(h264parser.get_static_pad("sink")):
        print(f"Could not link {name} pad of qtdemux to sink pad of h264parser")
        
def main(source_path,dest_path):

    Gst.init(None)
    pipeline = Gst.Pipeline()


    source = Gst.ElementFactory.make("filesrc", "file-source")
    demux = Gst.ElementFactory.make("qtdemux", "demux")
    h264parser = Gst.ElementFactory.make("h264parse", "h264-parser")
    decoder = Gst.ElementFactory.make("nvv4l2decoder", "nvv4l2-decoder")
    streammux = Gst.ElementFactory.make("nvstreammux", "Stream-muxer")
    encoder = Gst.ElementFactory.make("nvv4l2h264enc", "nvv4l2-h264-encoder")
    h264parser2 = Gst.ElementFactory.make("h264parse", "h264-parser2")
    qtmux = Gst.ElementFactory.make("qtmux", "qtmux")
    sink = Gst.ElementFactory.make("filesink", "filesink")
    nvstreamdemux = Gst.ElementFactory.make("nvstreamdemux", "nvstream-demux")


    
    sink.set_property("location", dest_path)
    source.set_property('location', source_path) # replace it with your mp4 file
    streammux.set_property('batch-size', 1)
    if os.environ.get('USE_NEW_NVSTREAMMUX') != 'yes': 
        streammux.set_property('width', 1280)
        streammux.set_property('height', 720)


    pipeline.add(source)
    pipeline.add(demux)
    pipeline.add(h264parser)
    pipeline.add(decoder)

    pipeline.add(streammux)
    pipeline.add(nvstreamdemux)

    pipeline.add(encoder)
    pipeline.add(h264parser2)
    pipeline.add(qtmux)
    pipeline.add(sink)



    print("Linking elements in the Pipeline \n")

    source.link(demux)        
    demux.connect("pad-added", cb_new_pad, h264parser)
    h264parser.link(decoder)


    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(nvstreamdemux)
    
    sinkpad_nvdemux = encoder.get_request_pad("sink_0")
    if not sinkpad_nvdemux:
        sys.stderr.write(" Unable to get the sink pad of encoder\n")
    srcpad_nvdemux = nvstreamdemux.get_static_pad("src")
    if not srcpad_nvdemux:
        sys.stderr.write(" Unable to get source pad of nvdemux\n")
    srcpad_nvdemux.link(sinkpad_nvdemux)
    
      
    encoder.link(h264parser2)
    h264parser2.link(qtmux)
    qtmux.link(sink)

    loop = GLib.MainLoop()
    bus = pipeline.get_bus()
    bus.add_signal_watch()
    bus.connect ("message", bus_call, loop)


    pipeline.set_state(Gst.State.PLAYING)
    try:
        loop.run()
    except:
        pass
    
    pipeline.set_state(Gst.State.NULL)

I am unable to link the nvstreammux-> Nvstreamdemux->encoder.

Can u help in rectifying the issue ?

The pad name and link order are wrong.

Please use “gst-inspect-1.0 nvstreamdemux” to check the correct pad name.

This is basic GStreamer coding skills, please refer to GStreamer resources. It is a must to have basic GStreamer knowledge and coding skills before you start with DeepStream. GStreamer: open source multimedia framework

 sinkpad_encoder = encoder.get_static_pad("sink")
    if not sinkpad_encoder:
        sys.stderr.write(" Unable to get the sink pad of encoder \n")
        
    srcpad_nvdemux = nvstreamdemux.get_request_pad("src_0")
    if not srcpad_nvdemux:
        sys.stderr.write(" Unable to get source pad of nvdemux \n")
        
    srcpad_nvdemux.link(sinkpad_encoder)

Corrected it thanks.
Its working

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