diff mbox

[FFmpeg-devel] examples: set GOP size to 10 seconds

Message ID 8e05ff3f-d928-3a36-8e93-cd95ac877aae@gmail.com
State New
Headers show

Commit Message

Alfred E. Heggestad Oct. 29, 2019, 9:25 a.m. UTC
using a gop_size of 10 in the example code is very misleading.
in practice this means around 2 keyframes per second.

a normal video encoder should not send keyframes so frequent,
a better interval is 10 seconds.

Signed-off-by: Alfred E. Heggestad <alfred.heggestad@gmail.com>
---
  doc/examples/encode_video.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Liu Steven Oct. 29, 2019, 9:34 a.m. UTC | #1
> 在 2019年10月29日,17:25,Alfred E. Heggestad <alfred.heggestad@gmail.com> 写道:
> 
> using a gop_size of 10 in the example code is very misleading.
> in practice this means around 2 keyframes per second.
> 
> a normal video encoder should not send keyframes so frequent,
> a better interval is 10 seconds.

10 seconds is too long. i think 10 frames maybe ok for a sample.
but usually set to 2s one GOP here, for publish stream to rtmp server.
This is just a sample, so i think 10 second is too long.
> 
> Signed-off-by: Alfred E. Heggestad <alfred.heggestad@gmail.com>
> ---
> doc/examples/encode_video.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/doc/examples/encode_video.c b/doc/examples/encode_video.c
> index d9ab409908..8c5ee9818e 100644
> --- a/doc/examples/encode_video.c
> +++ b/doc/examples/encode_video.c
> @@ -110,13 +110,13 @@ int main(int argc, char **argv)
>     c->time_base = (AVRational){1, 25};
>     c->framerate = (AVRational){25, 1};
> 
> -    /* emit one intra frame every ten frames
> +    /* emit one intra frame every ten seconds
>      * check frame pict_type before passing frame
>      * to encoder, if frame->pict_type is AV_PICTURE_TYPE_I
>      * then gop_size is ignored and the output of encoder
>      * will always be I frame irrespective to gop_size
>      */
> -    c->gop_size = 10;
> +    c->gop_size = 10 * 25;
>     c->max_b_frames = 1;
>     c->pix_fmt = AV_PIX_FMT_YUV420P;
> 
> -- 
> 2.20.1 (Apple Git-117)
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

Thanks
Steven
Alfred E. Heggestad Oct. 29, 2019, 10:08 a.m. UTC | #2
On 29/10/2019 10:34, Steven Liu wrote:
> 
> 
>> 在 2019年10月29日,17:25,Alfred E. Heggestad <alfred.heggestad@gmail.com> 写道:
>>
>> using a gop_size of 10 in the example code is very misleading.
>> in practice this means around 2 keyframes per second.
>>
>> a normal video encoder should not send keyframes so frequent,
>> a better interval is 10 seconds.
> 
> 10 seconds is too long. i think 10 frames maybe ok for a sample.
> but usually set to 2s one GOP here, for publish stream to rtmp server.
> This is just a sample, so i think 10 second is too long.

Hi Steven,

I think we should make it clear in the code that the GOP size
depends on the framerate. Keep in mind that many people just copy
the example code to use in their applications, and does not
necessarily try to understand all the small details.


I am sure we can agree on a nice value for the keyframe interval,
but my point is that the value should be in seconds and not frames.

For example 5 seconds:


   c->gop_size = 5 * FPS;




/alfred
Steven Liu Oct. 29, 2019, 10:13 a.m. UTC | #3
Alfred E. Heggestad <alfred.heggestad@gmail.com> 于2019年10月29日周二 下午6:08写道:
>
> On 29/10/2019 10:34, Steven Liu wrote:
> >
> >
> >> 在 2019年10月29日,17:25,Alfred E. Heggestad <alfred.heggestad@gmail.com> 写道:
> >>
> >> using a gop_size of 10 in the example code is very misleading.
> >> in practice this means around 2 keyframes per second.
> >>
> >> a normal video encoder should not send keyframes so frequent,
> >> a better interval is 10 seconds.
> >
> > 10 seconds is too long. i think 10 frames maybe ok for a sample.
> > but usually set to 2s one GOP here, for publish stream to rtmp server.
> > This is just a sample, so i think 10 second is too long.
>
> Hi Steven,
>
> I think we should make it clear in the code that the GOP size
> depends on the framerate. Keep in mind that many people just copy
> the example code to use in their applications, and does not
> necessarily try to understand all the small details.
>
>
> I am sure we can agree on a nice value for the keyframe interval,
> but my point is that the value should be in seconds and not frames.

Yes i get your point, but the comment of the gop_size is:

    /**
     * the number of pictures in a group of pictures, or 0 for intra_only
     * - encoding: Set by user.
     * - decoding: unused
     */
    int gop_size;
Maybe user should read the document or the API's comments before they
use it, not only copy & paste.

>
> For example 5 seconds:
>
>
>    c->gop_size = 5 * FPS;
>
>
>
>
> /alfred
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Michael Niedermayer Oct. 30, 2019, 11:44 a.m. UTC | #4
On Tue, Oct 29, 2019 at 10:25:03AM +0100, Alfred E. Heggestad wrote:
> using a gop_size of 10 in the example code is very misleading.
> in practice this means around 2 keyframes per second.
> 
> a normal video encoder should not send keyframes so frequent,
> a better interval is 10 seconds.
> 
> Signed-off-by: Alfred E. Heggestad <alfred.heggestad@gmail.com>
> ---
>  doc/examples/encode_video.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/doc/examples/encode_video.c b/doc/examples/encode_video.c
> index d9ab409908..8c5ee9818e 100644
> --- a/doc/examples/encode_video.c
> +++ b/doc/examples/encode_video.c
> @@ -110,13 +110,13 @@ int main(int argc, char **argv)
>      c->time_base = (AVRational){1, 25};
>      c->framerate = (AVRational){25, 1};
> 
> -    /* emit one intra frame every ten frames
> +    /* emit one intra frame every ten seconds
>       * check frame pict_type before passing frame
>       * to encoder, if frame->pict_type is AV_PICTURE_TYPE_I
>       * then gop_size is ignored and the output of encoder
>       * will always be I frame irrespective to gop_size
>       */
> -    c->gop_size = 10;
> +    c->gop_size = 10 * 25;

several codecs have a limit of 132 dependant non key blocks
so 250 is a risky default, it would only strictly be valid with B frames
for some codecs
I know 10sec is commonly used but i think it should not be the recommanded
default in an example for the reason above. Especially not without
clear documentation of the spec violation this could cause

Thanks

[...]
diff mbox

Patch

diff --git a/doc/examples/encode_video.c b/doc/examples/encode_video.c
index d9ab409908..8c5ee9818e 100644
--- a/doc/examples/encode_video.c
+++ b/doc/examples/encode_video.c
@@ -110,13 +110,13 @@  int main(int argc, char **argv)
      c->time_base = (AVRational){1, 25};
      c->framerate = (AVRational){25, 1};

-    /* emit one intra frame every ten frames
+    /* emit one intra frame every ten seconds
       * check frame pict_type before passing frame
       * to encoder, if frame->pict_type is AV_PICTURE_TYPE_I
       * then gop_size is ignored and the output of encoder
       * will always be I frame irrespective to gop_size
       */
-    c->gop_size = 10;
+    c->gop_size = 10 * 25;
      c->max_b_frames = 1;
      c->pix_fmt = AV_PIX_FMT_YUV420P;