[FFmpeg-devel] [PATCH] Add scale parameter to lensfun filter

Daniel Playfair Cal daniel.playfair.cal at gmail.com
Fri Mar 29 00:56:54 EET 2019


Hi,

Is anyone able to take a look at this?

I'd appreciate it. It's my first time posting a patch to ffmpeg (or any
mailing list) so please let me know if I've done anything wrong :)

Daniel

On Mon, Mar 25, 2019 at 1:07 PM <daniel.playfair.cal at gmail.com> wrote:

> From: Daniel Playfair Cal <daniel.playfair.cal at gmail.com>
>
> The lensfun filter wraps the lensfun library which performs
> transformations on videos to correct for lens distortion. Often this
> results in areas in the input being mapped to areas that fall outside
> the boundaries of the output. The library has a parameter called scale
> which is a scale factor applied to the output video. By decreasing it it
> is possible to regain the areas of the video which would otherwise have
> been lost. There is a special value of 0 which indicates that the
> library should automatically determine a scale factor that results in
> the output frame being filled (i.e. little or no black/unmapped areas).
>
> This patch adds a corresponding scale option to the lensfun filter which
> is passed through to the library. The existing behaviour of using the
> automatic value of 0 is retained as the default behaviour, while other
> values will be passed through to the library.
>
> Signed-off-by: Daniel Playfair Cal <daniel.playfair.cal at gmail.com>
> ---
>  doc/filters.texi         | 9 +++++++++
>  libavfilter/vf_lensfun.c | 4 +++-
>  2 files changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 4ffb392a7f..c04fe3a4b6 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -11417,6 +11417,15 @@ focus distance is only used for vignetting and
> only slightly affects the
>  vignetting correction process. If unknown, leave it at the default value
> (which
>  is 1000).
>
> + at item scale
> +The scale factor which is applied after transformation. After correction
> the
> +video is no longer necessarily rectangular. This parameter controls how
> much of
> +the resulting image is visible. The value 0 means that a value will be
> chosen
> +automatically such that there is little or no unmapped area in the output
> +image. 1.0 means that no additional scaling is done. Lower values may
> result
> +in more of the corrected image being visible, while higher values may
> avoid
> +unmapped areas in the output.
> +
>  @item target_geometry
>  The target geometry of the output image/video. The following values are
> valid
>  options:
> diff --git a/libavfilter/vf_lensfun.c b/libavfilter/vf_lensfun.c
> index 901cd9ff90..3b723dd2d0 100644
> --- a/libavfilter/vf_lensfun.c
> +++ b/libavfilter/vf_lensfun.c
> @@ -79,6 +79,7 @@ typedef struct LensfunContext {
>      float focal_length;
>      float aperture;
>      float focus_distance;
> +    float scale;
>      int target_geometry;
>      int reverse;
>      int interpolation_type;
> @@ -108,6 +109,7 @@ static const AVOption lensfun_options[] = {
>      { "focal_length", "focal length of video (zoom; constant for the
> duration of the use of this filter)", OFFSET(focal_length),
> AV_OPT_TYPE_FLOAT, {.dbl=18}, 0.0, DBL_MAX, FLAGS },
>      { "aperture", "aperture (constant for the duration of the use of this
> filter)", OFFSET(aperture), AV_OPT_TYPE_FLOAT, {.dbl=3.5}, 0.0, DBL_MAX,
> FLAGS },
>      { "focus_distance", "focus distance (constant for the duration of the
> use of this filter)", OFFSET(focus_distance), AV_OPT_TYPE_FLOAT,
> {.dbl=1000.0f}, 0.0, DBL_MAX, FLAGS },
> +    { "scale", "scale factor applied after corrections (0.0 means
> automatic scaling)", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0,
> DBL_MAX, FLAGS },
>      { "target_geometry", "target geometry of the lens correction (only
> when geometry correction is enabled)", OFFSET(target_geometry),
> AV_OPT_TYPE_INT, {.i64=LF_RECTILINEAR}, 0, INT_MAX, FLAGS, "lens_geometry"
> },
>          { "rectilinear", "rectilinear lens (default)", 0,
> AV_OPT_TYPE_CONST, {.i64=LF_RECTILINEAR}, 0, 0, FLAGS, "lens_geometry" },
>          { "fisheye", "fisheye lens", 0, AV_OPT_TYPE_CONST,
> {.i64=LF_FISHEYE}, 0, 0, FLAGS, "lens_geometry" },
> @@ -228,7 +230,7 @@ static int config_props(AVFilterLink *inlink)
>                                     lensfun->focal_length,
>                                     lensfun->aperture,
>                                     lensfun->focus_distance,
> -                                   0.0,
> +                                   lensfun->scale,
>                                     lensfun->target_geometry,
>                                     lensfun_mode,
>                                     lensfun->reverse);
> --
> 2.21.0
>
>


More information about the ffmpeg-devel mailing list