ffmpeg - AVPacket 中的用户自定义私有数据
问题描述
有没有办法AVPacket
在解码之前附加一些用户私有数据以匹配输入AVPacket
和解码输出AVFrame
?某种AVFrame::opaque
。
具体来说,在存在 B 帧的情况下,h264 码流的解码过程可以重新排序,我想确定哪个AVPacket
被解码为哪个AVFrame
。
解决方案
感谢@Gyan,我能够在主解码循环中使用以下代码解决问题。
static uint64_t privateId = 0;
// Allocate dictionary and add appropriate key/value record
AVDictionary * frameDict = NULL;
av_dict_set(&frameDict, "private_id", std::to_string(privateId++).c_str(), 0);
// Pack dictionary to be able to use it as a side data in AVPacket
int frameDictSize = 0;
uint8_t *frameDictData = av_packet_pack_dictionary(frameDict, &frameDictSize);
// Free dictionary not used any more
av_dict_free(&frameDict);
// Add side_data to AVPacket which will be decoded
av_packet_add_side_data(&avPacket, AVPacketSideDataType::AV_PKT_DATA_STRINGS_METADATA, frameDictData, frameDictSize);
// Do the actual decoding
...
// Free side data from packet
av_packet_free_side_data(&avPacket);
// Obtain privateId from decoded frame
uint64_t privateId = std::stoul(av_dict_get(avFrame->metadata, "private_id", NULL, 0)->value);
// Free dictionary from decoded frame
av_dict_free(&avFrame->metadata);
推荐阅读
- zen-cart - 在zenkart中集成razorpay支付模块
- excel - 将变量设置为值会产生运行时错误 1004:应用程序定义或对象定义错误
- java - java中的时间戳验证器
- hadoop - MapReduce 主进程如何决定将哪个任务分配给单个工作进程?
- lua - 我的代码在 Minecraft 中的计算机控制的种子分析器上给出了“尝试调用零值”
- node.js - AWS Lambda 数据库连接问题 [更新问题]
- android - mvvm + 实时数据,由于以前的实时数据值重新加载相同的片段
- python - Docker:如何调试本地主机“内部服务器错误”?
- reactjs - why onChange event does not have event.keyCode property in react?
- python - 如何让 pip uninstall 删除安装后创建的文件?