From a2b4aced46b9244840fd768e763ee678b53f4867 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sun, 21 May 2023 02:15:26 +0200 Subject: [PATCH 1/3] avformat/demux: add support to derive timestamps from packet durations for video Signed-off-by: Paul B Mahol --- libavformat/demux.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libavformat/demux.c b/libavformat/demux.c index dec02a1a6b..d0d912ff98 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -1195,6 +1195,15 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, st->time_base, AV_ROUND_DOWN); } + } else if ((s->iformat->flags & AVFMT_NOTIMESTAMPS) && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if (sti->avctx->time_base.num > 0 && + sti->avctx->time_base.den > 0) { + out_pkt->duration = + av_rescale_q_rnd(sti->parser->duration, + sti->avctx->time_base, + st->time_base, + AV_ROUND_UP); + } } out_pkt->stream_index = st->index; -- 2.39.1