From patchwork Fri Jun 16 09:29:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 42134 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp1391867pzb; Fri, 16 Jun 2023 02:32:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4zcgc7J7fJVOcLFNUJhGIO9Ijb3uyxlAsvtE74hvGWLjz00QBRbvQTie92P9Be9LOHGFSg X-Received: by 2002:a17:907:3f18:b0:975:942e:81d5 with SMTP id hq24-20020a1709073f1800b00975942e81d5mr1655660ejc.1.1686907962466; Fri, 16 Jun 2023 02:32:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686907962; cv=none; d=google.com; s=arc-20160816; b=G/+sSFDvXuS9rHNILByo2wpXbUZxvjAgh45bHiTsW+INI3nBcZ0RQc1rXyjudp5/33 kzY8E7WdoQpd/TR2ZIZB9yeB3UWN81pynkcHTlMpKQ7tXrYICznzfg/xXb1TKmZVKYZC gSD+QHGvLCoQYzANVKc9I60sc7C9MOzxkTj2Gq7d+SpBp07pGImpnBR/tI57CRg8l7zu Kt6DHw60Szsa2MFcLow1bcriN26VIlJ5xNyv4FyXzT7oBD+poZr/YGyaol1Uk8vqfdQj E9Ve8kuMPO3aeL0vn8+96q0t3LrHTbK+PrRTXEfF0gSK2EEgdYEJ+QGwbz1lLsaIDyeD +W1g== 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=zO4n6Zi1zCei9OBYFKiFI/GlGjMWj+3cEEuPe2PrGto=; b=TkULwkWyJsYRBdqmO/xBKpm/TagWjmT2T1SSWnvr/mL78JboHkpK4DurnuaM2Tgl47 qNBtg4Yvmd7lP/4dwU2Vyyk9H/BDptzxNN0Z0KfImeUepeR9x4qqoOLMYWFLdvnN7AZr PgTlkwEsWmh7a7fvLO7Zu+7WOCo6H5SzlusFi0SL8xPuJidzn2aSrx+oUHbcNYizCCpb FmRYqFdmqkyrl37mknkxIy6LPSx3ORd+dk5EDD6TIpsboBVnIKLRLyzonGxcwKsQx7Qx sP0ibb21onLNxnbpRVt+NH6aI0ngFbDLltr8E1vZiM31c2TNN5oprpaAjvCMHj7X4+Dn d+fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b="DvY1td4/"; 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 qt21-20020a170906ecf500b0098288d36168si1670896ejb.76.2023.06.16.02.32.42; Fri, 16 Jun 2023 02:32:42 -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="DvY1td4/"; 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 36A5768C5A9; Fri, 16 Jun 2023 12:30:41 +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 79EAB68C5C1 for ; Fri, 16 Jun 2023 12:30:31 +0300 (EEST) Received: from localhost (217-74-0-168.hsi.r-kom.net [217.74.0.168]) by haasn.dev (Postfix) with ESMTPSA id 55301436B4; Fri, 16 Jun 2023 11:30:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1686907831; bh=Bu6cXQFW7flVz2N+p3SkLuhVfsVN4MBHUxoCNHn6ysQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DvY1td4/OyFChzBX8YYN+/lcHFc59GxuaPOdfw/fM2SmgOTM/rIZspUwy5vYdQCpX PfP3WBqUHHZ4E4GI4f9Tdh33rSqOX3+BCX/yAj8UqfJEprMiJBxcAxG5yNBSmy3Pgy wEI0rhGGCW2lQfLgyG208KfZgbK1fLpLJqTL5cTs= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Jun 2023 11:29:58 +0200 Message-ID: <20230616092959.5247-21-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230616092959.5247-1-ffmpeg@haasn.xyz> References: <20230616092959.5247-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 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: i46KBxzGwAiT 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 9b1526f19e..7840677b06 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -1156,6 +1156,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; @@ -1196,6 +1201,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 */