[FFmpeg-devel] [PATCH] lavc/utils: list the supported field values in avcodec_open2()

Stefano Sabatini stefasab at gmail.com
Wed Oct 17 13:14:28 CEST 2012


Report the list of supported pix/sample formats, channel layouts, or
samplerates in case the codec supports only a limited number of them, and
the user didn't provide one of the supported values.

Improve feedback.
---
 libavcodec/utils.c |   42 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 41 insertions(+), 1 deletions(-)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 66f9271..1f174f7 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -949,7 +949,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
     }
 
     if (av_codec_is_encoder(avctx->codec)) {
-        int i;
+        int i, is_first;
         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])
@@ -966,6 +966,16 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
                 snprintf(buf, sizeof(buf), "%d", avctx->sample_fmt);
                 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));
+
+                av_log(avctx, AV_LOG_ERROR, "Choose sample format between: ");
+                is_first = 1;
+                for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
+                    av_log(avctx, AV_LOG_ERROR, "%s%s", is_first ? "" : ", ",
+                           av_get_sample_fmt_name(avctx->codec->sample_fmts[i]));
+                    is_first = 0;
+                }
+                av_log(avctx, AV_LOG_ERROR, "\n");
+
                 ret = AVERROR(EINVAL);
                 goto free_and_end;
             }
@@ -981,6 +991,16 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
                 snprintf(buf, sizeof(buf), "%d", avctx->pix_fmt);
                 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));
+
+                av_log(avctx, AV_LOG_ERROR, "Choose pixel format between: ");
+                is_first = 1;
+                for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++) {
+                    av_log(avctx, AV_LOG_ERROR, "%s%s", is_first ? "" : ", ",
+                           av_get_pix_fmt_name(avctx->codec->pix_fmts[i]));
+                    is_first = 0;
+                }
+                av_log(avctx, AV_LOG_ERROR, "\n");
+
                 ret = AVERROR(EINVAL);
                 goto free_and_end;
             }
@@ -992,6 +1012,16 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
             if (avctx->codec->supported_samplerates[i] == 0) {
                 av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
                        avctx->sample_rate);
+
+                av_log(avctx, AV_LOG_ERROR, "Choose sample rate between: ");
+                is_first = 1;
+                for (i = 0; avctx->codec->supported_samplerates[i]; i++) {
+                    av_log(avctx, AV_LOG_ERROR, "%s%s", is_first ? "" : ", ",
+                           av_get_pix_fmt_name(avctx->codec->supported_samplerates[i]));
+                    is_first = 0;
+                }
+                av_log(avctx, AV_LOG_ERROR, "\n");
+
                 ret = AVERROR(EINVAL);
                 goto free_and_end;
             }
@@ -1007,6 +1037,16 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
                     char buf[512];
                     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);
+
+                    av_log(avctx, AV_LOG_ERROR, "Choose channel layout between: ");
+                    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_log(avctx, AV_LOG_ERROR, "%s%s", is_first ? "" : ", ", buf);
+                        is_first = 0;
+                    }
+                    av_log(avctx, AV_LOG_ERROR, "\n");
+
                     ret = AVERROR(EINVAL);
                     goto free_and_end;
                 }
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list