我已经成功地使用加载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 - 尽管ffprobe
和av_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_layout
(AV_CH_FRONT_CENTER
)。
我应该说明我使用的FFmpeg 2.1。 – cmannett85