gpt4 book ai didi

ffmpeg - AVPacket 中用户自定义私有(private)数据

转载 作者:行者123 更新时间:2023-12-04 15:55:31 53 4
gpt4 key购买 nike

有没有办法在解码之前将一些用户私有(private)数据附加到 AVPacket 以匹配输入 AVPacket 和解码输出 AVFrame?某种AVFrame::opaque

具体来说,h264 码流的解码过程可以在存在 B 帧的情况下进行重新排序,我想确定哪个 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);

关于ffmpeg - AVPacket 中用户自定义私有(private)数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51856505/

53 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com