From patchwork Mon Oct 10 16:10:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38679 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp443726pzb; Mon, 10 Oct 2022 09:12:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7zT8I1mIvg7pnD3019iqKQgtk+D7UYygEYP1w5PneWvaYFvVGlAYcUgilg6X+BztDRgMg8 X-Received: by 2002:a17:907:a073:b0:78d:51c4:5b8c with SMTP id ia19-20020a170907a07300b0078d51c45b8cmr13786534ejc.355.1665418360841; Mon, 10 Oct 2022 09:12:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665418360; cv=none; d=google.com; s=arc-20160816; b=yErSjOHYIr2pp/f+LqSg4FjAJRCYqCLl2Po479+cyklWc5SoZrYQRmLBXlIwA6ZMUL nKaVtNL59UMIxPEw9iJtqdk8T65tZ/2ygLh0tXujpA5QIsX/PQ96vf64u9wbo2JKCwu3 xM+ngu3UthWQL9EmEV9rdUIkpfY1un0zzZvPVEE+jW+rhgCMyWSl8T0vLrEvWNfgVrpQ mxNYDWbIlUxxwnDXH24hiT7W3A56FtYMxBLZWDhQHs5KuezjnBNmYk7a2vGqKoXvUiu/ zOgtQTF8Ec4whJqp/omJ9GOuC91ZuF/g0OQJrjDWwCoiJtoMJiLvYk9uSukC5+8d5fV3 zrDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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=IaTNwJbM/Zj8p4Wnk5RB4GXYpvRSmOyzTAY8FJBTZ94=; b=hOt76V3VJP/eKy+kR27lNOTOcvG0XNVSgTOGNqabbMoqsIKJeOMbQ/tcmJBEt6m922 pfeRLg7DMETK4mQL7QgNCbv0cjU+zK6EDamuefd5UxWBA6KuUFCXhpc7eSp8fu8EB67P g/K+HIC4FftyGYIOe5WNkFk1KGdP60cy3Xpw5F0Zi0ausp/GgshFkq6sMbRO/1lSyIu9 Lw8gFkqxu6H6cxV+ODEjvp1X3AhxcPtwAeummLOZ0xSCm3CU3JCIEdbVX9YfbfP7tS/j zuIDEVkSTwtEBOS0RJ3ntWOhUh/EBCvGiCE/jtQlurcDtlsWaRCbWMtH4HP8G/rP58cR payg== 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 s21-20020a508d15000000b00459ff7667b4si10825266eds.203.2022.10.10.09.12.34; Mon, 10 Oct 2022 09:12:40 -0700 (PDT) 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 D6C7D68BC16; Mon, 10 Oct 2022 19:11:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 33A9D68BD22 for ; Mon, 10 Oct 2022 19:11:16 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 4BC9E2405EC for ; Mon, 10 Oct 2022 18:11:12 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id lDZgIPqwWP6G for ; Mon, 10 Oct 2022 18:11:11 +0200 (CEST) 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 mail0.khirnov.net (Postfix) with ESMTPS id 6F7752405F9 for ; Mon, 10 Oct 2022 18:11:08 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 06F983A13BB for ; Mon, 10 Oct 2022 18:11:02 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 10 Oct 2022 18:10:52 +0200 Message-Id: <20221010161055.18948-5-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221010161055.18948-1-anton@khirnov.net> References: <20221010161055.18948-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/8] lavfi/vf_decimate: use inverse of output framerate as timebase 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: tidMV7ztiYCD This filter currently keeps the input timebase, but produces CFR output. It is thus simpler to use 1/output fps as the output timebase. Also, set output frame durations. --- libavfilter/vf_decimate.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libavfilter/vf_decimate.c b/libavfilter/vf_decimate.c index 01404e6fec..f61e501c96 100644 --- a/libavfilter/vf_decimate.c +++ b/libavfilter/vf_decimate.c @@ -43,7 +43,6 @@ typedef struct DecimateContext { AVFrame *last; ///< last frame from the previous queue AVFrame **clean_src; ///< frame queue for the clean source int got_frame[2]; ///< frame request flag for each input stream - AVRational ts_unit; ///< timestamp units for the output frames int64_t last_pts; ///< last output timestamp int64_t start_pts; ///< base for output timestamps uint32_t eof; ///< bitmask for end of stream @@ -213,6 +212,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) /* push all frames except the drop */ ret = 0; for (i = 0; i < dm->cycle && dm->queue[i].frame; i++) { + AVRational in_tb = ctx->inputs[INPUT_MAIN]->time_base; if (i == drop) { if (dm->ppsrc) av_frame_free(&dm->clean_src[i]); @@ -221,7 +221,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) AVFrame *frame = dm->queue[i].frame; dm->queue[i].frame = NULL; if (frame->pts != AV_NOPTS_VALUE && dm->start_pts == AV_NOPTS_VALUE) - dm->start_pts = frame->pts; + dm->start_pts = av_rescale_q(frame->pts, in_tb, outlink->time_base); + if (dm->ppsrc) { av_frame_free(&frame); frame = dm->clean_src[i]; @@ -229,8 +230,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) continue; dm->clean_src[i] = NULL; } - frame->pts = av_rescale_q(outlink->frame_count_in, dm->ts_unit, (AVRational){1,1}) + + frame->pts = outlink->frame_count_in + (dm->start_pts == AV_NOPTS_VALUE ? 0 : dm->start_pts); + frame->duration = 1; dm->last_pts = frame->pts; ret = ff_filter_frame(outlink, frame); if (ret < 0) @@ -404,7 +406,7 @@ static int config_output(AVFilterLink *outlink) fps = av_mul_q(fps, (AVRational){dm->cycle - 1, dm->cycle}); av_log(ctx, AV_LOG_VERBOSE, "FPS: %d/%d -> %d/%d\n", inlink->frame_rate.num, inlink->frame_rate.den, fps.num, fps.den); - outlink->time_base = inlink->time_base; + outlink->time_base = av_inv_q(fps); outlink->frame_rate = fps; outlink->sample_aspect_ratio = inlink->sample_aspect_ratio; if (dm->ppsrc) { @@ -414,7 +416,6 @@ static int config_output(AVFilterLink *outlink) outlink->w = inlink->w; outlink->h = inlink->h; } - dm->ts_unit = av_inv_q(av_mul_q(fps, outlink->time_base)); return 0; }