Save files every 60 frames instead of 1 Gst.SECOND in splitmuxsink

• Hardware Platform (Jetson / GPU) : NVIDIA Jetson AGX Orin
• DeepStream Version : 7.1
• JetPack Version (valid for Jetson only) : 6.1
• TensorRT Version : 10.3
• Issue Type( questions, new requirements, bugs) : question

Hello,

In my pipeline I am using as a sink splitmuxsink element. Currently I save files in splitmuxsink every 1 Gst.SECOND, however I would like to change the logic to save files every 60 frames instead of 1 second. Here is my code:

def create_pipeline_element(
    factory_name: str, element_name: str, print_name: str, logger: logging.Logger
) -> Gst.Element:
    """
    Create GStreamer pipeline element
    """
    # Create GStreamer element
    element = Gst.ElementFactory.make(factory_name, element_name)

    if not element:
        raise ValueError(f"Unable to create {print_name}")

    logger.info(f"Successfully created {print_name}.")

    return element

...

# Create H265 parser element
h265_parser = create_pipeline_element(
"h265parse", "h265-parser", "H265 Parser", logger
)

# Create H265 splitmuxsink element
h265_splitmuxsink = create_pipeline_element(
"splitmuxsink", "h265-mux", "H265 SplitMuxSink", logger
)
h265_splitmuxsink.set_property(
"location", "/media/ramdisk/temp/v_temp%06d.hevc"
)
h265_splitmuxsink.set_property("max-size-time", Gst.SECOND)

Question
I would like to replace Gst.SECOND with some other functionality, exactly saying - Save file every 60 frames instead of 1 second. How can i achieve that?

Thoughts
I thought about creating a pad probe function that is connected to this element, counts frames and when there are 60 frames it saves the file to the specified location. However, I find it very tedious and unnecessary. Is there any other way to do it? Some other parameter in splitmuxsink that will allow me to save files every 60 frames?

Sorrry for the long delay,This problem seems to have nothing to do with DeepStream.

The splitmuxsink element does not support counting by frame. Adding a probe function is a feasible solution.

So there isn’t any property in splitmuxsink to save videos to files by frame count?

Is there any other element that may have such a property?

As far as I know, there is no such element.

In addition, saving every 60 frames as a separate file requires the encoder to output an IDR frame (including SPS/PPS and other decoded data) every 60 frames.

So my current pipeline to save h265 files look like this:

# Create H265 queue element
h265_queue = create_pipeline_element(
    "queue", "h265-queue", "H265 Queue", logger
)

# Create H265 identity element
h265_identity = create_pipeline_element(
    "identity", "h265-identity", "H265 Identity", logger
)
h265_identity.set_property("sync", True)

# Create H265 encoder element
h265_encoder = create_pipeline_element(
    "nvv4l2h265enc", "h265-encoder", "H265 Encoder", logger
)
h265_encoder.set_property("iframeinterval", 60)
h265_encoder.set_property("idrinterval", 60)
h265_encoder.set_property("control-rate", 0)
h265_encoder.set_property("bitrate", 60000 * 1000)
h265_encoder.set_property("qp-range", "27,51:27,51:27,51")

# Create H265 parser element
h265_parser = create_pipeline_element(
    "h265parse", "h265-parser", "H265 Parser", logger
)

# Create H265 splitmuxsink element
h265_splitmuxsink = create_pipeline_element(
    "splitmuxsink", "h265-mux", "H265 SplitMuxSink", logger
)
h265_splitmuxsink.set_property("location", "temp%06d.hevc")
h265_splitmuxsink.set_property("max-size-time", Gst.SECOND)

Here, my encoder has set iframeinterval and idrinterval to 60. Does this ensure that my hevc file will be saved every 60 frames, or I still have to write a custom probe function?

This ensures that each 60 frames can be decoded independentl, but triggering start and stop still requires you to add a probe function.

1 Like

Thank You for clarification. However, I also have a question with splitmuxsink. When trying to access its sink pad I tried to get static pad, like this:

sink_pad = h265_splitmuxsink.get_static_pad("sink")

I got an error, that this sink_pad is Non type. I could not find any example how to attach a probe function to splitmuxsink element.

How can I attach such a probe function so that I can count frames and then perform emit("split-now") on splitmuxsink element?

For splitmuxsink, it should be:

sink_pad = h265_splitmuxsink.get_static_pad("video")

You can check it through gst-inspect-1.0 splitmuxsink

1 Like

Thank You. It worked but with get_request_pad("video") as all sink pad elements of splitmuxsink are On request.

1 Like

In addition, I wrote such a function that saves files every 60 frames:

frame_counter = {"count":0}

...

def h265_splitmuxsink_pad_probe_function(
    pad: Gst.Pad, info: Gst.PadProbeInfo, frame_counter: int, splitmuxsink: Gst.Element
) -> Gst.PadProbeReturn:
    """
    Pad probe function to count frames and trigger file save.
    """
    frame_counter["count"] += 1
    if frame_counter["count"] >= 60:
        # Reset frame counter
        frame_counter["count"] = 0

        # Trigger splitmuxsink to save file
        splitmuxsink.emit("split-now")
    return Gst.PadProbeReturn.OK
1 Like

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