gpt4 book ai didi

c++ - 如何使用 libav* 将 KLV 数据包编码为 H.264 视频

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:18:44 29 4
gpt4 key购买 nike

目前我正在使用 libav* 对 H.264 视频进行编码。我想将 KLVPackets 添加到比特流,但不知道在哪里实现它。

avcodec 中有一个结构,但我不确定如何将它写入帧元数据

typedef struct {
UID key;
int64_t offset;
uint64_t length;
} KLVPacket;

当前FFMPEG代码(只留下相关代码):

av_register_all();

pOutputFormat = av_guess_format(NULL, fileName, NULL);
pFormatCtx=avformat_alloc_context();
pVideoStream = av_new_stream(pFormatCtx,0);
pCodecCtx=pVideoStream->codec;
...
av_dump_format(pFormatCtx, 0, fileName,1);
pCodec = avcodec_find_encoder(pCodecCtx->codec_id);
avio_open(&pFormatCtx->pb, fileName, AVIO_FLAG_READ_WRITE)
avformat_write_header(pFormatCtx, &pDict);
...
avcodec_encode_video(pCodecCtx,outbuf,outbuf_size,ppicture);
...
int ret = av_interleaved_write_frame(pFormatCtx, &pkt);

有人知道我可以使用的任何示例吗?

最佳答案

KLV 元数据是独立于视频的流。您将流复用到具有自己的 PID 的 MPEG-2 传输流中。

另一种实现方式是将 KLV 作为单独的流发送。也就是说,在一个 IP/端口上广播您的视频,在另一个 IP/端口上广播您的 KLV。

无论哪种方式,您最大的问题是将 KLV 数据同步到视频。我还没有找到可以将 KLV 多路复用到视频的开源库。您可以付费购买一些图书馆,但我还没有使用过其中任何一个。

关于c++ - 如何使用 libav* 将 KLV 数据包编码为 H.264 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14140590/

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