From patchwork Sun Jun 18 11:17:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 42194 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:be15:b0:121:b37c:e101 with SMTP id ge21csp56984pzb; Sun, 18 Jun 2023 04:22:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5qFbmlfSfchbxaLOck6lhYYlC6gsbcuFNKlXZ7Bgce4yZ+CC+GoHwOwIAeICPE6ceuwxUO X-Received: by 2002:a17:907:72ce:b0:96f:a412:8b03 with SMTP id du14-20020a17090772ce00b0096fa4128b03mr6271650ejc.5.1687087324066; Sun, 18 Jun 2023 04:22:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687087324; cv=none; d=google.com; s=arc-20160816; b=PwzqLz5CnK+VW9nKkQx11lGsytcP3S2rPg0LoITwXj1qZWWSMEsz9HN9xJ6kXl0iKH XmfOaOZ1ZG7B5VKUMZv+9vyp0t3mHkVIw+1Om8zyVdBqiobY9syvgM82Zz3Ux1lAxaZk dkWtQnhF5TDUQ4x+N7mcysRnY7YGjC2Mbf6Di0hofwOIWIO6n4PhmAcRZYNEGsb77AiG OS0pAAYzfzFpCtl7hhSjcq80agh/I4myq+daLqCh5XN2NrqQjwp3f3IzmWqpKIZgUUdY wytomHDL2fTa5n1cC/nqDDyc7WqWF6AVigcPHy1WrJ7EjsTvegsKieCmfD3B70f8lvzM VHBA== 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:dkim-signature:delivered-to; bh=lN5Fk9mDDsI75FNCiY3QopNTFOOwCKSnjHT/WX2WA1Y=; b=kJKKNzo63oJUDRgK/hQdexVfN8CdrHfFecvJ2OTkyyhKWWr60vZLFu2UnCEic+eVCD xGtKiBG9no7WVzQKwen2h2mH5QLQwy9h9MDJjqTGosl70KuoSQeuLC9HzmIdppKJaemS HTD24t7YkWl4ZPhbwZKxRLuVrfdY4RrghTeTRhuHwUXcBFiI1CDn/1dWboX61XS5gbwr rmC++NVJVX/eZWoLAZjvPUx5ND+pn1cTjCCUsWMnPVXS73CFTpY+b4RjrqdhhCL+yiRG 8Miiv9d9b3/QHSyKN0dgt9Ow+BhIyZ2PbGaVhALZa0h+wnc83PgGspVVNYUsW+OfjdhX GQAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=iuzRL0Oe; 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 i17-20020a170906851100b009886cc3e82csi626929ejx.540.2023.06.18.04.22.03; Sun, 18 Jun 2023 04:22:04 -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; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=iuzRL0Oe; 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 A0B7C68C15F; Sun, 18 Jun 2023 14:20:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2053568BFA1 for ; Sun, 18 Jun 2023 14:20:16 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 922E34B8A0; Sun, 18 Jun 2023 13:20:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1687087213; bh=gAlLcYYNr6VOd5QW6ZfbSq0IxYVumeMrLqAUWeemzkY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iuzRL0OeFsKb+PStAIE7zykvTowdyNtkuNaKFS8SPjAy3fDKgA182sr4Rg+reG+CB /Tl19N2oAnPo0Jbw17vG9bIWbAsbxDIirbLjUZ8W6iV1sCTrhxL4yIsh8Reo3hn2bm 8pvTA0NSQQEOC0Dq9H/1q7eFtIBYTkAInpBR6eTs= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Jun 2023 13:17:13 +0200 Message-ID: <20230618111955.40994-23-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230618111955.40994-2-ffmpeg@haasn.xyz> References: <20230618111955.40994-2-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 21/22] lavfi/vf_libplacebo: set time_base/frame_rate dynamically 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: tdDT6VvP7kj6 From: Niklas Haas Use the gcd of all input timebases to ensure PTS accuracy. For the framerate, just pick the highest of all the inputs, under the assumption that we will render frames with approximately this frequency. Of course, this is not 100% accurate, in particular if the input frames are badly misaligned. But this field is informational to begin with. Importantly, it covers the "common" case of combining high FPS and low FPS streams with aligned frames. --- libavfilter/vf_libplacebo.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index 1085b6fdd0a..09a24e7c291 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -1158,6 +1158,11 @@ static int libplacebo_config_input(AVFilterLink *inlink) return 0; } +static inline AVRational max_q(AVRational a, AVRational b) +{ + return av_cmp_q(a, b) < 0 ? b : a; +} + static int libplacebo_config_output(AVFilterLink *outlink) { int err; @@ -1198,6 +1203,16 @@ static int libplacebo_config_output(AVFilterLink *outlink) if (s->fps.num) { outlink->frame_rate = s->fps; outlink->time_base = av_inv_q(s->fps); + } else { + outlink->frame_rate = avctx->inputs[0]->frame_rate; + outlink->time_base = avctx->inputs[0]->time_base; + for (int i = 1; i < s->nb_inputs; i++) { + outlink->frame_rate = max_q(outlink->frame_rate, + avctx->inputs[i]->frame_rate); + outlink->time_base = av_gcd_q(outlink->time_base, + avctx->inputs[i]->time_base, + AV_TIME_BASE / 2, AV_TIME_BASE_Q); + } } /* Static variables */