From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id D14C946C4F for ; Fri, 5 Jul 2024 10:42:49 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1CE2A68DAE0; Fri, 5 Jul 2024 13:42:47 +0300 (EEST) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A29B468DAE0 for ; Fri, 5 Jul 2024 13:42:39 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=Q3H/6P2Z; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 3D2814DE2 for ; Fri, 5 Jul 2024 12:42:38 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id BadrLvs5cInA for ; Fri, 5 Jul 2024 12:42:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1720176156; bh=/o4yPYOZy+jaFtlQF90smdBbCcrjTDcFHPHH2GtDdSs=; h=From:To:Subject:Date:From; b=Q3H/6P2ZePDpZsSLDyqkoS5cPUUPHP7GOgIVYal70ApDhVMkx7Hr7t3cJpiuqB5Gk jMFvu5rNo2S+81dzNRZAX66/WM52OV3+WmNZwTUugF/4X8ff+20SH2d9IhRzD8L2PL VgUDmk5aizF2DNZZKHihqsIBIrBD/ohJiZm6BEb4Rg/PaqGsIo/piBYkenpY1kQCCd ZzQ43gXqEjIzLACf1S5npqRVATq0WloPdrXU0rjDRQy+6MS6ww3mueRr4V/L7fPJpm 8S402fz/zJ1o9xafnegpovfv0cGF6SGma05anLoi1XRwhxWLA22Bb2AUn1Iv8Mm7Ks n0wB0JPvW5GNg== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id E5D174D9C for ; Fri, 5 Jul 2024 12:42:36 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B02CB3A02CA for ; Fri, 05 Jul 2024 12:42:36 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Jul 2024 12:42:31 +0200 Message-ID: <20240705104233.6703-1-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] fftools/ffmpeg_dec: improve detection of lavf-guessed durations X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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".