Re: [FFmpeg-devel] [PATCH 1/3] lavfi: Add pad_vaapi filter
On Ma, 2024-03-18 at 14:06 +0800, Xiang, Haihao wrote: > From: Haihao Xiang > > Signed-off-by: Haihao Xiang > --- > configure | 1 + > doc/filters.texi | 77 ++ > libavfilter/Makefile | 1 + > libavfilter/allfilters.c | 1 + > libavfilter/vf_pad_vaapi.c | 283 + > 5 files changed, 363 insertions(+) > create mode 100644 libavfilter/vf_pad_vaapi.c > > diff --git a/configure b/configure > index 2b4c4ec9a2..4f64f48b38 100755 > --- a/configure > +++ b/configure > @@ -3890,6 +3890,7 @@ vstack_qsv_filter_deps="libmfx" > vstack_qsv_filter_select="qsvvpp" > xstack_qsv_filter_deps="libmfx" > xstack_qsv_filter_select="qsvvpp" > +pad_vaapi_filter_deps="vaapi_1" > > # examples > avio_http_serve_files_deps="avformat avutil fork" > diff --git a/doc/filters.texi b/doc/filters.texi > index 913365671d..2bd1a5b9e7 100644 > --- a/doc/filters.texi > +++ b/doc/filters.texi > @@ -27941,6 +27941,83 @@ first input stream. For the syntax of this option, > check the > See @ref{xstack}. > @end table > > +@section pad_vaapi > + > +Add paddings to the input image, and place the original input at the > +provided @var{x}, @var{y} coordinates. > + > +It accepts the following options: > + > +@table @option > +@item width, w > +@item height, h > +Specify an expression for the size of the output image with the > +paddings added. If the value for @var{width} or @var{height} is 0, the > +corresponding input size is used for the output. > + > +The @var{width} expression can reference the value set by the > +@var{height} expression, and vice versa. > + > +The default value of @var{width} and @var{height} is 0. > + > +@item x > +@item y > +Specify the offsets to place the input image at within the padded area, > +with respect to the top/left border of the output image. > + > +The @var{x} expression can reference the value set by the @var{y} > +expression, and vice versa. > + > +The default value of @var{x} and @var{y} is 0. > + > +If @var{x} or @var{y} evaluate to a negative number, they'll be changed > +so the input image is centered on the padded area. > + > +@item color > +Specify the color of the padded area. For the syntax of this option, > +check the @ref{color syntax,,"Color" section in the ffmpeg-utils > +manual,ffmpeg-utils}. > + > +@item aspect > +Pad to an aspect instead to a resolution. > +@end table > + > +The value for the @var{width}, @var{height}, @var{x}, and @var{y} > +options are expressions containing the following constants: > + > +@table @option > +@item in_w > +@item in_h > +The input video width and height. > + > +@item iw > +@item ih > +These are the same as @var{in_w} and @var{in_h}. > + > +@item out_w > +@item out_h > +The output width and height (the size of the padded area), as > +specified by the @var{width} and @var{height} expressions. > + > +@item ow > +@item oh > +These are the same as @var{out_w} and @var{out_h}. > + > +@item x > +@item y > +The x and y offsets as specified by the @var{x} and @var{y} > +expressions, or NAN if not yet specified. > + > +@item a > +same as @var{iw} / @var{ih} > + > +@item sar > +input sample aspect ratio > + > +@item dar > +input display aspect ratio, it is the same as (@var{iw} / @var{ih}) * > @var{sar} > +@end table > + > @c man end VAAPI VIDEO FILTERS > > @chapter Vulkan Video Filters > diff --git a/libavfilter/Makefile b/libavfilter/Makefile > index 994d9773ba..babcc7b676 100644 > --- a/libavfilter/Makefile > +++ b/libavfilter/Makefile > @@ -581,6 +581,7 @@ OBJS-$(CONFIG_XSTACK_VAAPI_FILTER) += > vf_stack_vaapi.o framesync.o vaa > OBJS-$(CONFIG_HSTACK_QSV_FILTER) += vf_stack_qsv.o framesync.o > OBJS-$(CONFIG_VSTACK_QSV_FILTER) += vf_stack_qsv.o framesync.o > OBJS-$(CONFIG_XSTACK_QSV_FILTER) += vf_stack_qsv.o framesync.o > +OBJS-$(CONFIG_PAD_VAAPI_FILTER) += vf_pad_vaapi.o vaapi_vpp.o > > OBJS-$(CONFIG_ALLRGB_FILTER) += vsrc_testsrc.o > OBJS-$(CONFIG_ALLYUV_FILTER) += vsrc_testsrc.o > diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c > index 149bf50997..1e024b3376 100644 > --- a/libavfilter/allfilters.c > +++ b/libavfilter/allfilters.c > @@ -546,6 +546,7 @@ extern const AVFilter ff_vf_xstack_vaapi; > extern const AVFilter ff_vf_hstack_qsv; > extern const AVFilter ff_vf_vstack_qsv; > extern const AVFilter ff_vf_xstack_qsv; > +extern const AVFilter ff_vf_pad_vaapi; > > extern const AVFilter ff_vsrc_allrgb; > extern const AVFilter ff_vsrc_allyuv; > diff --git a/libavfilter/vf_pad_vaapi.c b/libavfilter/vf_pad_vaapi.c > new file mode 100644 > index 00..98f6285222 > --- /dev/null > +++ b/libavfilter/vf_pad_vaapi.c > @@ -0,0 +1,283 @@ > +/* > + * This file is part of FFmpeg. > + * > + * FFmpeg is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software
[FFmpeg-devel] [PATCH 1/3] lavfi: Add pad_vaapi filter
From: Haihao Xiang Signed-off-by: Haihao Xiang --- configure | 1 + doc/filters.texi | 77 ++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_pad_vaapi.c | 283 + 5 files changed, 363 insertions(+) create mode 100644 libavfilter/vf_pad_vaapi.c diff --git a/configure b/configure index 2b4c4ec9a2..4f64f48b38 100755 --- a/configure +++ b/configure @@ -3890,6 +3890,7 @@ vstack_qsv_filter_deps="libmfx" vstack_qsv_filter_select="qsvvpp" xstack_qsv_filter_deps="libmfx" xstack_qsv_filter_select="qsvvpp" +pad_vaapi_filter_deps="vaapi_1" # examples avio_http_serve_files_deps="avformat avutil fork" diff --git a/doc/filters.texi b/doc/filters.texi index 913365671d..2bd1a5b9e7 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -27941,6 +27941,83 @@ first input stream. For the syntax of this option, check the See @ref{xstack}. @end table +@section pad_vaapi + +Add paddings to the input image, and place the original input at the +provided @var{x}, @var{y} coordinates. + +It accepts the following options: + +@table @option +@item width, w +@item height, h +Specify an expression for the size of the output image with the +paddings added. If the value for @var{width} or @var{height} is 0, the +corresponding input size is used for the output. + +The @var{width} expression can reference the value set by the +@var{height} expression, and vice versa. + +The default value of @var{width} and @var{height} is 0. + +@item x +@item y +Specify the offsets to place the input image at within the padded area, +with respect to the top/left border of the output image. + +The @var{x} expression can reference the value set by the @var{y} +expression, and vice versa. + +The default value of @var{x} and @var{y} is 0. + +If @var{x} or @var{y} evaluate to a negative number, they'll be changed +so the input image is centered on the padded area. + +@item color +Specify the color of the padded area. For the syntax of this option, +check the @ref{color syntax,,"Color" section in the ffmpeg-utils +manual,ffmpeg-utils}. + +@item aspect +Pad to an aspect instead to a resolution. +@end table + +The value for the @var{width}, @var{height}, @var{x}, and @var{y} +options are expressions containing the following constants: + +@table @option +@item in_w +@item in_h +The input video width and height. + +@item iw +@item ih +These are the same as @var{in_w} and @var{in_h}. + +@item out_w +@item out_h +The output width and height (the size of the padded area), as +specified by the @var{width} and @var{height} expressions. + +@item ow +@item oh +These are the same as @var{out_w} and @var{out_h}. + +@item x +@item y +The x and y offsets as specified by the @var{x} and @var{y} +expressions, or NAN if not yet specified. + +@item a +same as @var{iw} / @var{ih} + +@item sar +input sample aspect ratio + +@item dar +input display aspect ratio, it is the same as (@var{iw} / @var{ih}) * @var{sar} +@end table + @c man end VAAPI VIDEO FILTERS @chapter Vulkan Video Filters diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 994d9773ba..babcc7b676 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -581,6 +581,7 @@ OBJS-$(CONFIG_XSTACK_VAAPI_FILTER) += vf_stack_vaapi.o framesync.o vaa OBJS-$(CONFIG_HSTACK_QSV_FILTER) += vf_stack_qsv.o framesync.o OBJS-$(CONFIG_VSTACK_QSV_FILTER) += vf_stack_qsv.o framesync.o OBJS-$(CONFIG_XSTACK_QSV_FILTER) += vf_stack_qsv.o framesync.o +OBJS-$(CONFIG_PAD_VAAPI_FILTER) += vf_pad_vaapi.o vaapi_vpp.o OBJS-$(CONFIG_ALLRGB_FILTER) += vsrc_testsrc.o OBJS-$(CONFIG_ALLYUV_FILTER) += vsrc_testsrc.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 149bf50997..1e024b3376 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -546,6 +546,7 @@ extern const AVFilter ff_vf_xstack_vaapi; extern const AVFilter ff_vf_hstack_qsv; extern const AVFilter ff_vf_vstack_qsv; extern const AVFilter ff_vf_xstack_qsv; +extern const AVFilter ff_vf_pad_vaapi; extern const AVFilter ff_vsrc_allrgb; extern const AVFilter ff_vsrc_allyuv; diff --git a/libavfilter/vf_pad_vaapi.c b/libavfilter/vf_pad_vaapi.c new file mode 100644 index 00..98f6285222 --- /dev/null +++ b/libavfilter/vf_pad_vaapi.c @@ -0,0 +1,283 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You