本文介绍了如何使用libav *将KLV数据包编码为H.264视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Currently I am using libav* to encode H.264 videos. I want to add KLVPackets to the bitstream but do not know where to implement it.

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

There is a struct within avcodec, but I am unsure of how to write it out to the frame metadata

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

当前FFMPEG代码(仅左侧相关代码):

Current FFMPEG code (only left relevant code):

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);

任何人都知道我可以从事的工作吗?

Anyone know of any examples I can work from?

推荐答案

KLV元数据是与视频分开的流.您可以使用自己的PID将流混入MPEG-2传输流中.

KLV Metadata is meant to be a stream separate to the video. You mux in the stream into an MPEG-2 Transport Stream with its own PID.

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

An alternative implementation is to send the KLV as a separate stream. That is, broadcast your video on one IP/Port and your KLV on another IP/Port.

无论哪种方式,您最大的问题就是将KLV数据同步到视频.我还没有找到一个可以在KLV中混合播放视频的开源库.您可以付费购买一些图书馆,但我尚未使用其中任何一个.

Either way, your biggest issue will be synchronizing the KLV data to the video. I have yet to find an open source library that muxes in KLV to video well. There are a few libraries you can pay for, but I have yet to use any one of them.

这篇关于如何使用libav *将KLV数据包编码为H.264视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 00:02