2013-11-15 26 views
1

我已经成功地使用加载FFmpeg的压缩音频文件,并使用一些代码,我已经写了查询其channel_layouts:AVCodecContext :: channel_layout 0为WAV文件

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

我已经删除了所有的错误检查简洁。然而,对于微软的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文件(与刚好相同的音频数据从相同的应用程序生成),给出0x33的channel_layoutAV_CH_FRONT_CENTER)。

+0

我应该说明我使用的FFmpeg 2.1。 – cmannett85

回答

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