From 65001aa93e8393c31c417b45761a318bc8cdd6ef Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 9 Aug 2022 14:25:55 +0200 Subject: fftools/ffmpeg: add a live mux mode Track the wallclock time at which each input packet is demuxed and propagate it through decoding and encoding. When the live mux option is used, drop all packets demuxed before the muxer is opened. This is intended to avoid latency when opening the muxer takes a long time. --- fftools/ffmpeg.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'fftools/ffmpeg.c') diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 0682a6fcc5..4da1f94c03 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -925,6 +925,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) av_ts2str(frame->pts), av_ts2timestr(frame->pts, &enc->time_base), enc->time_base.num, enc->time_base.den); } + frame->reordered_opaque = (int64_t)frame->opaque; } update_benchmark(NULL); @@ -956,6 +957,11 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) return ret; } + if (enc->codec->capabilities & AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE) + pkt->opaque = (void*)enc->reordered_opaque; + else if (frame) + pkt->opaque = frame->opaque; + if (debug_ts) { av_log(NULL, AV_LOG_INFO, "encoder -> type:%s " "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s " @@ -2076,6 +2082,7 @@ static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacke *got_frame = 0; if (pkt) { + avctx->reordered_opaque = (int64_t)pkt->opaque; ret = avcodec_send_packet(avctx, pkt); // In particular, we don't expect AVERROR(EAGAIN), because we read all // decoded frames with avcodec_receive_frame() until done. @@ -2086,8 +2093,10 @@ static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacke ret = avcodec_receive_frame(avctx, frame); if (ret < 0 && ret != AVERROR(EAGAIN)) return ret; - if (ret >= 0) + if (ret >= 0) { *got_frame = 1; + frame->opaque = (void*)frame->reordered_opaque; + } return 0; } -- cgit v1.2.3