[FFmpeg-devel] [PATCH 2/3] lavfi: modify avfilter_get_matrix to support separate scale factors

Mark Thompson sw at jkqxz.net
Sat Jul 20 16:31:56 EEST 2019


On 20/07/2019 00:19, Jarek Samic wrote:
> ---
>  libavfilter/transform.c  | 13 ++++++++++---
>  libavfilter/transform.h  | 30 +++++++++++++++++++-----------
>  libavfilter/vf_deshake.c |  7 +++++--
>  3 files changed, 34 insertions(+), 16 deletions(-)
> 
> diff --git a/libavfilter/transform.c b/libavfilter/transform.c
> index f92fc4d42f..f65de965cd 100644
> --- a/libavfilter/transform.c
> +++ b/libavfilter/transform.c
> @@ -103,12 +103,19 @@ INTERPOLATE_METHOD(interpolate_biquadratic)
>      }
>  }
>  
> -void avfilter_get_matrix(float x_shift, float y_shift, float angle, float zoom, float *matrix) {
> -    matrix[0] = zoom * cos(angle);
> +void avfilter_get_matrix(
> +    float x_shift,
> +    float y_shift,
> +    float angle,
> +    float scale_x,
> +    float scale_y,
> +    float *matrix
> +) {
> +    matrix[0] = scale_x * cos(angle);
>      matrix[1] = -sin(angle);
>      matrix[2] = x_shift;
>      matrix[3] = -matrix[1];
> -    matrix[4] = matrix[0];
> +    matrix[4] = scale_y * cos(angle);
>      matrix[5] = y_shift;
>      matrix[6] = 0;
>      matrix[7] = 0;
> diff --git a/libavfilter/transform.h b/libavfilter/transform.h
> index 07436bfccb..0bdc9be123 100644
> --- a/libavfilter/transform.h
> +++ b/libavfilter/transform.h
> @@ -60,20 +60,28 @@ enum FillMethod {
>  #define FILL_DEFAULT FILL_ORIGINAL
>  
>  /**
> - * Get an affine transformation matrix from a given translation, rotation, and
> - * zoom factor. The matrix will look like:
> + * Get an affine transformation matrix from given translation, rotation, and
> + * zoom factors. The matrix will look like:
>   *
> - * [ zoom * cos(angle),           -sin(angle),     x_shift,
> - *          sin(angle),     zoom * cos(angle),     y_shift,
> - *                   0,                     0,           1 ]
> + * [ scale_x * cos(angle),           -sin(angle),     x_shift,
> + *             sin(angle),  scale_y * cos(angle),     y_shift,
> + *                      0,                     0,           1 ]
>   *
> - * @param x_shift horizontal translation
> - * @param y_shift vertical translation
> - * @param angle   rotation in radians
> - * @param zoom    scale percent (1.0 = 100%)
> - * @param matrix  9-item affine transformation matrix
> + * @param x_shift   horizontal translation
> + * @param y_shift   vertical translation
> + * @param angle     rotation in radians
> + * @param scale_x   x scale percent (1.0 = 100%)
> + * @param scale_y   y scale percent (1.0 = 100%)
> + * @param matrix    9-item affine transformation matrix
>   */
> -void avfilter_get_matrix(float x_shift, float y_shift, float angle, float zoom, float *matrix);
> +void avfilter_get_matrix(
> +    float x_shift,
> +    float y_shift,
> +    float angle,
> +    float scale_x,
> +    float scale_y,
> +    float *matrix
> +);

Apologies for not noticing this when we talked about it earlier, but this function is actually user-visible - it's global with an exported prefix (<http://git.videolan.org/?p=ffmpeg.git;a=blob;f=libavfilter/libavfilter.v;h=6518e5fc0960bc0c468e7cd3531634857fe4c68f;hb=HEAD>).  That means the API/ABI is fixed and you shouldn't be changing the signature.

You could make a new function (with ff_ prefix, I guess?), or just inline the code in your own filter.

Thanks,

- Mark


(I'm not sure /why/ it's exported.  A bit of searching doesn't find any code which uses it other than the existing deshake filter, so maybe it doesn't need to be part of the user API?)


More information about the ffmpeg-devel mailing list