[FFmpeg-devel] [RFC] How to make container format and sample format select the codec format

Stefano Sabatini stefano.sabatini-lala
Fri Jan 14 16:06:15 CET 2011

Hi all,

ffmpeg -i INPUT -sample_fmt u8 out.wav
results in an output with sample format set to s16.

To force the format to u8 you have to specify the codec, -acodec
pcm_u8 in this case.

This is because in new_audio_stream():
codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_AUDIO);

and av_guess_codec() doesn't take in consideration the sample format
specified by the user.
My idea is to extend av_guess_codec() to:

enum CodecID av_guess_codec2(AVOutputFormat *fmt, const char *short_name,
                             const char *filename, const char *mime_type,
                             int format, enum AVMediaType type);

Then I would need some way to specify the map in the muxers a
sample_fmt -> codec_id map (adding a field to the output formats, or a

Is this acceptable? If people consider this overkill we should at
least warn the user that the provided sample format was ignored, like
in the attached patch.
FFmpeg = Fostering Funny Multimedia Programmable Extravagant Gigant

More information about the ffmpeg-devel mailing list