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

Stefano Sabatini stefasab at gmail.com
Sun Oct 21 21:44:11 CEST 2012


---
 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;
+            }
+            av_log(avctx, AV_LOG_ERROR, "Choose pixel format between: %s\n", pbuf.str);
+            av_bprint_clear(&pbuf);
+
             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]));
+                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;
 }
 
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list