Re: [FFmpeg-devel] [PATCH] Ensure scaled video is divisible by n

2019-07-08 Thread Lars Kiesow
Hi Michael,

> commit message should begin with a prefix like 
> avfilter/vf_scale: ...

Thanks for the hint. Will use that.

> what does this feature have to do with force_original_aspect_ratio ?
> i think it should not be under this if()

This really only makes sense when using force_original_aspect_ratio
since otherwise, you could just use something like scale=320:-2. The
force_original_aspect_ratio option is great to have a video fit within
a given maximum size but unfortunately, this may cause encoder issues
due to the resulting size.

But I guess that my documentation for this option wasn't the best. I'll
improve that so that it will hopefully become clear what the new option
is meant for.

> also the rounding is always down, it probably should be rounding to
> closest (for n=2 it doesnt matter but for larger divisibility like 16
> rounding down by 15 instead of rounding up by 1 seems not ideal

Good point. Thinking about this again, since I'm coupling this with
force_original_aspect_ratio anyway, it would definitely make sense to
have this comply to the `increase` or `decrease` options of that
setting, rounding up if `increase` is set, rounding down if `decrease`
is set.

I will update the code accordingly and send out a new patch in a moment.

Best regards,
Lars
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] Ensure scaled video is divisible by n

2019-07-05 Thread Michael Niedermayer
On Wed, Jul 03, 2019 at 06:16:51PM +0200, Lars Kiesow wrote:
> 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(-)

commit message should begin with a prefix like 
avfilter/vf_scale: ...

> 
> 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;

what does this feature have to do with force_original_aspect_ratio ?
i think it should not be under this if()

also the rounding is always down, it probably should be rounding to closest
(for n=2 it doesnt matter but for larger divisibility like 16 rounding down
by 15 instead of rounding up by 1 seems not ideal


[...]

thx

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Awnsering whenever a program halts or runs forever is
On a turing machine, in general impossible (turings halting problem).
On any real computer, always possible as a real computer has a finite number
of states N, and will either halt in less than N cycles or never halt.


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] Ensure scaled video is divisible by n

2019-07-03 Thread Lars Kiesow
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 },
-- 
2.21.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] Ensure scaled video is divisible by n

2019-07-03 Thread Lars Kiesow
On Wed, 3 Jul 2019 18:04:26 +0200
Paul B Mahol  wrote:

> On 7/3/19, Lars Kiesow  wrote:
> > Hi Paul,
> >  
> >> >  { "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", "enforce that the output resolution
> >> > is divisible by a defined integer", OFFSET(force_divisible_by),
> >> > AV_OPT_TYPE_INT, { .i64 = 1}, 0, 256, FLAGS, "force_oar" },  
> >>
> >> Are you sure you need "force_oar" ?
> >> If not, move it bellow 3 lines.  
> >
> > I'm honestly not sure since I don't know what it's used for ;-)
> >
> > From the AVOption Struct docs, I assumed that this should have the
> > same value as in force_original_aspect_ratio since it's used in the
> > same context. But it does work without and I can remove it if you
> > want me to. Should I?  
> 
> Yes, Look at belllow 3 lines, they have "force_oar" at end, because
> that gives special meaning to values.
> 
> Your option should not have these.
> 
> To confirm these, run "ffmpeg -h filter=scale" before and after you
> removed it.

Oh, got it makes sense. Thanks.
Will update the patch.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] Ensure scaled video is divisible by n

2019-07-03 Thread Paul B Mahol
On 7/3/19, Lars Kiesow  wrote:
> Hi Paul,
>
>> >  { "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", "enforce that the output resolution is
>> > divisible by a defined integer", OFFSET(force_divisible_by),
>> > AV_OPT_TYPE_INT, { .i64 = 1}, 0, 256, FLAGS, "force_oar" },
>>
>> Are you sure you need "force_oar" ?
>> If not, move it bellow 3 lines.
>
> I'm honestly not sure since I don't know what it's used for ;-)
>
> From the AVOption Struct docs, I assumed that this should have the same
> value as in force_original_aspect_ratio since it's used in the same
> context. But it does work without and I can remove it if you want me to.
> Should I?

Yes, Look at belllow 3 lines, they have "force_oar" at end, because
that gives special meaning to values.

Your option should not have these.

To confirm these, run "ffmpeg -h filter=scale" before and after you removed it.

>
> Best regards,
> Lars
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] Ensure scaled video is divisible by n

2019-07-03 Thread Lars Kiesow
Hi Paul,

> >  { "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", "enforce that the output resolution is
> > divisible by a defined integer", OFFSET(force_divisible_by),
> > AV_OPT_TYPE_INT, { .i64 = 1}, 0, 256, FLAGS, "force_oar" },  
> 
> Are you sure you need "force_oar" ?
> If not, move it bellow 3 lines.

I'm honestly not sure since I don't know what it's used for ;-)

From the AVOption Struct docs, I assumed that this should have the same
value as in force_original_aspect_ratio since it's used in the same
context. But it does work without and I can remove it if you want me to.
Should I?

Best regards,
Lars
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] Ensure scaled video is divisible by n

2019-07-03 Thread Paul B Mahol
On 7/3/19, Lars Kiesow  wrote:
> 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..c02b82dd07 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", "enforce that the output resolution is
> divisible by a defined integer", OFFSET(force_divisible_by),
> AV_OPT_TYPE_INT, { .i64 = 1}, 0, 256, FLAGS, "force_oar" },

Are you sure you need "force_oar" ?
If not, move it bellow 3 lines.

>  { "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" },
> --
> 2.21.0
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] Ensure scaled video is divisible by n

2019-07-03 Thread Lars Kiesow
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..c02b82dd07 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", "enforce that the output resolution is divisible 
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" },
-- 
2.21.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] Ensure scaled video is divisible by n

2019-07-03 Thread Paul B Mahol
On 7/3/19, Lars Kiesow  wrote:
> 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),

endorce and devisible are typos.

> 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" },
> --
> 2.21.0
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] Ensure scaled video is divisible by n

2019-07-03 Thread Lars Kiesow
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" },
-- 
2.21.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".