C++ AVCodeContext::WAV文件的通道_布局0

C++ AVCodeContext::WAV文件的通道_布局0,c++,ffmpeg,wav,codec,C++,Ffmpeg,Wav,Codec,我已经成功地使用FFmpeg加载压缩音频文件,并使用我编写的一些代码查询它们的频道布局: 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, -

我已经成功地使用FFmpeg加载压缩音频文件,并使用我编写的一些代码查询它们的频道布局:

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

另外,
codecxt->channels
返回正确的值。使用flac文件(使用从同一应用程序生成的完全相同的音频数据),将
频道布局设置为0x4(
AV\u chu FRONT\u CENTER
)。

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

flac文件具有正确的
channel\u布局
,因为FFmpeg的flac编解码器填充此字段。您可以在文件
flac\u channel\u layouts
数组中找到对应表

如果需要手动填充
频道布局
,可以调用:


codecxt->channel\u layout=av\u get\u default\u channel\u layout(codecxt->channels)

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

flac文件具有正确的
channel\u布局
,因为FFmpeg的flac编解码器填充此字段。您可以在文件
flac\u channel\u layouts
数组中找到对应表

如果需要手动填充
频道布局
,可以调用:


codecxt->channel\u layout=av\u get\u default\u channel\u layout(codecxt->channels)

我应该声明我正在使用FFmpeg 2.1。我应该声明我正在使用FFmpeg 2.1。
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