How to determine if buffer is a key-frame using pyds

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU)
NA
• DeepStream Version
6.2 and 6.3
• JetPack Version (valid for Jetson only)
NA
• TensorRT Version
NA
• NVIDIA GPU Driver Version (valid for GPU only)
NA
• Issue Type( questions, new requirements, bugs)

Just a question… if one has

def tiler_sink_pad_buffer_probe(pad, info, u_data):
    gst_buffer = info.get_buffer()

how can you tell if gst_buffer is a key_frame?

I saw a comment on the gstreamer boards that indicated the following works in C

if(!GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT))
{
// it's a keyframe
}

Is there a way in Python?

Thanks,
Robert.

I am not 100% sure if this would work, but from the document it seems there is a function named Gst.Buffer.has_flags
So in your example, probably doing

if gst_buffer.has_flags(Gst.BufferFlags.DELTA_UNIT):
    ...

might work.

In fact,The flag of the key frame is meaningful only before decoding.

Take deepstream_test_1.py as an example,the following code can get the results.

In the tiler sink probe function, it is impossible to get the key frame tag, it is meaningless.

+def parser_src_pad_buffer_probe(pad,info,u_data):
+    gst_buffer = info.get_buffer()
+    if not gst_buffer:
+        print("Unable to get GstBuffer ")
+        return Gst.PadProbeReturn.ERROR
+
+    if gst_buffer.has_flags(Gst.BufferFlags.DELTA_UNIT) == False:
+        print("key frame ")
+
+    return Gst.PadProbeReturn.OK


+    parsersrcpad = h264parser.get_static_pad("src")
+    if not parsersrcpad:
+        sys.stderr.write(" Unable to get src pad of h264parser \n")
+
+    parsersrcpad.add_probe(Gst.PadProbeType.BUFFER, parser_src_pad_buffer_probe, 0)

Thanks @marmikshah and @junshengy … very helpful!

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