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

Jon*_*lus 5 c++ ffmpeg h.264 libav

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

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

typedef struct {
    UID key;
    int64_t offset;
    uint64_t length;
} KLVPacket;
Run Code Online (Sandbox Code Playgroud)

当前 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);
Run Code Online (Sandbox Code Playgroud)

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

It'*_*ete 2

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

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

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