[FFmpeg-devel] [PATCH v1] avformat/mux: Set AV_PKT_FLAG_KEY for is_intra_only packet

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Fri Apr 3 18:19:08 EEST 2020


lance.lmwang at gmail.com:
> From: Limin Wang <lance.lmwang at gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
> ---
>  libavformat/mux.c                | 16 ++++++++
>  tests/ref/fate/binsub-movtextenc |  2 +-
>  tests/ref/fate/movenc            | 50 +++++++++++------------
>  tests/ref/fate/sub2video         | 86 ++++++++++++++++++++--------------------
>  4 files changed, 85 insertions(+), 69 deletions(-)
> 
> diff --git a/libavformat/mux.c b/libavformat/mux.c
> index cc2d1e2..dc897c2 100644
> --- a/libavformat/mux.c
> +++ b/libavformat/mux.c
> @@ -548,6 +548,17 @@ fail:
>      return ret;
>  }
>  
> +static int is_intra_only(enum AVCodecID id)
> +{
> +    const AVCodecDescriptor *d = avcodec_descriptor_get(id);
> +    if (!d)
> +        return 0;
> +    if ((d->type == AVMEDIA_TYPE_VIDEO || d->type == AVMEDIA_TYPE_AUDIO) &&
> +        !(d->props & AV_CODEC_PROP_INTRA_ONLY))
> +        return 0;
> +    return 1;
> +}
> +
>  #define AV_PKT_FLAG_UNCODED_FRAME 0x2000
>  
>  /* Note: using sizeof(AVFrame) from outside lavu is unsafe in general, but
> @@ -664,6 +675,11 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *
>          frac_add(st->internal->priv_pts, (int64_t)st->time_base.den * st->time_base.num);
>          break;
>      }
> +
> +    /* update flags */
> +    if (is_intra_only(st->codecpar->codec_id))
> +        pkt->flags |= AV_PKT_FLAG_KEY;
> +
>      return 0;
>  }
>  FF_ENABLE_DEPRECATION_WARNINGS

You have added the check to code that is deprecated and slated to be
removed. Maybe it would be better to add it to prepare_input_packet()
instead?

> diff --git a/tests/ref/fate/binsub-movtextenc b/tests/ref/fate/binsub-movtextenc
> index 78c05f4..a8f94b7 100644
> --- a/tests/ref/fate/binsub-movtextenc
> +++ b/tests/ref/fate/binsub-movtextenc
> @@ -1 +1 @@
> -35adf776cd73e808186ae7124445f4b8
> +fc6d07679ac1f718aa50de687924cd97
> diff --git a/tests/ref/fate/movenc b/tests/ref/fate/movenc
> index 637a347..fb39b98 100644
> --- a/tests/ref/fate/movenc
> +++ b/tests/ref/fate/movenc
> @@ -2,17 +2,17 @@ write_data len 36, time nopts, type header atom ftyp
>  write_data len 2389, time nopts, type header atom -
>  write_data len 788, time 1000000, type sync atom moof
>  write_data len 110, time nopts, type trailer atom -
> -66cf48604f039aa9a51711786f5c8778 3323 non-empty-moov
> +5f401347fc3c771b819e2449d69d4861 3323 non-empty-moov
>  write_data len 36, time nopts, type header atom ftyp
>  write_data len 2721, time nopts, type header atom -
>  write_data len 908, time 966667, type sync atom moof
>  write_data len 110, time nopts, type trailer atom -
> -04b2e86f455af94f9258b8d66dbf71f5 3775 non-empty-moov-elst
> +4267feee527adf8cd4f7b36ac0fc0872 3775 non-empty-moov-elst
>  write_data len 36, time nopts, type header atom ftyp
>  write_data len 2629, time nopts, type header atom -
>  write_data len 908, time 1000000, type sync atom moof
>  write_data len 110, time nopts, type trailer atom -
> -e9f6fa032d6d8265d67aef5de81a48bf 3683 non-empty-moov-no-elst
> +44077b9ad45f3e16fafe4e5ada54e9b0 3683 non-empty-moov-no-elst
>  write_data len 24, time nopts, type header atom ftyp
[...]
> -1,  225640000,  225640000,  2127000,     2133, 0x670c11a5, F=0x0
> +1,  225640000,  225640000,  2127000,     2133, 0x670c11a5
>  0,       1139,       1139,        1,   518400, 0xbab197ea
> -1,  227834000,  227834000,  1262000,     1264, 0xc1d9fc57, F=0x0
> +1,  227834000,  227834000,  1262000,     1264, 0xc1d9fc57
>  0,       1140,       1140,        1,   518400, 0xb046dd30
>  0,       1145,       1145,        1,   518400, 0xbab197ea
> 
Have you checked whether all these changes are beneficial?

- Andreas


More information about the ffmpeg-devel mailing list