c++ FFMPEG不写AVCC框信息
C++ FFMPEG not writing AVCC box information
我正在尝试使用c++中的FFMPEG API将原始H264编码为mp4容器。这一切都很好,但是AVCC框是空的,它返回错误:[iso file] Box "avcC" size 8无效
如果在输出文件上使用命令行工具:
ffmpeg -i output.mp4 -vcodec copy fixed.mp4
输出文件工作,AVCC填充了所需的信息。我不知道为什么这个命令行参数工作,但我无法使用API产生相同的结果。
我在c++代码中所做的(也在函数调用之间做一些事情):
outputFormat_ = av_guess_format( "mp4", NULL, NULL ); //AV_CODEC_H264
formatContext_ = avformat_alloc_context();
formatContext_->oformat = outputFormat_;
...
AVDictionary *opts = NULL;
char tmpstr[50]; sprintf(tmpstr, "%i", muxRate * KILOBYTESTOBYTES);
av_dict_set(&opts, "muxrate", tmpstr, 0);
avformat_write_header( formatContext_, &opts);
av_write_trailer(formatContext_);
这个输出是正确的,除了它缺少AVCC信息。手动添加这个(并相应地固定盒子长度)让我可以很好地播放视频。知道为什么API调用不生成AVCC信息吗?
作为参考,以下是修复前mp4的字符:
.avc1 ......................... €.8.H H…… .......................................... yy avcC……stt
之后:
avc1 ......................... €.8.H H…… .......................................... yy…! avcC.B€€(丫. . gB (U.a. -•……hI<€…stt
我的MP4文件也有空AVCC框的问题。原来我是在调用avcodec_open2
之后在AVCodecContext
实例上设置CODEC_FLAG_GLOBAL_HEADER
标志。
avcodec_open2
之前设置标志。解决了。所需的数据是AVCC编解码器的SPS和PPS组件。由于原始的H264流是附件b格式,这出现在每个i帧的开始,在NAL单元开始0x00 0x00 0x00 0x01 0x67
和0x00 0x00 0x00 0x01 0x68
。所以我们需要的是将这些信息复制到AVStream编解码器的extradata字段:
codecContext = stream->codec;
...
// videoSeqHeader contains the PPS and SPS NAL unit data
codecContext->extradata = (uint8_t*)malloc( sizeof(uint8_t) * videoSeqHeader_.size() );
for( unsigned int index = 0; index < videoSeqHeader_.size(); index++ )
{
codecContext->extradata[index] = videoSeqHeader_[index];
}
codecContext->extradata_size = (int)videoSeqHeader_.size();
这导致AVCC框被正确填充。
- 正在查找文档以获得PS4平台的C++中的设备信息
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 如何设置一个范围来提取我想要获得的信息
- 系统参数信息A 与 SPI_GETMOUSE 返回 0
- 为什么 gcovr 会生成空覆盖率统计信息?
- 我已经阅读了很多关于 2d 数组的信息,但我在作业中使用它时遇到了麻烦
- 将信息输入到下面显示的结构向量中的正确语法/格式是什么
- 调试符号中缺少 QObject 类信息(编辑但存在其他 Qt 类)
- 为什么数组大小信息可用于"sizeof"运算符和 delete[] 运算符,但在将数组作为参数传递到
- Pisarze - 来自波兰奥林匹克信息学的数据分析任务
- 将数组信息存储到 c++ 向量中有一个"Access violation reading location"
- C++20 个模块在 clang (Windows):在最简单的示例中键入信息错误
- C++ 如何暂停控制台输出,以便用户可以在继续之前阅读信息
- 如何从WebAssembly模块检测浏览器信息?
- Visual Studio 2017 C++,不能使用 typeid() 获取信息对象,缺少指针?;
- 如何实现具有多个平台__FILE__和__LINE__信息的 C/C++ 可变参数日志记录宏?
- 按字母顺序打印存储在字符数组中的信息
- std::extent 实现详细信息说明
- c++ FFMPEG不写AVCC框信息