How do I encode KLV packets to an H.264 video using libav*

血红的双手。 提交于 2021-01-21 05:08:33

问题


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.

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;

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?


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/14140590/how-do-i-encode-klv-packets-to-an-h-264-video-using-libav

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!