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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With