AVCodecContext::channel_layout 0 表示 WAV 文件
AVCodecContext::channel_layout 0 for WAV files
我已经使用 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 - 尽管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 文件(具有从同一应用程序生成的完全相同的音频数据)给出0x4 ( AV_CH_FRONT_CENTER
) 的channel_layout
您的WAV文件使用FFmpeg的pcm_s16le编解码器,该编解码器没有有关通道布局的信息。您只能拥有频道数。在这里可以找到很多解释
您对 flac 文件具有正确的channel_layout
,因为 FFmpeg 的 flac 编解码器填充此字段。你可以在libavcodec/flac.c文件(flac_channel_layouts
数组)上找到对应表。
如果您需要手动填写channel_layout
,您可以致电:
codecCxt->channel_layout = av_get_default_channel_layout( codecCxt->channels );
相关文章:
- 表示"accepting anything for this template argument" C++概念的通配符
- 如何将ampl中的集合表示为c++中的向量
- std::is_base_of表示ctor编译错误
- 输入中的字符串数未知(以字母表示)
- 我可以信任表示整数的浮点或双精度来保持精度吗
- c++模板来表示多项式
- 询问在设计我的手臂模拟器功能表示格式1
- CMakeLists.txt中的命名空间表示法
- C++射线示踪剂ppm表示没有足够的数据来显示图像
- 如何计算Big-O表示法中的平均渐近运行时间
- 我应该如何表示我拥有的连续元素序列?
- 在C++中,使用带有 std::optional 参数的函数<T>来表示可选参数是否有意义?
- 在 std::无符号字符的向量处存储 int 的十六进制表示形式
- 表示类模板C++空类型
- 具有所表示类的相同构造函数签名的代理类模板
- 嵌套在循环中的两个循环的 big-O 表示法
- 具有引用成员的结构是否具有唯一的对象表示形式
- 使用 int 表示浮点除法 C++
- Geeksforgeeks C 程序故障排除:IEE 754 表示法为十进制
- AVCodecContext::channel_layout 0 表示 WAV 文件