diff options
author | Anton Khirnov <anton@khirnov.net> | 2022-08-09 14:25:55 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2022-08-10 11:47:29 +0200 |
commit | 65001aa93e8393c31c417b45761a318bc8cdd6ef (patch) | |
tree | 4b283b1f7b76eb79394541d5154e914474ea3108 /fftools/ffmpeg.c | |
parent | d931554f668186729bf290ed9afa6e9a4417328b (diff) |
fftools/ffmpeg: add a live mux modelive
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.
Diffstat (limited to 'fftools/ffmpeg.c')
-rw-r--r-- | fftools/ffmpeg.c | 11 |
1 files changed, 10 insertions, 1 deletions
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; } |