From patchwork Sun Jan 28 03:01:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 45862 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:8786:b0:199:de12:6fa6 with SMTP id ph6csp832785pzb; Sat, 27 Jan 2024 19:01:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IGdLO6H94y1wujBykuihAO0i57XcjDmmMMoirGzJvLIYE5YARO8YLQDkeLEpcIFufQflVQ0 X-Received: by 2002:adf:a1c5:0:b0:337:c58a:ac91 with SMTP id v5-20020adfa1c5000000b00337c58aac91mr2525462wrv.1.1706410913688; Sat, 27 Jan 2024 19:01:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706410913; cv=none; d=google.com; s=arc-20160816; b=BWKhrLWO1AiVR9lnsbHFVdWPCqBToGexWZ1AIKa7vPhE2zQEYOTD962LtV4LKivsK0 lE1piB+FOsTaptqSlbUfOeygb/gPwXUnM7wxgBv+DQC9/9fp/jfyaQ2KEA0u8bkEhM7B rXcyrdQIXSDO0tPYeWV4EyWHhyTHN9zeKppCBldg8ZZlyz3OQkdFJvT6zj3yALRLrURb daJtgf6iBzbVXLs6uNOzDAv6AtFWnr0FtGs1VaS0rHChYdU3EBGAh1XPAEjWEK1Xb/I0 2pyDnlrEbIxGRRb+RxMMuUgr/hdYENx0CQOrqoUQWUFGyHsdpoC3ikDpvSgvy9mSbq8t WRJA== 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:message-id:date:to:from :delivered-to; bh=il/HzhqtEKIDIlzkmVVzR64HYVfjS9csrstD0w4Kk8U=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=UGOl7eWGpoYe3LxklkxVeDR1e77qguCcm/KmMou3BY2PAp0l9qhTlzagf+IyChHlxF 34hY/bfAq5HeD10757X87+oL86Z/tzbzHK6kP+9Qk7TkA+GS9ZaiWPbyV93dkZzTvkI/ EqOFq43x7FsEv0SL2CNXUdOotAKcQGgaq4MDvEu0S9y2N569qwsCpPYG9rl+gUSTJyCo jX3bwoR0n7fgE6mTMfUkgM/8ncnDyN2vdt+JDmW8BOGliTHk/0xel5qII7y8MWv7Wvtf TJluc8q3xEAymVUkMydfWBuUHOxu6eQqncjQ0NsJhI3n4vU++Dc0mvBDcc2mufi2866r 1eQQ== 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-20020a170906579a00b00a2a3d352161si2108197ejq.561.2024.01.27.19.01.53; Sat, 27 Jan 2024 19:01:53 -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 4F92A68CD88; Sun, 28 Jan 2024 05:01:49 +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 4641E68CD88 for ; Sun, 28 Jan 2024 05:01:42 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id ED093E9CD7; Sun, 28 Jan 2024 04:01:40 +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 r_vIWnIZPvpj; Sun, 28 Jan 2024 04:01:39 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 93E98E9CBF; Sun, 28 Jan 2024 04:01:39 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 Jan 2024 04:01:34 +0100 Message-Id: <20240128030136.5585-1-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avutil/rational: increase av_d2q precision 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: CbRtGu9D6GWw Fixes parsing small timebases from expressions (where the expression API converts the result to double), like in this command line: ffprobe -f lavfi -i testsrc=d=1,settb=1/2000000000 -show_streams -show_entries stream=time_base Before the patch timebase was parsed as 1/1999999999. Signed-off-by: Marton Balint --- libavutil/rational.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavutil/rational.c b/libavutil/rational.c index eb148ddb12..329fbf3302 100644 --- a/libavutil/rational.c +++ b/libavutil/rational.c @@ -114,7 +114,7 @@ AVRational av_d2q(double d, int max) return (AVRational) { d < 0 ? -1 : 1, 0 }; frexp(d, &exponent); exponent = FFMAX(exponent-1, 0); - den = 1LL << (61 - exponent); + den = 1LL << (62 - exponent); // (int64_t)rint() and llrint() do not work with gcc on ia64 and sparc64, // see Ticket2713 for affected gcc/glibc versions av_reduce(&a.num, &a.den, floor(d * den + 0.5), den, max); From patchwork Sun Jan 28 03:01:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 45863 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:8786:b0:199:de12:6fa6 with SMTP id ph6csp832843pzb; Sat, 27 Jan 2024 19:02:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IGwvl/4RvFzfUBGS5jXPx4eRgme5dv8GFKGl21gsNX91RiCbN/+2f5mBFV5L54iFoskptq1 X-Received: by 2002:a2e:80ca:0:b0:2cd:ce2:496e with SMTP id r10-20020a2e80ca000000b002cd0ce2496emr1395957ljg.37.1706410924995; Sat, 27 Jan 2024 19:02:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706410924; cv=none; d=google.com; s=arc-20160816; b=MhrAUjYrvqCshjHeajsR3rsAFDk+TdLFbbay8y/wOTaSYpe8f+zu0Kdz1VxEjXcRqc MGa2BGOklJvFK9GBon6CMNALbiAnBUUhkKtpOG/RUj+GYCGgubVPao2XpwPUizPch7I2 sxoHWjFgdawiai16Pf9patlB7oW7H2S8QIW6BO5tEa5e1qP5UqeDT+ohPWFdRYEpNn2N bpu7UKu70S1Zaon0jOia7f08RCrk3XVfIZ88xynRbo7/MrKBCFcRusIsNO8xzy+1ilmi M8EJf5pIvunxczSPSQNBJ0dnSDSbAjeWySDLXXuMQqkcNAzO6mqSuv/MYYb0nhKz+/mb B5GQ== 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=G96g8IlgHQLTzBpdqYMeq0BaFNMz8EhOtPTrGBLzfrw=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=tjpuWIht0UTG2WBZcPa3z/QDM9Ip2cih8wfPVxVlE3wFJK5XqPMiGpAAAO8hQb0WF+ IXhd4Cl/l0wLuFbThfHrZpjcmyE8LmQGWBwiixTHicjdouxt1H4tr6qswlz2rRTiDWR6 IMiSpzdzU+O8lQTH6Sg+gzVxkkyAUYwxU67g4+cHCu302W0cp8RAlCFahrla+zCWj9PL /88FlahDJVyMDjKc+buGk88vzT+493Daumdv3usnMt8GcYUFcB7yY1Sod+P6GIg0RrKc bsCVC64du9QoCPBZp7NLpQZS/ZaHwrsaY5A9O6nSeonEDFmtx37PhiLy1Pyyil27LbGP E/rA== 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 h13-20020a0564020e0d00b0055c5b3d78d2si2320022edh.316.2024.01.27.19.02.04; Sat, 27 Jan 2024 19:02:04 -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 77FC568D14E; Sun, 28 Jan 2024 05:01:55 +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 C7B0168D128 for ; Sun, 28 Jan 2024 05:01:48 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 9984AE9CD7; Sun, 28 Jan 2024 04:01:48 +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 4KP25Nj5H0Wf; Sun, 28 Jan 2024 04:01:46 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id CD91DE9CBF; Sun, 28 Jan 2024 04:01:45 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 Jan 2024 04:01:35 +0100 Message-Id: <20240128030136.5585-2-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 2/3] avfilter/yadif_common: factorize some part of the config_output and the uninit functions 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: 8oGHfH7in+Xu This unifies slightly diverged code and ensures that cc_fifo is always initialized. Signed-off-by: Marton Balint --- libavfilter/vf_bwdif.c | 30 +++------------------- libavfilter/vf_bwdif_cuda.c | 15 +++-------- libavfilter/vf_bwdif_vulkan.c | 12 ++++----- libavfilter/vf_yadif.c | 33 +++--------------------- libavfilter/vf_yadif_cuda.c | 27 +++---------------- libavfilter/vf_yadif_videotoolbox.m | 19 +++----------- libavfilter/yadif.h | 4 +++ libavfilter/yadif_common.c | 40 +++++++++++++++++++++++++++++ 8 files changed, 66 insertions(+), 114 deletions(-) diff --git a/libavfilter/vf_bwdif.c b/libavfilter/vf_bwdif.c index 353cd0b61a..9042db8d7f 100644 --- a/libavfilter/vf_bwdif.c +++ b/libavfilter/vf_bwdif.c @@ -137,17 +137,6 @@ static void filter(AVFilterContext *ctx, AVFrame *dstpic, } } -static av_cold void uninit(AVFilterContext *ctx) -{ - BWDIFContext *bwdif = ctx->priv; - YADIFContext *yadif = &bwdif->yadif; - - av_frame_free(&yadif->prev); - av_frame_free(&yadif->cur ); - av_frame_free(&yadif->next); - ff_ccfifo_uninit(&yadif->cc_fifo); -} - static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P, @@ -176,20 +165,9 @@ static int config_props(AVFilterLink *link) YADIFContext *yadif = &s->yadif; int ret; - link->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2}); - link->w = link->src->inputs[0]->w; - link->h = link->src->inputs[0]->h; - - if(yadif->mode&1) - link->frame_rate = av_mul_q(link->src->inputs[0]->frame_rate, (AVRational){2,1}); - else - link->frame_rate = ctx->inputs[0]->frame_rate; - - ret = ff_ccfifo_init(&yadif->cc_fifo, link->frame_rate, ctx); - if (ret < 0 ) { - av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); - return ret; - } + ret = ff_yadif_config_output_common(link); + if (ret < 0) + return AVERROR(EINVAL); yadif->csp = av_pix_fmt_desc_get(link->format); yadif->filter = filter; @@ -251,7 +229,7 @@ const AVFilter ff_vf_bwdif = { .description = NULL_IF_CONFIG_SMALL("Deinterlace the input image."), .priv_size = sizeof(BWDIFContext), .priv_class = &bwdif_class, - .uninit = uninit, + .uninit = ff_yadif_uninit, FILTER_INPUTS(avfilter_vf_bwdif_inputs), FILTER_OUTPUTS(avfilter_vf_bwdif_outputs), FILTER_PIXFMTS_ARRAY(pix_fmts), diff --git a/libavfilter/vf_bwdif_cuda.c b/libavfilter/vf_bwdif_cuda.c index 418f15f989..7585d1fe25 100644 --- a/libavfilter/vf_bwdif_cuda.c +++ b/libavfilter/vf_bwdif_cuda.c @@ -208,9 +208,7 @@ static av_cold void deint_cuda_uninit(AVFilterContext *ctx) CHECK_CU(cu->cuCtxPopCurrent(&dummy)); } - av_frame_free(&y->prev); - av_frame_free(&y->cur); - av_frame_free(&y->next); + ff_yadif_uninit(ctx); av_buffer_unref(&s->device_ref); s->hwctx = NULL; @@ -288,14 +286,9 @@ static int config_output(AVFilterLink *link) goto exit; } - link->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2}); - link->w = ctx->inputs[0]->w; - link->h = ctx->inputs[0]->h; - - if(y->mode & 1) - link->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate, - (AVRational){2, 1}); - + ret = ff_yadif_config_output_common(link); + if (ret < 0) + goto exit; y->csp = av_pix_fmt_desc_get(output_frames->sw_format); y->filter = filter; diff --git a/libavfilter/vf_bwdif_vulkan.c b/libavfilter/vf_bwdif_vulkan.c index c51df9aa26..57711fb672 100644 --- a/libavfilter/vf_bwdif_vulkan.c +++ b/libavfilter/vf_bwdif_vulkan.c @@ -296,6 +296,8 @@ static void bwdif_vulkan_uninit(AVFilterContext *avctx) ff_vk_uninit(&s->vkctx); + ff_yadif_uninit(avctx); + s->initialized = 0; } @@ -354,13 +356,9 @@ static int bwdif_vulkan_config_output(AVFilterLink *outlink) if (!outlink->hw_frames_ctx) return AVERROR(ENOMEM); - outlink->time_base = av_mul_q(avctx->inputs[0]->time_base, (AVRational){1, 2}); - outlink->w = vkctx->output_width; - outlink->h = vkctx->output_height; - - if (y->mode & 1) - outlink->frame_rate = av_mul_q(avctx->inputs[0]->frame_rate, - (AVRational){2, 1}); + err = ff_yadif_config_output_common(outlink); + if (err < 0) + return err; y->csp = av_pix_fmt_desc_get(vkctx->frames->sw_format); y->filter = bwdif_vulkan_filter_frame; diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c index a5a856bf5f..aa5ca4a889 100644 --- a/libavfilter/vf_yadif.c +++ b/libavfilter/vf_yadif.c @@ -251,16 +251,6 @@ static void filter(AVFilterContext *ctx, AVFrame *dstpic, } } -static av_cold void uninit(AVFilterContext *ctx) -{ - YADIFContext *yadif = ctx->priv; - - av_frame_free(&yadif->prev); - av_frame_free(&yadif->cur ); - av_frame_free(&yadif->next); - ff_ccfifo_uninit(&yadif->cc_fifo); -} - static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV440P, @@ -285,26 +275,9 @@ static int config_output(AVFilterLink *outlink) YADIFContext *s = ctx->priv; int ret; - outlink->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2}); - outlink->w = ctx->inputs[0]->w; - outlink->h = ctx->inputs[0]->h; - - if(s->mode & 1) - outlink->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate, - (AVRational){2, 1}); - else - outlink->frame_rate = ctx->inputs[0]->frame_rate; - - ret = ff_ccfifo_init(&s->cc_fifo, outlink->frame_rate, ctx); - if (ret < 0) { - av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); + ret = ff_yadif_config_output_common(outlink); + if (ret < 0) return ret; - } - - if (outlink->w < 3 || outlink->h < 3) { - av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n"); - return AVERROR(EINVAL); - } s->csp = av_pix_fmt_desc_get(outlink->format); s->filter = filter; @@ -354,7 +327,7 @@ const AVFilter ff_vf_yadif = { .description = NULL_IF_CONFIG_SMALL("Deinterlace the input image."), .priv_size = sizeof(YADIFContext), .priv_class = &yadif_class, - .uninit = uninit, + .uninit = ff_yadif_uninit, FILTER_INPUTS(avfilter_vf_yadif_inputs), FILTER_OUTPUTS(avfilter_vf_yadif_outputs), FILTER_PIXFMTS_ARRAY(pix_fmts), diff --git a/libavfilter/vf_yadif_cuda.c b/libavfilter/vf_yadif_cuda.c index d777757e65..17389f092f 100644 --- a/libavfilter/vf_yadif_cuda.c +++ b/libavfilter/vf_yadif_cuda.c @@ -200,10 +200,7 @@ static av_cold void deint_cuda_uninit(AVFilterContext *ctx) CHECK_CU(cu->cuCtxPopCurrent(&dummy)); } - av_frame_free(&y->prev); - av_frame_free(&y->cur); - av_frame_free(&y->next); - ff_ccfifo_uninit(&y->cc_fifo); + ff_yadif_uninit(ctx); av_buffer_unref(&s->device_ref); s->hwctx = NULL; @@ -281,27 +278,9 @@ static int config_output(AVFilterLink *link) goto exit; } - link->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2}); - link->w = ctx->inputs[0]->w; - link->h = ctx->inputs[0]->h; - - if(y->mode & 1) - link->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate, - (AVRational){2, 1}); - else - link->frame_rate = ctx->inputs[0]->frame_rate; - - ret = ff_ccfifo_init(&y->cc_fifo, link->frame_rate, ctx); - if (ret < 0) { - av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); - goto exit; - } - - if (link->w < 3 || link->h < 3) { - av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n"); - ret = AVERROR(EINVAL); + ret = ff_yadif_config_output_common(link); + if (ret < 0) goto exit; - } y->csp = av_pix_fmt_desc_get(output_frames->sw_format); y->filter = filter; diff --git a/libavfilter/vf_yadif_videotoolbox.m b/libavfilter/vf_yadif_videotoolbox.m index 69186c2254..28d836b782 100644 --- a/libavfilter/vf_yadif_videotoolbox.m +++ b/libavfilter/vf_yadif_videotoolbox.m @@ -174,9 +174,7 @@ static av_cold void do_uninit(AVFilterContext *ctx) API_AVAILABLE(macos(10.11), YADIFVTContext *s = ctx->priv; YADIFContext *y = &s->yadif; - av_frame_free(&y->prev); - av_frame_free(&y->cur); - av_frame_free(&y->next); + ff_yadif_uninit(ctx); av_buffer_unref(&s->device_ref); av_buffer_unref(&s->input_frames_ref); @@ -363,20 +361,9 @@ static int do_config_output(AVFilterLink *link) API_AVAILABLE(macos(10.11), ios( goto exit; } - link->time_base.num = ctx->inputs[0]->time_base.num; - link->time_base.den = ctx->inputs[0]->time_base.den * 2; - link->w = ctx->inputs[0]->w; - link->h = ctx->inputs[0]->h; - - if(y->mode & 1) - link->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate, - (AVRational){2, 1}); - - if (link->w < 3 || link->h < 3) { - av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n"); - ret = AVERROR(EINVAL); + ret = ff_yadif_config_output_common(link); + if (ret < 0) goto exit; - } y->csp = av_pix_fmt_desc_get(output_frames->sw_format); y->filter = filter; diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h index fbb99fd46e..2c4fed62d2 100644 --- a/libavfilter/yadif.h +++ b/libavfilter/yadif.h @@ -94,6 +94,10 @@ int ff_yadif_filter_frame(AVFilterLink *link, AVFrame *frame); int ff_yadif_request_frame(AVFilterLink *link); +int ff_yadif_config_output_common(AVFilterLink *outlink); + +void ff_yadif_uninit(AVFilterContext *ctx); + extern const AVOption ff_yadif_options[]; #endif /* AVFILTER_YADIF_H */ diff --git a/libavfilter/yadif_common.c b/libavfilter/yadif_common.c index 21097011f5..933372529e 100644 --- a/libavfilter/yadif_common.c +++ b/libavfilter/yadif_common.c @@ -209,6 +209,46 @@ int ff_yadif_request_frame(AVFilterLink *link) return 0; } +int ff_yadif_config_output_common(AVFilterLink *outlink) +{ + AVFilterContext *ctx = outlink->src; + YADIFContext *yadif = ctx->priv; + int ret; + + outlink->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2}); + outlink->w = ctx->inputs[0]->w; + outlink->h = ctx->inputs[0]->h; + + if (outlink->w < 3 || outlink->h < 3) { + av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n"); + return AVERROR(EINVAL); + } + + if(yadif->mode & 1) + outlink->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate, + (AVRational){2, 1}); + else + outlink->frame_rate = ctx->inputs[0]->frame_rate; + + ret = ff_ccfifo_init(&yadif->cc_fifo, outlink->frame_rate, ctx); + if (ret < 0) { + av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); + return ret; + } + + return 0; +} + +void ff_yadif_uninit(AVFilterContext *ctx) +{ + YADIFContext *yadif = ctx->priv; + + av_frame_free(&yadif->prev); + av_frame_free(&yadif->cur ); + av_frame_free(&yadif->next); + ff_ccfifo_uninit(&yadif->cc_fifo); +} + #define OFFSET(x) offsetof(YADIFContext, x) #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM From patchwork Sun Jan 28 03:01:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 45864 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:8786:b0:199:de12:6fa6 with SMTP id ph6csp832891pzb; Sat, 27 Jan 2024 19:02:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGEhXV2P8JQ7kQtgYPN5MDMDTIdydvLORa0cN0ULlRJUPIjgp7ByiCmyZEz4ot7WYC37Sok X-Received: by 2002:aa7:c90e:0:b0:55e:eadf:be5 with SMTP id b14-20020aa7c90e000000b0055eeadf0be5mr50282edt.2.1706410933459; Sat, 27 Jan 2024 19:02:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706410933; cv=none; d=google.com; s=arc-20160816; b=FLTMsNfvmF/jlWNoRijWwvjosAbCBYTS6zsrgkcFHofzn8+3emadxsW4HbE93r0GbT BXIiKOCbWLZyQzoQR2G5ImcPKNiOl4Pbx7Q/tutpoo2VnJ636zGqUwB4ufP1FVfseFsF nwqgV6mFXHqc5SO0d8C6tymFmssnPX1z0ZC34gQpm5xQnHJ1lL2kSXU4PZZHL3yi3gnl GRnnENtmvCGalKXK7qTFexXQ7TBTSjhBjUHH4PfW6o7D5TdqbdPBZ2spWCjmWAsGm07h Ad53ZYEAzrqyQZvWJRUCGOaEmIDvHR41bglX3FXI/iU8Z3NqLV8dLJfuLzla+TnW7By3 H8TA== 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=CvNb/ZVupRHtfebuy4/+YjZuYf4bCEgXtaUGOP0GJu0=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=sA1grrU9ANNya1Fc99EWqld015H3a91180uvPWork+ES0nq8Qvwc0QIu+aJCMmPYaW v9cvhaxypia+YfEWLBPeMGdM1IDIF8PvFtdjmw2BGYqYQExmGRLEFgj1UMIfI4TSEls6 2QDiEoJfuwos6hbo3TQ74aPzSKO7VJfqUezSnvA4d2ZcsBl9hrAbLwI6BfZy5wBPUdbv utMbF/OQJy/Kl4LwvnVg7gb06xXD3Pz04V3ATBZQ7SNAdMDpis2qYRM3z825kbpbioaa jR/DsH/4z0wGS9Qyiklc1gGW8CIwQWvgdlIg4v9ypmYzEvEuwlfVgE9WQROTkzP2Pnhu RafQ== 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 g13-20020a0564021ecd00b0055eba1df579si994826edg.571.2024.01.27.19.02.13; Sat, 27 Jan 2024 19:02:13 -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 8682868D147; Sun, 28 Jan 2024 05:01:58 +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 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 6z24hdUcgwTc 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;