From patchwork Wed Jul 3 15:15:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lars Kiesow X-Patchwork-Id: 13807 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id C4688449F5C for ; Wed, 3 Jul 2019 18:16:19 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A130D689BB7; Wed, 3 Jul 2019 18:16:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mta-out-2-1.rz.uni-osnabrueck.de (mta-out-2-1.rz.uni-osnabrueck.de [131.173.18.152]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 01DCB689B43 for ; Wed, 3 Jul 2019 18:16:14 +0300 (EEST) Received: from smtp-auth.serv.Uni-Osnabrueck.DE (vm135.rz.uni-osnabrueck.de [131.173.16.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mta-out-2-1.rz.uni-osnabrueck.de (Postfix) with ESMTPS id 40380300047B; Wed, 3 Jul 2019 17:16:13 +0200 (CEST) Received: (authenticated bits=0) by smtp-auth.serv.Uni-Osnabrueck.DE (8.13.8/8.13.8) with ESMTP id x63FG0PQ027380 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 3 Jul 2019 17:16:12 +0200 From: Lars Kiesow To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Jul 2019 17:15:38 +0200 Message-Id: <20190703151538.24002-1-lkiesow@uos.de> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-PMX-Version: vm135.rz.Uni-Osnabrueck.DE (Univ. Osnabrueck) with PMX 6.3.2.2635362, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2019.7.3.150017, AntiVirus-Engine: 5.63.0, AntiVirus-Data: 2019.7.3.5630000 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report= HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, NO_URI_HTTPS 0, __ANY_URI 0, __CP_MEDIA_BODY 0, __CTE 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __MIME_TEXT_ONLY 0, __MIME_TEXT_P 0, __MIME_TEXT_P1 0, __MIME_VERSION 0, __NO_HTML_TAG_RAW 0, __SANE_MSGID 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0 X-PMX-Spam-Level: IIIIIIII Subject: [FFmpeg-devel] [PATCH] Ensure scaled video is divisible by n X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Lars Kiesow Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This patch adds a new option to the scale filter which ensures that the output resolution is divisible by the given integer similar to using -n in the `w` and `h` options. But this works even if the `force_original_aspect_ratio` is used. The use case for this is to set a fixed target resolution using `w` and `h`, to use the `force_original_aspect_ratio` option to make sure that the video always fits in the defined bounding box regardless of aspect ratio, but to also make sure that the calculated output resolution is divisible by n so in can be encoded with certain encoders/options if that is required. Signed-off-by: Lars Kiesow --- doc/filters.texi | 5 +++++ libavfilter/vf_scale.c | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 700a76f239..1694fdda28 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -15215,6 +15215,11 @@ Please note that this is a different thing than specifying -1 for @option{w} or @option{h}, you still need to specify the output resolution for this option to work. +@item force_divisible_by +Ensures that the output resolution is divisible by the given integer similar +to using -n in the @option{w} and @option{h} options. But this works even if +the @option{force_original_aspect_ratio} is used. + @end table The values of the @option{w} and @option{h} options are expressions diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index f741419e7e..1cc28f6a56 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -86,6 +86,7 @@ typedef struct ScaleContext { int in_v_chr_pos; int force_original_aspect_ratio; + int force_divisible_by; int nb_slices; @@ -237,10 +238,11 @@ static int config_props(AVFilterLink *outlink) goto fail; /* Note that force_original_aspect_ratio may overwrite the previous set - * dimensions so that it is not divisible by the set factors anymore. */ + * dimensions so that it is not divisible by the set factors anymore + * unless force_divisible_by is defined as well */ if (scale->force_original_aspect_ratio) { - int tmp_w = av_rescale(h, inlink->w, inlink->h); - int tmp_h = av_rescale(w, inlink->h, inlink->w); + int tmp_w = av_rescale(h, inlink->w, inlink->h) / scale->force_divisible_by * scale->force_divisible_by; + int tmp_h = av_rescale(w, inlink->h, inlink->w) / scale->force_divisible_by * scale->force_divisible_by; if (scale->force_original_aspect_ratio == 1) { w = FFMIN(tmp_w, w); @@ -589,6 +591,7 @@ static const AVOption scale_options[] = { { "out_v_chr_pos", "output vertical chroma position in luma grid/256" , OFFSET(out_v_chr_pos), AV_OPT_TYPE_INT, { .i64 = -513}, -513, 512, FLAGS }, { "out_h_chr_pos", "output horizontal chroma position in luma grid/256", OFFSET(out_h_chr_pos), AV_OPT_TYPE_INT, { .i64 = -513}, -513, 512, FLAGS }, { "force_original_aspect_ratio", "decrease or increase w/h if necessary to keep the original AR", OFFSET(force_original_aspect_ratio), AV_OPT_TYPE_INT, { .i64 = 0}, 0, 2, FLAGS, "force_oar" }, + { "force_divisible_by", "endorce that the output resolution is devisible by a defined integer", OFFSET(force_divisible_by), AV_OPT_TYPE_INT, { .i64 = 1}, 0, 256, FLAGS, "force_oar" }, { "disable", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, 0, 0, FLAGS, "force_oar" }, { "decrease", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 0, FLAGS, "force_oar" }, { "increase", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 0, FLAGS, "force_oar" },