Muxing audio and video inside a container

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

• 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=<.mp4 file> ! qtdemux name=demux demux.video_0 ! h264parse ! nvv4l2decoder num-extra-surfaces=2 ! m.sink_0 nvstreammux batch-size=1 width=1280 height=720 name=m ! nvstreamdemux name=d d.src_0 ! nvv4l2h264enc ! h264parse ! mux.video_0 qtmux name=mux ! filesink location=new.mp4 enable-last-sample=0 demux.audio_0 ! queue ! mux.audio_0

Python implementation

def cb_new_pad_1(qtmux, pad, qtdemux):
    name = pad.get_name()
    if "audio_0" in  name and qtdemux.get_static_pad("audio_0").link(pad):
        print(f"Could not link {name} pad of qtmux to audio_0 pad of qtdemux")
def cb_new_pad(qtdemux, pad, data,qtmux):
    h264parser = data
    name = pad.get_name()

    if "video_0" in  name and"sink")):
        print(f"Could not link {name} pad of qtdemux to sink pad of h264parser")
    if "audio_0" in name and"audio_0")):
        print(f"Could not link {name} pad of qtdemux to audio_0 pad of qtmux")

def main(source_path,dest_path):
    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)




    print("Linking elements in the Pipeline \n")        
    demux.connect("pad-added", cb_new_pad, h264parser,qtmux)
    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")
    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")
    qtmux_audio = streammux.get_request_pad("audio_0")
    if not qtmux_audio:
        sys.stderr.write(" Unable to get qtmux_audio \n")
#     qtmux.connect("pad-added", cb_new_pad_1,demux)

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

    # start play back and listen to events
    print("Starting pipeline (First Time)\n")
    time_run_pipeline_start = time.time()

The above pipeline is supposed to decode->encode video and final output will be muxed with source audio

The pipeline freezes and does not terminate

The last step of the Pipeline : demux.audio_0 ! queue ! mux.audio_0 where in linking the Demux audio to Mux Audio has some issue I guess.

Tried accessing the pad using :

qtmux_audio = streammux.get_request_pad(“audio_0”)
if not qtmux_audio:
sys.stderr.write(" Unable to get qtmux_audio \n")
Not able to get the audio_0 from qtmux.

I am passing a file with audio and video, Can anyone help me resolve this issue?

Adding Queue Between the Qtdemux audio and the Qtmux audio pads resolved the issue

1 Like

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