I am trying to encode KLV metadata (MISB 0601) with a regular video stream. I am using the ffmpeg examples and hove come up with this
to start a klv stream:
int Streamer::add_klv_stream(){
this->klv_stream = avformat_new_stream(this->output_context, NULL);
this->klv_stream->codec->codec_type = AVMEDIA_TYPE_DATA;
this->klv_stream->codec->codec_id = AV_CODEC_ID_SMPTE_KLV;
this->klv_stream->codec->codec_tag = 1096174667; //some magic number?
this->klv_stream->time_base = AVRational{ 1, 30 };
this->klv_stream->id = this->output_context->nb_streams - 1;
}
to add a klv data packet
int Streamer::addKlv(uint8_t * some_array) {
AVPacket pkt;
av_init_packet(&pkt);
pkt.size = 10;
pkt.data = some_array;//(uint8_t*)GetKlv(pkt.size);
auto res = write_frame(this->output_context, &this->video_stream.st->time_base, this->klv_stream, &pkt);
//ret = write_frame(this->output_context, &c->time_base, this->video_stream.st, &pkt);
free(pkt.data);
return res;
}
However, I get a BAD ACCESSS error in write_frame (specifically the av_interleaved_write_frame call)
int Streamer::write_frame(AVFormatContext *fmt_ctx, const AVRational *time_base, AVStream *st, AVPacket *pkt)
{
/* rescale output packet timestamp values from codec to stream timebase */
av_packet_rescale_ts(pkt, *time_base, st->time_base);
pkt->stream_index = st->index;
/* Write the compressed frame to the media file. */
//log_packet(fmt_ctx, pkt);
return av_interleaved_write_frame(fmt_ctx, pkt); //error is here
}
If anyone knows how to mux klv data and video it would be much appreciated.
Thanks in advance.
question from:
https://stackoverflow.com/questions/65861720/ffmpeg-encode-klv-data-with-video 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…