WAV文件的AVCodecContext :: channel_layout 0

时间:2013-11-15 12:43:38

标签: c++ ffmpeg wav codec

我已经使用FFmpeg成功加载了压缩音频文件,并使用我编写的一些代码查询了他们的channel_layouts:

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 );

为简洁起见,我删除了所有错误检查。但是对于Microsoft WAV文件(单声道或立体声),AVCodecContext::channel_layout成员始终为0 - 尽管ffprobeav_dump_format(..)都返回有效信息:

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

codecCxt->channels也返回正确的值。使用flac文件(完全从同一个应用程序生成相同的音频数据),得到channel_layout 0x4(AV_CH_FRONT_CENTER)。

1 个答案:

答案 0 :(得分:3)

您的WAV文件使用FFmpeg的pcm_s16le编解码器,它没有关于通道布局的信息。您只能拥有频道数量。可以找到很多解释here

你有正确的channel_layout flac文件,因为FFmpeg的flac编解码器填充了这个字段。您可以在libavcodec/flac.c文件flac_channel_layouts数组中找到对应表。

如果您需要手动填写channel_layout,可以致电:

codecCxt->channel_layout = av_get_default_channel_layout( codecCxt->channels );

相关问题