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 |
Le mar. 23 mars 2021 05 h 30, Javiku <[hidden email]> a écrit : Hello, 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.
_______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
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 |
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 |
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 |
In reply to this post by Nicolas Dufresne-5
Hi Nicolas,
I am currently working on a plugin that also relies on being able to trigger keyframes. I'm wondering if there has been any further work or testing on this feature? I also am happy to do some testing if that helps. I have a plugin that triggers keyframes and works well with x264enc that I can test against. regards Michael -- Sent from: http://gstreamer-devel.966125.n4.nabble.com/ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Le mercredi 26 mai 2021 à 02:04 -0500, MichaelK via gstreamer-devel a écrit :
> Hi Nicolas, > > I am currently working on a plugin that also relies on being able to trigger > keyframes. I'm wondering if there has been any further work or testing on > this feature? I also am happy to do some testing if that helps. I have a > plugin that triggers keyframes and works well with x264enc that I can test > against. There is no implementation posted yet. As I said, this isn't very hard, but still, someone that needs it will have to write the code. > > regards > > Michael > > > > > -- > 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 |
Thanks Nicolas,
I can confirm this works. I added the below definition to gst_v4l2_video_enc_handle_frame() +GstV4l2Object *v4l2object = self->v4l2output; And the below if statement just before GST_VIDEO_ENCODER_STREAM_UNLOCK (encoder); + + +if (GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME (frame)) { + struct v4l2_control ctrl = { V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME, 1 }; + if (v4l2object->ioctl (v4l2object->video_fd,VIDIOC_S_CTRL , &ctrl) < 0) + GST_ELEMENT_WARNING (self, RESOURCE, FAILED, + (_("Failed to force keyframe.")), (NULL)); +} + My keyframe triggers are being picked up and actioned. Thanks very much for the info, it was just what I needed. Cheers. Michael -- Sent from: http://gstreamer-devel.966125.n4.nabble.com/ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Le lundi 31 mai 2021 à 17:12 -0500, MichaelK via gstreamer-devel a écrit :
> Thanks Nicolas, > > I can confirm this works. I added the below definition to > gst_v4l2_video_enc_handle_frame() > > +GstV4l2Object *v4l2object = self->v4l2output; > > And the below if statement just before GST_VIDEO_ENCODER_STREAM_UNLOCK > (encoder); > > + > + > +if (GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME (frame)) { > + struct v4l2_control ctrl = { V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME, 1 }; > + if (v4l2object->ioctl (v4l2object->video_fd,VIDIOC_S_CTRL , &ctrl) < 0) > + GST_ELEMENT_WARNING (self, RESOURCE, FAILED, > + (_("Failed to force keyframe.")), (NULL)); > +} > + > > My keyframe triggers are being picked up and actioned. > > Thanks very much for the info, it was just what I needed. Looks like it, I knew not much was missing, but failed to look at it. Mind make a merge request ? (fork in gitlab into your namespace, then create branch, commit your work, push it there and the push script will give you a link to create the MR). Let me know if you need further guidance. > > Cheers. > > Michael > > > > > > > > > -- > 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 |
Free forum by Nabble | Edit this page |