force keyframe ignored (v4l2h264enc)

Nicolas Dufresne nicolas at
Tue Mar 23 19:32:10 UTC 2021

Le mardi 23 mars 2021 à 10:24 -0500, Javiku a écrit :
> Nicolas Dufresne-5 wrote
> > This is not yet implemented in this element, in fact there wasn't yet
> > support for this in Linux when that element was posted. I can provide you
> > hints on how to implement support for that, it should be fairly
> > straightforward.
> That would be great because I must use this element and a way to force key
> frames is an important requirement. Therefore implementing support for that
> seems to be the only solution. Thank you.

Here's is some information, V4L2 framework offert a control of type button (a
trigger) which ask for a new keyframe (it works ASAP).


    Force a key frame for the next queued buffer. Applicable to encoders. This
is a general, codec-agnostic keyframe control.

As of GStreamer side, GstVideoDecoder base class will handle the custom event
and will set a flag on the GstVideoCodecFrame of the associated frame we are
requested to make a key frame with. You have to trigger the button because you
queue the frame. Here's an example of code reading the flag:

And on V4L2 side here's where I think the code to trigger the button should be

I don't think that lock matters, you trigger with or without it I think. The
helpers for controls are not great and don't support buttons, I would just call
the ioctl() directly (well using the function pointer in v4l2object). Something
like this (not tested):

  struct v4l2_control ctrl = { V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME, 1 };
  if (v4l2object->ioctl (v4l2object->video_fd,VIDIOC_S_CTRL , &ctrk) < 0)
        (_("Failed to force keyframe.")), (NULL));

(if it's too complicated, I'll make an MR and you can help testing it)

Sent from:
gstreamer-devel mailing list
gstreamer-devel at

More information about the gstreamer-devel mailing list