[FFmpeg-devel] [PATCH] cmdutils: fix finding next codec for id

Mark Thompson sw at jkqxz.net
Wed Feb 7 21:58:24 EET 2018


On 07/02/18 12:14, Josh de Kock wrote:
> ---
>  fftools/cmdutils.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
> index 0b06ccc71a..8bb9952016 100644
> --- a/fftools/cmdutils.c
> +++ b/fftools/cmdutils.c
> @@ -1424,11 +1424,14 @@ static char get_media_type_char(enum AVMediaType type)
>  static const AVCodec *next_codec_for_id(enum AVCodecID id, const AVCodec *prev,
>                                          int encoder)
>  {
> +    const AVCodec *next = NULL;
>      void *i = 0;
> -    while ((prev = av_codec_iterate(&i))) {
> -        if (prev->id == id &&
> -            (encoder ? av_codec_is_encoder(prev) : av_codec_is_decoder(prev)))
> -            return prev;
> +
> +    while ((next = av_codec_iterate(&i))) {
> +        if (next->id == id &&
> +            (!prev || (strcmp(next->name, prev->name) > 0)) &&
> +            (encoder ? av_codec_is_encoder(next) : av_codec_is_decoder(next)))
> +            return next;
>      }
>      return NULL;
>  }
> 

This is wrong - the strcmp() will skip over matching codecs found later which have names earlier in the alphabet.  For example, for H.264 once you've found "libx264" (which is first) you skip over all of the "h264_foo" codecs which should be found after it after it because 'h' < 'l'.

- Mark


More information about the ffmpeg-devel mailing list