From patchwork Wed Jul 28 22:09:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 29090 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a11:4023:0:0:0:0 with SMTP id ky35csp6200660pxb; Wed, 28 Jul 2021 15:09:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwG/K2Aq+0QD+3yN34SBzLVcLO2gbGxxO8Rr12NQ0NfhdTBBSB3YjvGnycAcaRfq4Df75+g X-Received: by 2002:a17:906:688e:: with SMTP id n14mr1501899ejr.67.1627510187511; Wed, 28 Jul 2021 15:09:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627510187; cv=none; d=google.com; s=arc-20160816; b=0u4z2FOLsaePIOShkl14TZ92S+k+XHe0Ejin1HIW5ijS+yCNyBYZ7C2bDb6Q9rFLIj 4oXWWaChAsLeiq6e4VUfzi+G1seopAvFdY9DEGpJxWcGkHnabdu1TGB01PxThTOpZ30B hgm/Yz0zXQST0vgVZWssoHgTLdz0b/m9kg5mk8z6Y2cKzfh8UOgNshW6/dioF0D5NC/+ C4cYTWzFNqn+fQ2EY9rZL+vZ8/NAH0fO4YifkUfKaDcnhZb4/fOMF7ay2vFUY+XDSlYu 0LlTvesQk6of1dR/DGrUjIWNojsVQ+qpRrIaI2u0QjDfMdJ1xgNZYXDUTJjwAuu6BdKE 29Fw== 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=ED3ZJVhW6hEj+NQTRgHveqBJbjoUaGk+JIKE5PvLRkc=; b=ASGpve9NGDIEeKJiEGjEjpRPGG//infhY32MYDz7xQv7bbfTHOsSnzJHdkAdJT1P+4 XsP3iTrqvGI5ekfHuTkCPMfLrd95hK5wn8XmnpzzdHZ2ZkQUcZxV4n8TtMySGobL93g0 34ChAw91vVu2n/FKkCFQDpU5eHhbm+fDirI0X4DxPuYtJAQdGLOVz3ZP/n0BNoe0n/wV hi4ggGt8zCCsoH479BRFJTk2DyA6XFWjYAbYQk22etoKgUBbmvBnfgSf9ONG9ADW2nPF ko6j3nUgRrf86QDRyEuuHh1cgUkbNhCGcwkAwJz1HME/5gRMwK/tjrRgthCjWHnotK3W uLvg== 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 bj22si991288ejb.53.2021.07.28.15.09.47; Wed, 28 Jul 2021 15:09:47 -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 3DA60689CCC; Thu, 29 Jul 2021 01:09:44 +0300 (EEST) 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 6D07D680A0D for ; Thu, 29 Jul 2021 01:09:37 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 57FC2E5B28; Thu, 29 Jul 2021 00:09:37 +0200 (CEST) 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 kmEKymCV3kVu; Thu, 29 Jul 2021 00:09:36 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id D7A32E5B27; Thu, 29 Jul 2021 00:09:35 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Thu, 29 Jul 2021 00:09:17 +0200 Message-Id: <20210728220917.27743-1-cus@passwd.hu> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avfilter/af_apad: do not add infinte silence for zero pad_dur or whole_dur 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: HHGUNphvym9N Unfortunately pad_len and pad_dur behaviour was different if 0 was specified, pad_dur handled 0 duration as infinity, for pad_len, infinity was -1. Let's make the behaviour consistent by handling 0 duration for pad_dur and whole_dur as indeed 0 duration. This somewhat changes the behaviour of the filter if 0 was explicitly specified, but deprecating the old option and adding a new for the corrected behaviour seemed a bit overkill. So let's document the change instead. Signed-off-by: Marton Balint --- doc/filters.texi | 7 +++++-- libavfilter/af_apad.c | 8 ++++---- libavfilter/version.h | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 66c0f87e47..f164f4d62d 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -2248,12 +2248,12 @@ with @option{pad_len}. @item pad_dur Specify the duration of samples of silence to add. See @ref{time duration syntax,,the Time duration section in the ffmpeg-utils(1) manual,ffmpeg-utils} -for the accepted syntax. Used only if set to non-zero value. +for the accepted syntax. Used only if set to non-negative value. @item whole_dur Specify the minimum total duration in the output audio stream. See @ref{time duration syntax,,the Time duration section in the ffmpeg-utils(1) manual,ffmpeg-utils} -for the accepted syntax. Used only if set to non-zero value. If the value is longer than +for the accepted syntax. Used only if set to non-negative value. If the value is longer than the input audio length, silence is added to the end, until the value is reached. This option is mutually exclusive with @option{pad_dur} @end table @@ -2262,6 +2262,9 @@ If neither the @option{pad_len} nor the @option{whole_len} nor @option{pad_dur} nor @option{whole_dur} option is set, the filter will add silence to the end of the input stream indefinitely. +Note that for ffmpeg 4.4 and earlier a zero @option{pad_dur} or +@option{whole_dur} also caused the filter to add silence indefinitely. + @subsection Examples @itemize diff --git a/libavfilter/af_apad.c b/libavfilter/af_apad.c index 8628c0c2e2..ff60eaa397 100644 --- a/libavfilter/af_apad.c +++ b/libavfilter/af_apad.c @@ -52,8 +52,8 @@ static const AVOption apad_options[] = { { "packet_size", "set silence packet size", OFFSET(packet_size), AV_OPT_TYPE_INT, { .i64 = 4096 }, 0, INT_MAX, A }, { "pad_len", "set number of samples of silence to add", OFFSET(pad_len), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, A }, { "whole_len", "set minimum target number of samples in the audio stream", OFFSET(whole_len), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, A }, - { "pad_dur", "set duration of silence to add", OFFSET(pad_dur), AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT64_MAX, A }, - { "whole_dur", "set minimum target duration in the audio stream", OFFSET(whole_dur), AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT64_MAX, A }, + { "pad_dur", "set duration of silence to add", OFFSET(pad_dur), AV_OPT_TYPE_DURATION, { .i64 = -1 }, -1, INT64_MAX, A }, + { "whole_dur", "set minimum target duration in the audio stream", OFFSET(whole_dur), AV_OPT_TYPE_DURATION, { .i64 = -1 }, -1, INT64_MAX, A }, { NULL } }; @@ -138,9 +138,9 @@ static int config_output(AVFilterLink *outlink) AVFilterContext *ctx = outlink->src; APadContext *s = ctx->priv; - if (s->pad_dur) + if (s->pad_dur >= 0) s->pad_len = av_rescale(s->pad_dur, outlink->sample_rate, AV_TIME_BASE); - if (s->whole_dur) + if (s->whole_dur >= 0) s->whole_len = av_rescale(s->whole_dur, outlink->sample_rate, AV_TIME_BASE); s->pad_len_left = s->pad_len; diff --git a/libavfilter/version.h b/libavfilter/version.h index 75cd10dccd..85acd613a0 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -31,7 +31,7 @@ #define LIBAVFILTER_VERSION_MAJOR 8 #define LIBAVFILTER_VERSION_MINOR 1 -#define LIBAVFILTER_VERSION_MICRO 103 +#define LIBAVFILTER_VERSION_MICRO 104 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \