From patchwork Wed Jul 3 16:16:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lars Kiesow X-Patchwork-Id: 13809 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 DE1524499BF for ; Wed, 3 Jul 2019 19:17:15 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C0A3168AADF; Wed, 3 Jul 2019 19:17:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mta-out-1-1.rz.uni-osnabrueck.de (mta-out-1-1.rz.uni-osnabrueck.de [131.173.18.148]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 24BDD68A728 for ; Wed, 3 Jul 2019 19:17:09 +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-1-1.rz.uni-osnabrueck.de (Postfix) with ESMTPS id 72BD66E884D; Wed, 3 Jul 2019 18:17:08 +0200 (CEST) Received: (authenticated bits=0) by smtp-auth.serv.Uni-Osnabrueck.DE (8.13.8/8.13.8) with ESMTP id x63GH1SO002870 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 3 Jul 2019 18:17:08 +0200 From: Lars Kiesow To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Jul 2019 18:16:51 +0200 Message-Id: <20190703161651.27745-1-lkiesow@uos.de> X-Mailer: git-send-email 2.21.0 In-Reply-To: <69569_1562170283_5D1CD3AB_69569_8784_1_20190703181106.0a1bd2b0@lk.virtuos.uni-osnabrueck.de> References: <69569_1562170283_5D1CD3AB_69569_8784_1_20190703181106.0a1bd2b0@lk.virtuos.uni-osnabrueck.de> 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.160617, 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, IN_REP_TO 0, MSG_THREAD 0, NO_URI_HTTPS 0, REFERENCES 0, __ANY_URI 0, __CP_MEDIA_BODY 0, __CTE 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_REFERENCES 0, __HAS_X_MAILER 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_TEXT_P 0, __MIME_TEXT_P1 0, __MIME_VERSION 0, __NO_HTML_TAG_RAW 0, __REFERENCES 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..d1b486f3d6 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); @@ -592,6 +594,7 @@ static const AVOption scale_options[] = { { "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" }, + { "force_divisible_by", "enforce that the output resolution is divisible by a defined integer", OFFSET(force_divisible_by), AV_OPT_TYPE_INT, { .i64 = 1}, 1, 256, FLAGS }, { "param0", "Scaler param 0", OFFSET(param[0]), AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT }, INT_MIN, INT_MAX, FLAGS }, { "param1", "Scaler param 1", OFFSET(param[1]), AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT }, INT_MIN, INT_MAX, FLAGS }, { "nb_slices", "set the number of slices (debug purpose only)", OFFSET(nb_slices), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },