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 4B48E47A1A for ; Sun, 28 Jan 2024 03:02:11 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 53FC468D158; Sun, 28 Jan 2024 05:01:58 +0200 (EET) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3FE6B68D147 for ; Sun, 28 Jan 2024 05:01:51 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 1A7ACE9E46; Sun, 28 Jan 2024 04:01:51 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bAH0sFwkDcHr; Sun, 28 Jan 2024 04:01:49 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 95C82E9CBF; Sun, 28 Jan 2024 04:01:49 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 Jan 2024 04:01:36 +0100 Message-Id: <20240128030136.5585-3-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240128030136.5585-1-cus@passwd.hu> References: <20240128030136.5585-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avfilter/yadif_common: fix timestamps with very small timebases 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 Cc: Marton Balint 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: Yadif filter assumed that the output timebase is always half of the input timebase. This is not true if halving the input time base is not representable as an AVRational causing the output timestamps to be invalidly scaled in such a case. So let's use av_reduce instead of av_mul_q when calculating the output time base and if the conversion is inexact then let's fall back to the original timebase which probably makes more parctical sense than using x/INT_MAX. Fixes invalidly scaled pts_time values in this command line: ffmpeg -f lavfi -i testsrc -vf settb=tb=1/2000000000,yadif,showinfo -f null none Signed-off-by: Marton Balint --- libavfilter/yadif.h | 2 ++ libavfilter/yadif_common.c | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h index 2c4fed62d2..c144568242 100644 --- a/libavfilter/yadif.h +++ b/libavfilter/yadif.h @@ -86,6 +86,8 @@ typedef struct YADIFContext { * the first field. */ int current_field; ///< YADIFCurrentField + + int pts_divisor; } YADIFContext; void ff_yadif_init_x86(YADIFContext *yadif); diff --git a/libavfilter/yadif_common.c b/libavfilter/yadif_common.c index 933372529e..90a5cffc2d 100644 --- a/libavfilter/yadif_common.c +++ b/libavfilter/yadif_common.c @@ -61,7 +61,7 @@ FF_ENABLE_DEPRECATION_WARNINGS int64_t next_pts = yadif->next->pts; if (next_pts != AV_NOPTS_VALUE && cur_pts != AV_NOPTS_VALUE) { - yadif->out->pts = cur_pts + next_pts; + yadif->out->pts = (cur_pts + next_pts) / yadif->pts_divisor; } else { yadif->out->pts = AV_NOPTS_VALUE; } @@ -150,8 +150,8 @@ int ff_yadif_filter_frame(AVFilterLink *link, AVFrame *frame) ff_ccfifo_inject(&yadif->cc_fifo, yadif->out); av_frame_free(&yadif->prev); if (yadif->out->pts != AV_NOPTS_VALUE) - yadif->out->pts *= 2; - yadif->out->duration *= 2; + yadif->out->pts *= 2 / yadif->pts_divisor; + yadif->out->duration *= 2 / yadif->pts_divisor; return ff_filter_frame(ctx->outputs[0], yadif->out); } @@ -168,9 +168,9 @@ FF_ENABLE_DEPRECATION_WARNINGS yadif->out->flags &= ~AV_FRAME_FLAG_INTERLACED; if (yadif->out->pts != AV_NOPTS_VALUE) - yadif->out->pts *= 2; + yadif->out->pts *= 2 / yadif->pts_divisor; if (!(yadif->mode & 1)) - yadif->out->duration *= 2; + yadif->out->duration *= 2 / yadif->pts_divisor; return return_frame(ctx, 0); } @@ -213,9 +213,17 @@ int ff_yadif_config_output_common(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; YADIFContext *yadif = ctx->priv; + AVRational tb = ctx->inputs[0]->time_base; int ret; - outlink->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2}); + if (av_reduce(&outlink->time_base.num, &outlink->time_base.den, tb.num, tb.den * 2LL, INT_MAX)) { + yadif->pts_divisor = 1; + } else { + av_log(ctx, AV_LOG_WARNING, "Cannot use exact output timebase\n"); + outlink->time_base = tb; + yadif->pts_divisor = 2; + } + outlink->w = ctx->inputs[0]->w; outlink->h = ctx->inputs[0]->h; -- 2.35.3 _______________________________________________ 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".