Controlling File Save Order in GStreamer Pipeline

• Hardware Platform (Jetson / GPU) : NVIDIA Jetson AGX Orin
• DeepStream Version : 7.0
• JetPack Version (valid for Jetson only) : 6.0
• TensorRT Version : 8.6.2.3
• Issue Type( questions, new requirements, bugs) : questions

I have such a GStreamer pipeline writen in Python using DeepStream:

gst-launch-1.0 autoaudiosrc ! avenc_aac ! aacparse ! sm.audio_0 splitmuxsink name=sm location=output_data/audio_%02d.aac max-size-time=1000000000 \ nvarguscamerasrc sensor_id=0 sensor_mode=0 ! 'video/x-raw(memory:NVMM), width=1920, height=1080, framerate=60/1' ! nvvideoconvert ! m.sink_0 nvstreammux name=m width=1920 height=1080 batch-size=1 batched-push-timeout=4000000 ! nvv4l2h265enc iframeinterval=60 idrinterval=60 ! h265parse ! splitmuxsink location=output_data/video_%02d.h265 max-size-time=1000000000

The system processes data from two sources: a camera and a microphone. It generates 1-second video segments and saves them to the output_data folder. The goal is to save an AAC audio file only after the video H265 file have been successfully saved.

To complicate this a little bit lets assume that instead of 2 sinks there are 3 splitmuxsink components now and we do not know the file save order:

  1. One for saving AAC audio files
  2. One for saving H265 video files
  3. One for saving PNG image files

The desired workflow and the order of saving files is as follows:

  1. Save H265 video file
  2. Save PNG video file
  3. Save AAC audio file

How can I control the save order of files? I want to ensure H265 file is saved first, followed by PNG file. Only after both H265 and PNG files are complete should the AAC file be saved. Then the whole process repates as splitmusxinks are used, and every 1 second there are 3 files generated.

Could this be achieved with some GStreamer plugin or should I add a probe function to some elements in the pipeline (written in Python) that ensures the order?

No way to implement in pipeline level. Your pipeline is actually three pipelines which have no relationship. Your requirement needs detailed control on the low level raw data and timestamps. E.G. you need to know with which timestamp the H265 decoder should generate the key frame, so that you can save the h265 video from this timestamp and then you need to find out the pieces of audio which is aligned with the same timestamp. Seems you need to write your own muxer and file saver to handle the data order by yourself.

This is not DeepStream related topic.

Is it possible to connect three different pipelines (two video and one audio) into a single pipeline and then use the probe function to decide which file is saved first?

I believe the new nvstreammux can concatenate multiple streams into one. Could this be the solution, or is writing custom plugins the only option?

No, the (new) nvstreammux does not support audio and video batching.

Ok, Let’s assume now that I have a single pipeline with just video from file/camera source. This video is split using a tee element into two branches.

One branch saves the video in H264 format, while the other saves it in H265 format. Both branches perform different operations, such as inferences, detections or genreal video operations.

How can I control the file save order of the two pipelines that originate from the common pipeline?

I’ve told you in previous post. You can only control by yourself, no open source plugin meet your requirement. You can implement probe function or plugin to handle by yourself.

Thank you for your response. Just to ultimately clarify, if I have an example from Nvidia Gstreamer written in Python

and I need to control the file save order (e.g., ensuring the video is always saved before the audio). The solution is to create a custom plugin for audio and video sinks, or add a probe function with variables to control the file save order?

If probe function could solve this problem, should it be connected to the ogg-demuxer in this case or to the sink pads of audio and video sink?

The suggestion is to write a mux+file saving sink plugin to handle the low level data processing by yourself. You can’t change the saving order of the files by any public sink plugins, most sinks work with clock( GstBaseSink (gstreamer.freedesktop.org)), and try to consume the data ASAP. If you want to break the clock and change the order, you need to hold all GstBuffers in one place and check which audio pieces have the same timestamps with which video GOPs, then arrange the correct file saving operations by yourself.

1 Like

Thank You. It make sense right now.

Where can I find inormation about creating my own plugin? What have found so far is the information about the DS Custom OpenCV plugin: Implementing a Custom GStreamer Plugin with OpenCV Integration Example — DeepStream documentation 6.4 documentation and GStreamer Plugin Writer: Plugin Writer's Guide

Can you point me in the right direction? There seems to be a limited amount of information available. Are there any other resources except the one that I mentioned above?

Please study the GStreamer plugin development by yourself. The DeepStream sample plugin is of no use for your case.
Plugin Writer’s Guide (gstreamer.freedesktop.org)

1 Like

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