Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/3] fftools/ffmpeg_dec: improve detection of lavf-guessed durations
@ 2024-07-05 10:42 Anton Khirnov
  2024-07-05 10:42 ` [FFmpeg-devel] [PATCH 2/3] fftools/ffmpeg_mux_init: default to input timebase for streamcopy Anton Khirnov
  2024-07-05 10:42 ` [FFmpeg-devel] [PATCH 3/3] lavf: deprecate avformat_transfer_internal_stream_timing_info() Anton Khirnov
  0 siblings, 2 replies; 4+ messages in thread
From: Anton Khirnov @ 2024-07-05 10:42 UTC (permalink / raw)
  To: ffmpeg-devel

Will be useful in following commit.
---
 fftools/ffmpeg_dec.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 70de151301..c2bcf784b0 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -260,6 +260,10 @@ static int64_t video_duration_estimate(const DecoderPriv *dp, const AVFrame *fra
     const int  ts_unreliable = dp->flags & DECODER_FLAG_TS_UNRELIABLE;
     const int      fr_forced = dp->flags & DECODER_FLAG_FRAMERATE_FORCED;
     int64_t codec_duration = 0;
+    // difference between this and last frame's timestamps
+    const int64_t ts_diff =
+        (frame->pts != AV_NOPTS_VALUE && dp->last_frame_pts != AV_NOPTS_VALUE) ?
+        frame->pts - dp->last_frame_pts : -1;
 
     // XXX lavf currently makes up frame durations when they are not provided by
     // the container. As there is no way to reliably distinguish real container
@@ -267,8 +271,13 @@ static int64_t video_duration_estimate(const DecoderPriv *dp, const AVFrame *fra
     // the container has timestamps. Eventually lavf should stop making up
     // durations, then this should be simplified.
 
+    // frame duration is unreliable (typically guessed by lavf) when it is equal
+    // to 1 and the actual duration of the last frame is more than 2x larger
+    const int duration_unreliable = frame->duration == 1 && ts_diff > 2 * frame->duration;
+
     // prefer frame duration for containers with timestamps
-    if (frame->duration > 0 && (!ts_unreliable || fr_forced))
+    if (fr_forced ||
+        (frame->duration > 0 && !ts_unreliable && !duration_unreliable))
         return frame->duration;
 
     if (dp->dec_ctx->framerate.den && dp->dec_ctx->framerate.num) {
@@ -285,9 +294,8 @@ static int64_t video_duration_estimate(const DecoderPriv *dp, const AVFrame *fra
 
     // when timestamps are available, repeat last frame's actual duration
     // (i.e. pts difference between this and last frame)
-    if (frame->pts != AV_NOPTS_VALUE && dp->last_frame_pts != AV_NOPTS_VALUE &&
-        frame->pts > dp->last_frame_pts)
-        return frame->pts - dp->last_frame_pts;
+    if (ts_diff > 0)
+        return ts_diff;
 
     // try frame/codec duration
     if (frame->duration > 0)
-- 
2.43.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-07-05 16:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-05 10:42 [FFmpeg-devel] [PATCH 1/3] fftools/ffmpeg_dec: improve detection of lavf-guessed durations Anton Khirnov
2024-07-05 10:42 ` [FFmpeg-devel] [PATCH 2/3] fftools/ffmpeg_mux_init: default to input timebase for streamcopy Anton Khirnov
2024-07-05 10:42 ` [FFmpeg-devel] [PATCH 3/3] lavf: deprecate avformat_transfer_internal_stream_timing_info() Anton Khirnov
2024-07-05 16:01   ` James Almer

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git