diff options
author | Lars Kiesow <lkiesow@uos.de> | 2019-08-12 15:58:14 +0200 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2019-08-13 16:48:38 +0200 |
commit | 74d4bc0fa0e0f63b89ce020893c61e6703f3f282 (patch) | |
tree | 81d69ae4982ccc3f6fea090655609dbc3764dcd7 /libavfilter/vf_scale.c | |
parent | db78bc1297ebaa51cfe5c80775808ec11ed7512b (diff) | |
download | ffmpeg-74d4bc0fa0e0f63b89ce020893c61e6703f3f282.tar.gz |
libavfilter/vf_scale: Ensure scaled video is divisible by n
This patch adds a new option to the scale filter which ensures that the
output resolution is divisible by the given integer when used together
with `force_original_aspect_ratio`. This works similar to using `-n` in
the `w` and `h` options.
This option respects the value set for `force_original_aspect_ratio`,
increasing or decreasing the resolution accordingly.
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 <lkiesow@uos.de>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavfilter/vf_scale.c')
-rw-r--r-- | libavfilter/vf_scale.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index 7aebf56ad8..bf340b8e7b 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,7 +238,8 @@ 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); @@ -245,9 +247,19 @@ static int config_props(AVFilterLink *outlink) if (scale->force_original_aspect_ratio == 1) { w = FFMIN(tmp_w, w); h = FFMIN(tmp_h, h); + if (scale->force_divisible_by > 1) { + // round down + w = w / scale->force_divisible_by * scale->force_divisible_by; + h = h / scale->force_divisible_by * scale->force_divisible_by; + } } else { w = FFMAX(tmp_w, w); h = FFMAX(tmp_h, h); + if (scale->force_divisible_by > 1) { + // round up + w = (w + scale->force_divisible_by - 1) / scale->force_divisible_by * scale->force_divisible_by; + h = (h + scale->force_divisible_by - 1) / scale->force_divisible_by * scale->force_divisible_by; + } } } @@ -600,6 +612,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 when force_original_aspect_ratio is used", 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 }, |