force keyframe ignored (v4l2h264enc)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

force keyframe ignored (v4l2h264enc)

Javiku
Hello,
I tried to implement the solution proposed in
http://gstreamer-devel.966125.n4.nabble.com/How-to-force-keyframes-using-Python-GST-bindings-td4695810.html
<http://gstreamer-devel.966125.n4.nabble.com/How-to-force-keyframes-using-Python-GST-bindings-td4695810.html>  
but my "v4l2h264enc" encoder seems to ignore the event I send and no extra
key frames is generated. I just added a function to get a pointer to the
encoder and some messages that in fact are never displayed because the
conditions are always false. This is my code:

      ForceKeyStruct = gst_structure_new("GstForceKeyUnit","all-headers",
G_TYPE_BOOLEAN, TRUE, NULL);
      if(ForceKeyStruct == NULL)
        ipcd_warn("ForeKeyStruct NULL");
      force_key_unit_event = gst_event_new_custom(GST_EVENT_CUSTOM_UPSTREAM,
ForceKeyStruct);
      if(force_key_unit_event == NULL)
        ipcd_warn("force_key_unit_event NULL");
      enc = gst_bin_get_by_name(GST_BIN(pipeline), "v4l2h264enc0");
      if(enc == NULL)
        ipcd_warn("enc NULL");
      encoder_src_pad = gst_element_get_static_pad(enc, "src");
      if(!gst_pad_send_event(encoder_src_pad, force_key_unit_event))
        ipcd_warn("event not sent");
      gst_object_unref(encoder_src_pad);

When this code is executed I do not notice any change... as if the event was
completely ignored. The frame pattern does not change and I do not get any
additional key frame. I do not get any error message either. Am I doing
anything wrong? Is my encoder not able to handle that event? should I
explicitly configure the encoder to accept this event? Thanks in advance.
Regards Javiku




--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: force keyframe ignored (v4l2h264enc)

Nicolas Dufresne-5


Le mar. 23 mars 2021 05 h 30, Javiku <[hidden email]> a écrit :
Hello,
I tried to implement the solution proposed in
http://gstreamer-devel.966125.n4.nabble.com/How-to-force-keyframes-using-Python-GST-bindings-td4695810.html
<http://gstreamer-devel.966125.n4.nabble.com/How-to-force-keyframes-using-Python-GST-bindings-td4695810.html
but my "v4l2h264enc" encoder seems to ignore the event I send and no extra
key frames is generated. I just added a function to get a pointer to the
encoder and some messages that in fact are never displayed because the
conditions are always false. This is my code:

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.



      ForceKeyStruct = gst_structure_new("GstForceKeyUnit","all-headers",
G_TYPE_BOOLEAN, TRUE, NULL);
      if(ForceKeyStruct == NULL)
        ipcd_warn("ForeKeyStruct NULL");
      force_key_unit_event = gst_event_new_custom(GST_EVENT_CUSTOM_UPSTREAM,
ForceKeyStruct);
      if(force_key_unit_event == NULL)
        ipcd_warn("force_key_unit_event NULL");
      enc = gst_bin_get_by_name(GST_BIN(pipeline), "v4l2h264enc0");
      if(enc == NULL)
        ipcd_warn("enc NULL");
      encoder_src_pad = gst_element_get_static_pad(enc, "src");
      if(!gst_pad_send_event(encoder_src_pad, force_key_unit_event))
        ipcd_warn("event not sent");
      gst_object_unref(encoder_src_pad);

When this code is executed I do not notice any change... as if the event was
completely ignored. The frame pattern does not change and I do not get any
additional key frame. I do not get any error message either. Am I doing
anything wrong? Is my encoder not able to handle that event? should I
explicitly configure the encoder to accept this event? Thanks in advance.
Regards Javiku




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

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: force keyframe ignored (v4l2h264enc)

Javiku
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!



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: force keyframe ignored (v4l2h264enc)

Nicolas Dufresne-5
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
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel


_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: force keyframe ignored (v4l2h264enc)

Javiku
I don't know if the task is complicated for someone who has some experience
but it is definitely over my head :P I am new to GStreamer and I have to
admit that the code you linked overwhelmed me. On the other hand I have
plenty of time to test and I will be pleased to help somehow. You can
contact me directly to test new code that is not ready to be released or
just post messages within this thread if the implementation might be useful
for other people.
Thank you, best regards,
Javiku



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