[FFmpeg-devel] [PATCH] lavc/utils: show supported formats in check_encoder_constraints()

Nicolas George nicolas.george at normalesup.org
Sun Oct 21 21:48:33 CEST 2012


Le decadi 30 vendémiaire, an CCXXI, Stefano Sabatini a écrit :
> ---
>  libavcodec/utils.c |   41 +++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 41 insertions(+), 0 deletions(-)
> 
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 2e84678..9e08fcc 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -27,6 +27,7 @@
>  
>  #include "libavutil/avassert.h"
>  #include "libavutil/avstring.h"
> +#include "libavutil/bprint.h"
>  #include "libavutil/crc.h"
>  #include "libavutil/mathematics.h"
>  #include "libavutil/pixdesc.h"
> @@ -823,8 +824,11 @@ int attribute_align_arg ff_codec_open2_recursive(AVCodecContext *avctx, const AV
>  
>  static int check_encoder_constraints(AVCodecContext *avctx)
>  {
> +    AVBPrint pbuf;
>      int i, is_first;
>  
> +    av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
> +
>      if (avctx->codec->sample_fmts) {
>          for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++)
>              if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
> @@ -836,6 +840,15 @@ static int check_encoder_constraints(AVCodecContext *avctx)
>              av_log(avctx, AV_LOG_ERROR, "Specified sample format %s is invalid or not supported\n",
>                     (char *)av_x_if_null(av_get_sample_fmt_name(avctx->sample_fmt), buf));
>  
> +            is_first = 1;
> +            for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
> +                av_bprintf(&pbuf, "%s%s", is_first ? "" : ", ",
> +                           av_get_sample_fmt_name(avctx->codec->sample_fmts[i]));
> +                is_first = 0;
> +            }
> +            av_log(avctx, AV_LOG_ERROR, "Choose sample format between: %s\n", pbuf.str);
> +            av_bprint_clear(&pbuf);
> +
>              return AVERROR(EINVAL);
>          }
>      }
> @@ -852,6 +865,15 @@ static int check_encoder_constraints(AVCodecContext *avctx)
>              av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is invalid or not supported\n",
>                     (char *)av_x_if_null(av_get_pix_fmt_name(avctx->pix_fmt), buf));
>  
> +            is_first = 1;
> +            for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++) {

> +                av_bprintf(&pbuf, "%s%s", is_first ? "" : ", ",
> +                        av_get_pix_fmt_name(avctx->codec->pix_fmts[i]));
> +                is_first = 0;

I think you can test on i instead of using is_first.

> +            }
> +            av_log(avctx, AV_LOG_ERROR, "Choose pixel format between: %s\n", pbuf.str);

> +            av_bprint_clear(&pbuf);

I think it was av_bprint_finalize that you were looking for.

> +
>              return AVERROR(EINVAL);
>          }
>      }
> @@ -864,6 +886,15 @@ static int check_encoder_constraints(AVCodecContext *avctx)
>              av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
>                     avctx->sample_rate);
>  
> +            is_first = 1;
> +            for (i = 0; avctx->codec->supported_samplerates[i]; i++) {
> +                av_bprintf(&pbuf, "%s%s", is_first ? "" : ", ",

> +                           av_get_pix_fmt_name(avctx->codec->supported_samplerates[i]));

Looks strange to mix pixel formats and sample rates.

> +                is_first = 0;
> +            }
> +            av_log(avctx, AV_LOG_ERROR, "Choose sample rate between: %s\n", pbuf.str);
> +            av_bprint_clear(&pbuf);
> +
>              return AVERROR(EINVAL);
>          }
>      }
> @@ -880,6 +911,15 @@ static int check_encoder_constraints(AVCodecContext *avctx)
>                  av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
>                  av_log(avctx, AV_LOG_ERROR, "Specified channel layout '%s' is not supported\n", buf);
>  
> +                is_first = 1;
> +                for (i = 0; avctx->codec->channel_layouts[i]; i++) {
> +                    av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->codec->channel_layouts[i]);
> +                    av_bprintf(&pbuf, "%s%s", is_first ? "" : ", ", buf);
> +                    is_first = 0;
> +                }
> +                av_log(avctx, AV_LOG_ERROR, "Choose channel layout between: %s\n", pbuf.str);
> +                av_bprint_clear(&pbuf);
> +
>                  return AVERROR(EINVAL);
>              }
>          }
> @@ -897,6 +937,7 @@ static int check_encoder_constraints(AVCodecContext *avctx)
>          }
>      }
>  
> +    av_bprint_finalize(&pbuf, NULL);
>      return 0;
>  }
>  

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121021/9699af06/attachment.asc>


More information about the ffmpeg-devel mailing list