Forcing keyframes using v4l2encoder

Hi,

I’ve experimented with the nv4l2vp8enc encoder element in Gstreamer v1.14 on a jetson nano. I’ve noticed that keyframes appear to occur at about 8 second intervals. My application requires occasionally syncing a local camera capture with recording and rtp streams so when new endpoints are added to a pipeline, a keyframe should be generated. I’ve used the GstForceKeyUnit custom event successfully to request key frames from the base vp8enc encoder on Jetson, however the Nvidia encoder does not respond to these events. I believe this manifests itself in relatively long delays of several seconds at times to view webrtc streams depending on the moment the downstream viewer joins a session.

Is there a way to force a new keyframe? I’ve tried EOS, flush stop, and neither seems to work (the first produces an internal error, and the second approach appears to be entirely ignored).

1 Like

Hi,
Please set the two properties and check again:

  iframeinterval      : Encoding Intra Frame occurance frequency
                        flags: readable, writable, changeable only in NULL or READY state
                        Unsigned Integer. Range: 0 - 4294967295 Default: 30
  idrinterval         : Encoding IDR Frame occurance frequency
                        flags: readable, writable, changeable only in NULL or READY state
                        Unsigned Integer. Range: 0 - 4294967295 Default: 256

By default idrinterval=256 and you should need to set it to a smaller value in the usecase.

1 Like

So your suggestion to generate one keyframe for synchronization would be to do the following:

  • Set the encoder to state READY or NULL
  • set encoder.idrinterval = 0
  • set encoder to state PLAYING
  • capture one frame
  • set encoder to state READY or NULL
  • set encoder.idrinterval = 256
  • set encoder to state PLAYING

That seems overly complex. What I currently have that works is to set the capture pipeline state to NULL and then back to PLAYING. This resets the camera and the encoder and does generate a new keyframe for the first buffer. The only side effect is this resets the camera device which can cause some visual artifacts (my camera seems to recalibrate white balance during the start up period for about 1 second).

I will give this a shot and see if it helps.

Hi…how might you recompress a piece of an avi w/o cutting it into more modest documents? in your model, you would proved unable “extricate” the 50-99 fragment effectively as this would infer having the casing #100 as your cutting point (which should be a substantial keyframe).

could you clarify me how you figure out how to recompress discretionary pieces of an avi record? I,m still a significant novice at this so pardon my restricted virtuadubbing proficiencies.

Hi,
We suggest set idrinterval to 30 so that you will see keyframes every 1 second.

1 Like

Changing the interval to a low value like this permanently would reduce the effectiveness of the compression would it not? I’m streaming the data to disk and wouldn’t want to have re-encode the video again as a post-processing step.

Hi,

No. idrframeinterval = 30 or 60 is normal in RTSP case. If you receive broken bitstream due to network instability, you would need to receive complete IDR frame to start next decoding section. Waiting for 8 second may not be acceptable in this case.

If you would like to keep the setting and insert IDR frames at anytime, please check
Allocating a GstBuffer of type "memory:NVMM" - #23 by DaneLLL