FFmpeg - 如何获取打开 ALAC 编解码器所需的额外数据
FFmpeg - How do i get the extradata required to open the ALAC Codec?
我想知道如何使用 FFmpeg 库从 ALAC 媒体文件中获取额外数据,而无需手动解析文件?
我最初设置:
avformat_open_input(&formatContext, pszFileName, 0, 0);
avformat_find_stream_info(formatContext, NULL);
av_find_best_stream(formatContext, AVMEDIA_TYPE_AUDIO, -1, -1, &codec, 0);
codecContext = avcodec_alloc_context3(codec);
目前,我能够检测并找到 ALAC 编解码器,但它无法打开返回AVERROR_INVALIDDATA的编解码器,该编解码器来自额外的数据并且extradata_size未设置。
avcodec_open2(codecContext, codec, NULL);
FFmpeg 文档指出,某些编解码器需要将额外的数据和extradata_size设置为编解码器的规范。但是这些数据不应该由avformat_find_stream_info设置吗?
是的,extradata
在avformat_open_input()
或avformat_find_stream_info()
期间填充。但是,它会将其填充到您未使用的字段中。您需要以下代码:
avformat_open_input(&formatContext, pszFileName, 0, 0);
avformat_find_stream_info(formatContext, NULL);
int audioStreamIndex = av_find_best_stream(formatContext, AVMEDIA_TYPE_AUDIO, -1, -1, &codec, 0);
codecContext = avcodec_alloc_context3(codec);
avcodec_copy_context(codecContext, formatContext->streams[audioStreamIndex]->codec);
avcodec_open2(codecContext, codec, NULL);
相关的额外行是 avcodec_copy_context()
,它将数据从libavformat
解复用器(formatContext->streams[]
)复制到该上下文的副本(codecContext
),您将使用该上下文的副本在 libavcodec
中使用解码器进行解码。
相关文章:
- h264_cuvid编解码器未找到
- C++17 编解码器在将标准::字符串转换为标准::字符串时抛出"bad conversion"
- 如何使用 ffmpeg 将 3840 nb_samples编码为请求 1024 的编解码器
- FFMPEG:为什么当我调用av_codec_next()时,我所有的编解码器都没有显示出来
- OpenCV 检查计算机上是否安装了视频编解码器 (C++)
- OpenCV:FFMPEG:编解码器 ID 12 和格式 'mp4 / MP4 不支持标记
- 带有 H264 编解码器的 libav 错误消息。"非严格单调PTS"
- 为什么编解码器X264/X265忽略了输入框架的PT和DTS
- 如何修复"UnicodeDecodeError:"utf-8"编解码器无法解码字节时使用Python C扩展?
- C++ avformat_open_input返回空编解码器、宽度和高度
- 如何为 OpenCV 的视频编写器动态选择可用的编解码器?
- 将FFMPEG命令行转换为C 编解码器设置
- codecvt_utf8<wchar_t>被转换为本机编解码器<wchar_t,字符>
- 寻求使用 FFmpeg 在 mp4 容器中 h264 编解码器的视频帧.数据包 pts 始终为 0
- C++ 无法实例化编解码器以在 txt 文件中写入 unicode
- 警告:找不到编解码器参数(././modules/higgui/src/cap_ffmpeg_impl.hpp:540)
- OpenCV videoWriter编解码器问题
- 编解码器在 gcc 中不起作用
- Qt5 QMediaPlayer使用随程序一起提供的编解码器
- FFmpeg - 如何获取打开 ALAC 编解码器所需的额外数据