Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
841 views
in Technique[技术] by (71.8m points)

c++ - FFMPEG encode klv data with video

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...