force keyframe ignored (v4l2h264enc)

Nicolas Dufresne nicolas at ndufresne.ca
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).


V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME (button)

    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:

https://gitlab.freedesktop.org/gstreamer/gst-plugins-ugly/-/blob/master/ext/x264/gstx264enc.c#L2514

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

https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/blob/master/sys/v4l2/gstv4l2videoenc.c#L796

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):

https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/vidioc-g-ctrl.html

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

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





--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
gstreamer-devel at lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel




More information about the gstreamer-devel mailing list