From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 420F74C3F0 for ; Thu, 23 Jan 2025 06:40:06 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E4E2268B2D3; Thu, 23 Jan 2025 08:40:02 +0200 (EET) Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C3B4E68AE4B for ; Thu, 23 Jan 2025 08:39:56 +0200 (EET) Received: from smtp2.mailbox.org (unknown [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4YdrsP6GJkz9shj for ; Thu, 23 Jan 2025 07:39:53 +0100 (CET) From: Gyan Doshi To: ffmpeg-devel@ffmpeg.org Date: Thu, 23 Jan 2025 12:09:37 +0530 Message-ID: <20250123063937.70-1-ffmpeg@gyani.pro> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] avfilter/setpts: add option to preserve framerate 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: In f121d95, the outlink framerate was unconditionally unset. This breaks/bloats outputs from CFR muxers unless the user explicitly set a sane framerate. And the most common invocation for setpts seen in workflows, our docs and across the web is `PTS-STARTPTS` or others of the form `PTS+constant` which preserve the input framerate. Fixes #11428 --- doc/filters.texi | 6 ++++++ libavfilter/setpts.c | 6 +++++- tests/filtergraphs/setpts | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index b926b865ae..fc352ed34a 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -31478,6 +31478,12 @@ This filter accepts the following options: @item expr The expression which is evaluated for each frame to construct its timestamp. +@item keep_fps (@emph{video only}) +Boolean option which determines if the original framerate is preserved. +If set to false, be advised that a sane frame rate should be explicitly +specified if output is sent to a constant frame rate muxer. +Default is @code{true}. + @end table The expression is evaluated through the eval API and can contain the following diff --git a/libavfilter/setpts.c b/libavfilter/setpts.c index 75d96247af..6609fe86aa 100644 --- a/libavfilter/setpts.c +++ b/libavfilter/setpts.c @@ -98,6 +98,7 @@ typedef struct SetPTSContext { const AVClass *class; char *expr_str; AVExpr *expr; + int keep_fps; double var_values[VAR_VARS_NB]; enum AVMediaType type; } SetPTSContext; @@ -153,8 +154,10 @@ static int config_input(AVFilterLink *inlink) static int config_output_video(AVFilterLink *outlink) { FilterLink *l = ff_filter_link(outlink); + SetPTSContext *s = outlink->src->priv; - l->frame_rate = (AVRational){ 1, 0 }; + if (!s->keep_fps) + l->frame_rate = (AVRational){ 1, 0 }; return 0; } @@ -320,6 +323,7 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar #if CONFIG_SETPTS_FILTER static const AVOption setpts_options[] = { { "expr", "Expression determining the frame timestamp", OFFSET(expr_str), AV_OPT_TYPE_STRING, { .str = "PTS" }, .flags = V|F|R }, + { "keep_fps", "Preserve input framerate", OFFSET(keep_fps), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, .flags = V|F }, { NULL } }; AVFILTER_DEFINE_CLASS(setpts); diff --git a/tests/filtergraphs/setpts b/tests/filtergraphs/setpts index 79037d1b65..c217778bb4 100644 --- a/tests/filtergraphs/setpts +++ b/tests/filtergraphs/setpts @@ -1,2 +1,2 @@ settb=1/1000, -setpts=1/(35*TB) * (N + 0.05 * sin(N*2*PI/25)) +setpts=1/(35*TB) * (N + 0.05 * sin(N*2*PI/25)):keep_fps=0 -- 2.46.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".