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

2019-08-14 Thread Lars Kiesow
Hi Michael,

> will apply

Thanks.
___
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] libavfilter/vf_scale: Ensure scaled video is divisible by n

2019-08-13 Thread Michael Niedermayer
On Mon, Aug 12, 2019 at 03:58:14PM +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 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 
> ---
>  doc/filters.texi   | 12 
>  libavfilter/vf_scale.c | 15 ++-
>  2 files changed, 26 insertions(+), 1 deletion(-)

will apply

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Frequently ignored answer#1 FFmpeg bugs should be sent to our bugtracker. User
questions about the command line tools should be sent to the ffmpeg-user ML.
And questions about how to use libav* should be sent to the libav-user ML.


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".

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

2019-08-12 Thread Lars Kiesow
Hi Michael,

> > + if (scale->force_divisible_by > 1) {
> > + w = ceil(w / (float)scale->force_divisible_by) *
> > scale->force_divisible_by;
> > + h = ceil(h / (float)scale->force_divisible_by) *
> > scale->force_divisible_by;  
> 
> you dont need float here and its better not to use float when not
> needed so theres a chance less for platform bitexactness issues

Updated the patch so it's only using integers as well when rounding up.
I hope this works for you.

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".

[FFmpeg-devel] [PATCH] libavfilter/vf_scale: Ensure scaled video is divisible by n

2019-08-12 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 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 
---
 doc/filters.texi   | 12 
 libavfilter/vf_scale.c | 15 ++-
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index e081cdc7bc..01262d845e 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -15369,6 +15369,18 @@ 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 when used together with @option{force_original_aspect_ratio}. 
This
+works similar to using -n in the @option{w} and @option{h} options.
+
+This option respects the value set for @option{force_original_aspect_ratio},
+increasing or decreasing the resolution accordingly. This may slightly modify
+the video's aspect ration.
+
+This can be handy, for example, if you want to have a video fit within a 
defined
+resolution using the @option{force_original_aspect_ratio} option but have
+encoder restrictions when it comes to width or height.
+
 @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 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 },
-- 
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] libavfilter/vf_scale: Ensure scaled video is divisible by n

2019-08-11 Thread Michael Niedermayer
On Mon, Jul 08, 2019 at 05:43:40PM +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 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 
> ---
>  doc/filters.texi   | 12 
>  libavfilter/vf_scale.c | 13 -
>  2 files changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index ee6a93ffbf..2de71d9820 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -15231,6 +15231,18 @@ 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 when used together with @option{force_original_aspect_ratio}. 
> This
> +works similar to using -n in the @option{w} and @option{h} options.
> +
> +This option respects the value set for @option{force_original_aspect_ratio},
> +increasing or decreasing the resolution accordingly. This may slightly modify
> +the video's aspect ration.
> +
> +This can be handy, for example, if you want to have a video fit within a 
> defined
> +resolution using the @option{force_original_aspect_ratio} option but have
> +encoder restrictions when it comes to width or height.
> +
>  @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 7aebf56ad8..3ce6cdd1d5 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,17 @@ 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) {
> + 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) {
> + w = ceil(w / (float)scale->force_divisible_by) * 
> scale->force_divisible_by;
> + h = ceil(h / (float)scale->force_divisible_by) * 
> scale->force_divisible_by;

you dont need float here and its better not to use float when not needed
so theres a chance less for platform bitexactness issues

Thanks

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Modern terrorism, a quick summary: Need oil, start war with country that
has oil, kill hundread thousand in war. Let country fall into chaos,
be surprised about raise of fundamantalists. Drop more bombs, kill more
people, be surprised about them taking revenge and drop even more bombs
and strip your own citizens of their rights and freedoms. to be continued


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".

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

2019-08-11 Thread Paul B Mahol
Michael, can you merge this?

On Fri, Aug 9, 2019 at 10:16 AM Lars Kiesow  wrote:

> Well… then, can anyone merge this patch?
> Best regards,
> Lars
>
> On Mon, 5 Aug 2019 14:31:43 +0200
> Paul B Mahol  wrote:
>
> > On Mon, Aug 5, 2019 at 1:31 PM Lars Kiesow  wrote:
> >
> > > Hi everyone,
> > > this is now open for nearly a month with no more comments or change
> > > requests. Anything else I should do to get this merged?
> > > Best regards,
> > >
> >
> > Yes, ping it more frequently, until its merged.
> > Waiting for months will not help as people are busy.
> >
> >
> > > Lars
> > >
> > >
> > > On Mon,  8 Jul 2019 17:43:40 +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 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 
> > > > ---
> > > >  doc/filters.texi   | 12 
> > > >  libavfilter/vf_scale.c | 13 -
> > > >  2 files changed, 24 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/doc/filters.texi b/doc/filters.texi
> > > > index ee6a93ffbf..2de71d9820 100644
> > > > --- a/doc/filters.texi
> > > > +++ b/doc/filters.texi
> > > > @@ -15231,6 +15231,18 @@ 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 when used together with
> > > > @option{force_original_aspect_ratio}. This +works similar to
> > > > using -n in the @option{w} and @option{h} options. +
> > > > +This option respects the value set for
> > > > @option{force_original_aspect_ratio}, +increasing or decreasing
> > > > the resolution accordingly. This may slightly modify +the video's
> > > > aspect ration. +
> > > > +This can be handy, for example, if you want to have a video fit
> > > > within a defined +resolution using the
> > > > @option{force_original_aspect_ratio} option but have +encoder
> > > > restrictions when it comes to width or height. +
> > > >  @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 7aebf56ad8..3ce6cdd1d5 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,17 @@ 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) {
> > > > + 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) {
> > > > + w = ceil(w / (float)scale->force_divisible_by) *
> > > > scale->force_divisible_by;
> > > > + h = ceil(h / (float)scale->force_divisible_by) *
> > > > scale->force_divisible_by;
> > > > + }
> > > >  }
> > > >  }
> > > >
> > > > @@ -600,6 +610,7 @@ 

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

2019-08-09 Thread Lars Kiesow
Well… then, can anyone merge this patch?
Best regards,
Lars

On Mon, 5 Aug 2019 14:31:43 +0200
Paul B Mahol  wrote:

> On Mon, Aug 5, 2019 at 1:31 PM Lars Kiesow  wrote:
> 
> > Hi everyone,
> > this is now open for nearly a month with no more comments or change
> > requests. Anything else I should do to get this merged?
> > Best regards,
> >  
> 
> Yes, ping it more frequently, until its merged.
> Waiting for months will not help as people are busy.
> 
> 
> > Lars
> >
> >
> > On Mon,  8 Jul 2019 17:43:40 +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 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 
> > > ---
> > >  doc/filters.texi   | 12 
> > >  libavfilter/vf_scale.c | 13 -
> > >  2 files changed, 24 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/doc/filters.texi b/doc/filters.texi
> > > index ee6a93ffbf..2de71d9820 100644
> > > --- a/doc/filters.texi
> > > +++ b/doc/filters.texi
> > > @@ -15231,6 +15231,18 @@ 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 when used together with
> > > @option{force_original_aspect_ratio}. This +works similar to
> > > using -n in the @option{w} and @option{h} options. +
> > > +This option respects the value set for
> > > @option{force_original_aspect_ratio}, +increasing or decreasing
> > > the resolution accordingly. This may slightly modify +the video's
> > > aspect ration. +
> > > +This can be handy, for example, if you want to have a video fit
> > > within a defined +resolution using the
> > > @option{force_original_aspect_ratio} option but have +encoder
> > > restrictions when it comes to width or height. +
> > >  @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 7aebf56ad8..3ce6cdd1d5 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,17 @@ 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) {
> > > + 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) {
> > > + w = ceil(w / (float)scale->force_divisible_by) *
> > > scale->force_divisible_by;
> > > + h = ceil(h / (float)scale->force_divisible_by) *
> > > scale->force_divisible_by;
> > > + }
> > >  }
> > >  }
> > >
> > > @@ -600,6 +610,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, 

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

2019-08-05 Thread Paul B Mahol
On Mon, Aug 5, 2019 at 1:31 PM Lars Kiesow  wrote:

> Hi everyone,
> this is now open for nearly a month with no more comments or change
> requests. Anything else I should do to get this merged?
> Best regards,
>

Yes, ping it more frequently, until its merged.
Waiting for months will not help as people are busy.


> Lars
>
>
> On Mon,  8 Jul 2019 17:43:40 +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 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 
> > ---
> >  doc/filters.texi   | 12 
> >  libavfilter/vf_scale.c | 13 -
> >  2 files changed, 24 insertions(+), 1 deletion(-)
> >
> > diff --git a/doc/filters.texi b/doc/filters.texi
> > index ee6a93ffbf..2de71d9820 100644
> > --- a/doc/filters.texi
> > +++ b/doc/filters.texi
> > @@ -15231,6 +15231,18 @@ 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 when used together with
> > @option{force_original_aspect_ratio}. This +works similar to using -n
> > in the @option{w} and @option{h} options. +
> > +This option respects the value set for
> > @option{force_original_aspect_ratio}, +increasing or decreasing the
> > resolution accordingly. This may slightly modify +the video's aspect
> > ration. +
> > +This can be handy, for example, if you want to have a video fit
> > within a defined +resolution using the
> > @option{force_original_aspect_ratio} option but have +encoder
> > restrictions when it comes to width or height. +
> >  @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 7aebf56ad8..3ce6cdd1d5 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,17 @@ 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) {
> > + 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) {
> > + w = ceil(w / (float)scale->force_divisible_by) *
> > scale->force_divisible_by;
> > + h = ceil(h / (float)scale->force_divisible_by) *
> > scale->force_divisible_by;
> > + }
> >  }
> >  }
> >
> > @@ -600,6 +610,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  },
> 

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

2019-08-05 Thread Lars Kiesow
Hi everyone,
this is now open for nearly a month with no more comments or change
requests. Anything else I should do to get this merged?
Best regards,
Lars


On Mon,  8 Jul 2019 17:43:40 +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 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 
> ---
>  doc/filters.texi   | 12 
>  libavfilter/vf_scale.c | 13 -
>  2 files changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index ee6a93ffbf..2de71d9820 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -15231,6 +15231,18 @@ 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 when used together with
> @option{force_original_aspect_ratio}. This +works similar to using -n
> in the @option{w} and @option{h} options. +
> +This option respects the value set for
> @option{force_original_aspect_ratio}, +increasing or decreasing the
> resolution accordingly. This may slightly modify +the video's aspect
> ration. +
> +This can be handy, for example, if you want to have a video fit
> within a defined +resolution using the
> @option{force_original_aspect_ratio} option but have +encoder
> restrictions when it comes to width or height. +
>  @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 7aebf56ad8..3ce6cdd1d5 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,17 @@ 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) {
> + 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) {
> + w = ceil(w / (float)scale->force_divisible_by) *
> scale->force_divisible_by;
> + h = ceil(h / (float)scale->force_divisible_by) *
> scale->force_divisible_by;
> + }
>  }
>  }
>  
> @@ -600,6 +610,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 },

___
ffmpeg-devel 

[FFmpeg-devel] [PATCH] libavfilter/vf_scale: Ensure scaled video is divisible by n

2019-07-08 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 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 
---
 doc/filters.texi   | 12 
 libavfilter/vf_scale.c | 13 -
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index ee6a93ffbf..2de71d9820 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -15231,6 +15231,18 @@ 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 when used together with @option{force_original_aspect_ratio}. 
This
+works similar to using -n in the @option{w} and @option{h} options.
+
+This option respects the value set for @option{force_original_aspect_ratio},
+increasing or decreasing the resolution accordingly. This may slightly modify
+the video's aspect ration.
+
+This can be handy, for example, if you want to have a video fit within a 
defined
+resolution using the @option{force_original_aspect_ratio} option but have
+encoder restrictions when it comes to width or height.
+
 @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 7aebf56ad8..3ce6cdd1d5 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,17 @@ 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) {
+ 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) {
+ w = ceil(w / (float)scale->force_divisible_by) * 
scale->force_divisible_by;
+ h = ceil(h / (float)scale->force_divisible_by) * 
scale->force_divisible_by;
+ }
 }
 }
 
@@ -600,6 +610,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 },
-- 
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".