[FFmpeg-user] AVCodecContext::channel_layout 0 for WAV files

Camden Mannett camden.mannett at gmail.com
Fri Nov 15 21:50:25 CET 2013


I have been successfully loading compressed audio files using FFmpeg 2.1
and querying their channel_layouts using some code I've written:

    AVFormatContext* fmtCxt = nullptr;
    avformat_open_input( &fmtCxt, "###/440_sine.wav", nullptr, nullptr );
    avformat_find_stream_info( fmtCxt, nullptr );
    av_find_best_stream( fmtCxt, AVMEDIA_TYPE_AUDIO, -1, -1, nullptr, 0 );

    AVCodecContext* codecCxt = fmtCxt->streams[ret]->codec;
    AVCodec* codec = avcodec_find_decoder( codecCxt->codec_id );
    avcodec_open2( codecCxt, codec, nullptr );

    std::cout << "Channel Layout: " << codecCxt->channel_layout <<
std::endl;
    av_dump_format( fmtCxt, 0, "###/440_sine.wav", 0 );

I've removed all error checking for brevity.  However for Microsoft WAV
files (mono or stereo) the `AVCodecContext::channel_layout` member is
always 0 - despite `ffprobe` and `av_dump_format(..)` both returning valid
information:

    Input #0, wav, from '###/440_sine.wav':
    Duration: 00:00:00.01, bitrate: 740 kb/s
    Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 1
channels, s16, 705 kb/s

Using a flac file (with *exactly* the same audio data generated from the
same application), gives a `channel_layout` of 0x4 (`AV_CH_FRONT_CENTER`)
which is correct.

Do I have to treat uncompressed formats differently?


More information about the ffmpeg-user mailing list