[FFmpeg-devel] [PATCH] check sample_fmt in avcodec_open

Justin Ruggles justin.ruggles
Wed Feb 9 22:09:52 CET 2011


On 02/09/2011 03:47 PM, Ronald S. Bultje wrote:

> Hi,
> 
> 2011/2/9 M?ns Rullg?rd <mans at mansr.com>:
>> "Ronald S. Bultje" <rsbultje at gmail.com> writes:
>>
>>> From: Reimar D?ffinger <Reimar.Doeffinger at gmx.de>
>>>
>>> check AVCodecContext->sample_fmt against AVCodec->sample_fmts[] to ensure
>>> that the encoder supports the specified sample format. Error out if it doesn't.
>>> Previously, it would continue and output garbage.
>>> ---
>>>  libavcodec/utils.c |   10 ++++++++++
>>>  1 files changed, 10 insertions(+), 0 deletions(-)
>>>
>>> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
>>> index eede431..0816b39 100644
>>> --- a/libavcodec/utils.c
>>> +++ b/libavcodec/utils.c
>>> @@ -551,6 +551,16 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
>>>                 avctx->codec->max_lowres);
>>>          goto free_and_end;
>>>      }
>>> +    if (avctx->codec->sample_fmts && avctx->codec->encode) {
>>> +        int i;
>>> +        for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++)
>>> +            if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
>>> +                break;
>>> +        if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
>>> +            av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n");
>>
>> Is there an easy way to print the name of problematic sample format?
>> That would aid the user in resolving the problem.
> 
> This never happens in ffmpeg, it checks it before setting. This
> happens in applications setting sample_fmt unconditionally. It's
> basically a programming error, sort-of.


If it is an error, we need to indicate that it is an error instead of
silently creating bad output.  The alternative is to put such checks in
every encoder, which is not the best plan.

-Justin



More information about the ffmpeg-devel mailing list