From patchwork Wed Jan 31 22:54:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 45949 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:2c82:b0:199:de12:6fa6 with SMTP id g2csp176176pzj; Wed, 31 Jan 2024 14:55:36 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVLM3IZbQVs0uZP5qZP8FfHFW2CVZtnXsE7M2I6BQUdQISLZPEu69X+w/Ed8jr9p3fVPh6aF6wSLYBA6O+ddAH2uqmSEaiyfUaEUA== X-Google-Smtp-Source: AGHT+IH091nQJQFyV1cKeCF+wj3SsHBHD31dv9M6Ns9IY2spkCNTenTQW+zqIBmUOhBHb6gAGW8w X-Received: by 2002:a17:906:4148:b0:a35:a941:62e7 with SMTP id l8-20020a170906414800b00a35a94162e7mr460220ejk.2.1706741736599; Wed, 31 Jan 2024 14:55:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706741736; cv=none; d=google.com; s=arc-20160816; b=A3n7g5llX+NBcn9CVJzdCbGS7TV3S4fk2HYh7pEX1vwtd/DDX6mKY7yyr359ourmTM qH2DaJoQz4HJ+OZJ/wnehk6a6jprisphwgSFIG4GkaX1RomFGH6zz0EVVdYdvru6Ka8M 9X3ngPgHSYqWPP/gJZhLGKs/d1T+/Ec1mCG4U5XlC7Oufdm8/LjYmDp6CSm51DoZuGsp nifeXQB0WH7MnUcDBrbpxrrl3hYIh9NJCTZAuXOnDy7Hhr7ioHqtd1PLYU7UuxKyp5SM Uhv72Kj5eHi2TBqRVvHNFY7HcRTmaoiYSkDZ2babR2g2gaKUMpnrZs5MD6nPhkclukjA jz7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=pGetMtn+rVv3/RX1nOXH7U9bdMgy8BtlLtU0oEdNGFg=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=mAbFfUZhKVnTk585SvZDfRSGK1CsELDqLM8uCQDRcPuAAZ4dbE0miuo/msbfttVKT4 +jv4aqwO6MxHlmPKa014VrbO5HplarNPZTLKpXkijLal6a2we2CvZ2tat3L1Uw/uAc2x SZiRUjFopZy3jbrWw+Zx1rNGamSw4fb29aaqD3rRVXTN1OEplDdjOUowE8VDx6mi3zYQ JBs09Axs5VnhmGDPLOgkTfJnEDjzatr70v4xiY/M2bFjXji8kOrb0Xem/Yxi27Q72xWO /YCag1fRt7yTFB587glgGXniASNguPsVFP/0Dn5Sl3rMql0diQr1IRUnHqBlcb+Ys+PP LLLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k26-20020a170906579a00b00a2a3d352161si6201407ejq.561.2024.01.31.14.55.36; Wed, 31 Jan 2024 14:55:36 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 49DDD68D139; Thu, 1 Feb 2024 00:55:33 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 26B0D68CA0D for ; Thu, 1 Feb 2024 00:55:26 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id C47E0E9CCF; Wed, 31 Jan 2024 23:55:25 +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 ancvPPp5U33I; Wed, 31 Jan 2024 23:55:23 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 765ABE95DF; Wed, 31 Jan 2024 23:55:23 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 Jan 2024 23:54:51 +0100 Message-Id: <20240131225451.30636-1-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <32ff862c-93f6-7c61-7168-801868f2f41d@passwd.hu> References: <32ff862c-93f6-7c61-7168-801868f2f41d@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: kynmp4nzmYEF 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 v2: use less divisons and fix durations Signed-off-by: Marton Balint --- libavfilter/yadif.h | 2 ++ libavfilter/yadif_common.c | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h index 2c4fed62d2..888ba12365 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_multiplier; } YADIFContext; void ff_yadif_init_x86(YADIFContext *yadif); diff --git a/libavfilter/yadif_common.c b/libavfilter/yadif_common.c index 933372529e..446ffb7c3d 100644 --- a/libavfilter/yadif_common.c +++ b/libavfilter/yadif_common.c @@ -62,6 +62,10 @@ FF_ENABLE_DEPRECATION_WARNINGS if (next_pts != AV_NOPTS_VALUE && cur_pts != AV_NOPTS_VALUE) { yadif->out->pts = cur_pts + next_pts; + if (yadif->pts_multiplier == 1) { + yadif->out->pts /= 2; + yadif->out->duration /= 2; + } } else { yadif->out->pts = AV_NOPTS_VALUE; } @@ -150,8 +154,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 *= yadif->pts_multiplier; + yadif->out->duration *= yadif->pts_multiplier; return ff_filter_frame(ctx->outputs[0], yadif->out); } @@ -168,9 +172,11 @@ 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 *= yadif->pts_multiplier; if (!(yadif->mode & 1)) - yadif->out->duration *= 2; + yadif->out->duration *= yadif->pts_multiplier; + else if (yadif->pts_multiplier == 1) + yadif->out->duration /= 2; return return_frame(ctx, 0); } @@ -213,9 +219,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_multiplier = 2; + } else { + av_log(ctx, AV_LOG_WARNING, "Cannot use exact output timebase\n"); + outlink->time_base = tb; + yadif->pts_multiplier = 1; + } + outlink->w = ctx->inputs[0]->w; outlink->h = ctx->inputs[0]->h;