Nvv4l2h264enc failing on Jetpack 5.1 when called through gstreamer library's C API

My application uses the gstreamer C API to perform h.264 and h.265 encoding. This means we don’t use gstreamer-1.0, our C++ code includes the gstreamer library and calls gst_parse_launch to create the pipeline.

This works fine on Jetpack 4, and it works fine on Jetpack 5.1 with the h.265 encoder. However, when I try the h.264 encoder it fails to generate key frames. It generates only the first IDR frame, followed by an endless series of P frames. (I checked the NALU headers to confirm that no more IDR frames are being generated).

Our code is exactly the same on Jetpack 4 and Jetpack 5.1. This is the gstreamer pipeline:

appsrc name=vidframe ! videoconvert ! video/x-raw, width=1280, height=720, format=UYVY, framerate=15/1 ! nvvidconv ! nvv4l2h264enc insert-aud=1 insert-sps-pps=1 control-rate=1 bitrate=1800000 peak-bitrate=3600000 vbv-size=5000000 profile=4 preset_level=4 name=videnc ! h264parse ! appsink name=appsink sync=false

I tried to use the “force IDR” API to work around the problem, but no luck. I am not sure I am using “force IDR” correctly, I’m trying to use the following code:

GstStructure* structure = gst_structure_new_empty(“force-idr”);
GstEvent* event = gst_event_new_custom(GST_EVENT_CUSTOM_DOWNSTREAM, structure);
gst_element_send_event(p_impl->gstreamer_encoder_, event);

You may try setting nvv4l2h264enc property idrinterval:

... ! nvv4l2h264enc idrinterval=30 ...

That works! Thank you for the very fast and very accurate suggestion.

Looks like jetpack 4 always sets IDR interval to 30 frames, and in jetpack 5 there is a new API “idrinterval” to specify it yourself. Maybe the default was changed to something much higher than 30 frames…

Seems default is 256 for my L4T release R35.1 with gstreamer 1.16.3:

gst-inspect-1.0 nvv4l2h264enc
 idrinterval         : Encoding IDR Frame occurance frequency
                        flags: readable, writable, changeable only in NULL or READY state
                        Unsigned Integer. Range: 0 - 4294967295 Default: 256 

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