Re: [FFmpeg-devel] [PATCH V3] libavfilter/vaapi: enable vaapi rotation feature via call Intel iHD driver
Thanks Mark, I am considering it. I will send a new patch including both vaapi rotation and mirroring. > -Original Message- > From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of > Mark Thompson > Sent: Thursday, November 1, 2018 7:36 AM > To: ffmpeg-devel@ffmpeg.org > Subject: Re: [FFmpeg-devel] [PATCH V3] libavfilter/vaapi: enable vaapi > rotation feature via call Intel iHD driver > > On 31/10/18 02:43, Zachary Zhou wrote: > > libavfilter/vaapi: enable vaapi rotation feature via call Intel iHD > > driver > > I'd make the title something like "libavfilter: add rotate_vaapi filter". > There is > no reason to mention a particular implementation - anyone can implement > this API. > > > It supports clockwise rotation by 0/90/180/270 degrees defined in > > va/va_vpp.h, tested following command line on SKL platform > > > > ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 > > -hwaccel_output_format vaapi -i input.264 -vf "rotation_vaapi=angle=180" > > -c:v h264_vaapi output.h264 > > > > Signed-off-by: Zachary Zhou > > --- > > configure | 4 + > > libavfilter/Makefile | 1 + > > libavfilter/allfilters.c | 1 + > > libavfilter/vaapi_vpp.h | 1 + > > libavfilter/vf_rotate_vaapi.c | 252 > > ++ > > 5 files changed, 259 insertions(+) > > create mode 100644 libavfilter/vf_rotate_vaapi.c > > Referencing other discussion, I think this filter should do both the rotation > and > mirroring features. I don't know what the filter should be called, though - > matching the transpose filter as transpose_vaapi seems the most logical > choice to me, but I admit the exact options aren't quite right. > > The effect of rotating by one or three right angles surprised me - I would > expect the size to be changed as well, so a 1280x720 input becomes a > 720x1280 output rather than squishing the video. > > > diff --git a/configure b/configure > > index 85d5dd5962..4b5718135e 100755 > > --- a/configure > > +++ b/configure > > @@ -3439,6 +3439,7 @@ scale_filter_deps="swscale" > > scale_qsv_filter_deps="libmfx" > > select_filter_select="pixelutils" > > sharpness_vaapi_filter_deps="vaapi" > > +rotation_vaapi_filter_deps="vaapi" > > showcqt_filter_deps="avcodec avformat swscale" > > showcqt_filter_suggest="libfontconfig libfreetype" > > showcqt_filter_select="fft" > > @@ -6390,6 +6391,9 @@ if enabled vaapi; then > > fi > > > > check_cpp_condition vaapi_1 "va/va.h" "VA_CHECK_VERSION(1, 0, 0)" > > +if ! check_struct "va/va.h" "struct _VAProcPipelineCaps" > > rotation_flags; > then > > +disable rotation_vaapi_filter > > +fi > > Use the dependencies instead like other components. (See > vp9_vaapi_hwaccel for a check_struct like this one.) > > > fi > > > > if enabled_all opencl libdrm ; then > > diff --git a/libavfilter/Makefile b/libavfilter/Makefile index > > 108a2f87d7..534650364a 100644 > > --- a/libavfilter/Makefile > > +++ b/libavfilter/Makefile > > @@ -349,6 +349,7 @@ OBJS-$(CONFIG_SETRANGE_FILTER) += > vf_setparams.o > > OBJS-$(CONFIG_SETSAR_FILTER) += vf_aspect.o > > OBJS-$(CONFIG_SETTB_FILTER) += settb.o > > OBJS-$(CONFIG_SHARPNESS_VAAPI_FILTER)+= vf_misc_vaapi.o > vaapi_vpp.o > > +OBJS-$(CONFIG_ROTATION_VAAPI_FILTER) += vf_rotate_vaapi.o > vaapi_vpp.o > > OBJS-$(CONFIG_SHOWINFO_FILTER) += vf_showinfo.o > > OBJS-$(CONFIG_SHOWPALETTE_FILTER)+= vf_showpalette.o > > OBJS-$(CONFIG_SHUFFLEFRAMES_FILTER) += vf_shuffleframes.o > > diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index > > 557590850b..4b90a7f440 100644 > > --- a/libavfilter/allfilters.c > > +++ b/libavfilter/allfilters.c > > @@ -333,6 +333,7 @@ extern AVFilter ff_vf_setrange; extern AVFilter > > ff_vf_setsar; extern AVFilter ff_vf_settb; extern AVFilter > > ff_vf_sharpness_vaapi; > > +extern AVFilter ff_vf_rotation_vaapi; > > extern AVFilter ff_vf_showinfo; > > extern AVFilter ff_vf_showpalette; > > extern AVFilter ff_vf_shuffleframes; > > diff --git a/libavfilter/vaapi_vpp.h b/libavfilter/vaapi_vpp.h index > > 0bc31018d4..cfe19b689f 100644 > > --- a/libavfilter/vaapi_vpp.h > > +++ b/libavfilter/vaapi_vpp.h > > @@ -44,6 +44,7 @@ t
Re: [FFmpeg-devel] [PATCH V3] libavfilter/vaapi: enable vaapi rotation feature via call Intel iHD driver
On 31/10/18 02:43, Zachary Zhou wrote: > libavfilter/vaapi: enable vaapi rotation feature via call Intel iHD driver I'd make the title something like "libavfilter: add rotate_vaapi filter". There is no reason to mention a particular implementation - anyone can implement this API. > It supports clockwise rotation by 0/90/180/270 degrees defined in > va/va_vpp.h, tested following command line on SKL platform > > ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 > -hwaccel_output_format vaapi -i input.264 -vf "rotation_vaapi=angle=180" > -c:v h264_vaapi output.h264 > > Signed-off-by: Zachary Zhou > --- > configure | 4 + > libavfilter/Makefile | 1 + > libavfilter/allfilters.c | 1 + > libavfilter/vaapi_vpp.h | 1 + > libavfilter/vf_rotate_vaapi.c | 252 ++ > 5 files changed, 259 insertions(+) > create mode 100644 libavfilter/vf_rotate_vaapi.c Referencing other discussion, I think this filter should do both the rotation and mirroring features. I don't know what the filter should be called, though - matching the transpose filter as transpose_vaapi seems the most logical choice to me, but I admit the exact options aren't quite right. The effect of rotating by one or three right angles surprised me - I would expect the size to be changed as well, so a 1280x720 input becomes a 720x1280 output rather than squishing the video. > diff --git a/configure b/configure > index 85d5dd5962..4b5718135e 100755 > --- a/configure > +++ b/configure > @@ -3439,6 +3439,7 @@ scale_filter_deps="swscale" > scale_qsv_filter_deps="libmfx" > select_filter_select="pixelutils" > sharpness_vaapi_filter_deps="vaapi" > +rotation_vaapi_filter_deps="vaapi" > showcqt_filter_deps="avcodec avformat swscale" > showcqt_filter_suggest="libfontconfig libfreetype" > showcqt_filter_select="fft" > @@ -6390,6 +6391,9 @@ if enabled vaapi; then > fi > > check_cpp_condition vaapi_1 "va/va.h" "VA_CHECK_VERSION(1, 0, 0)" > +if ! check_struct "va/va.h" "struct _VAProcPipelineCaps" rotation_flags; > then > +disable rotation_vaapi_filter > +fi Use the dependencies instead like other components. (See vp9_vaapi_hwaccel for a check_struct like this one.) > fi > > if enabled_all opencl libdrm ; then > diff --git a/libavfilter/Makefile b/libavfilter/Makefile > index 108a2f87d7..534650364a 100644 > --- a/libavfilter/Makefile > +++ b/libavfilter/Makefile > @@ -349,6 +349,7 @@ OBJS-$(CONFIG_SETRANGE_FILTER) += > vf_setparams.o > OBJS-$(CONFIG_SETSAR_FILTER) += vf_aspect.o > OBJS-$(CONFIG_SETTB_FILTER) += settb.o > OBJS-$(CONFIG_SHARPNESS_VAAPI_FILTER)+= vf_misc_vaapi.o vaapi_vpp.o > +OBJS-$(CONFIG_ROTATION_VAAPI_FILTER) += vf_rotate_vaapi.o vaapi_vpp.o > OBJS-$(CONFIG_SHOWINFO_FILTER) += vf_showinfo.o > OBJS-$(CONFIG_SHOWPALETTE_FILTER)+= vf_showpalette.o > OBJS-$(CONFIG_SHUFFLEFRAMES_FILTER) += vf_shuffleframes.o > diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c > index 557590850b..4b90a7f440 100644 > --- a/libavfilter/allfilters.c > +++ b/libavfilter/allfilters.c > @@ -333,6 +333,7 @@ extern AVFilter ff_vf_setrange; > extern AVFilter ff_vf_setsar; > extern AVFilter ff_vf_settb; > extern AVFilter ff_vf_sharpness_vaapi; > +extern AVFilter ff_vf_rotation_vaapi; > extern AVFilter ff_vf_showinfo; > extern AVFilter ff_vf_showpalette; > extern AVFilter ff_vf_shuffleframes; > diff --git a/libavfilter/vaapi_vpp.h b/libavfilter/vaapi_vpp.h > index 0bc31018d4..cfe19b689f 100644 > --- a/libavfilter/vaapi_vpp.h > +++ b/libavfilter/vaapi_vpp.h > @@ -44,6 +44,7 @@ typedef struct VAAPIVPPContext { > int output_width; // computed width > int output_height; // computed height > > +int rotation_state; No reason to put this in the common context, it can be in the rotate-specific one. > VABufferID filter_buffers[VAProcFilterCount]; > intnb_filter_buffers; > > diff --git a/libavfilter/vf_rotate_vaapi.c b/libavfilter/vf_rotate_vaapi.c > new file mode 100644 > index 00..82e2a0fce4 > --- /dev/null > +++ b/libavfilter/vf_rotate_vaapi.c > @@ -0,0 +1,252 @@ > +/* > + * 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 should have received a copy of the GNU Lesser General Public > + * License along with FFmpeg; if not, write to the Free
Re: [FFmpeg-devel] [PATCH V3] libavfilter/vaapi: enable vaapi rotation feature via call Intel iHD driver
On 31/10/18 02:43, Zachary Zhou wrote: > libavfilter/vaapi: enable vaapi rotation feature via call Intel iHD driver I'd make the title something like "libavfilter: add rotate_vaapi filter". There is no reason to mention a particular implementation - anyone can implement this API. > It supports clockwise rotation by 0/90/180/270 degrees defined in > va/va_vpp.h, tested following command line on SKL platform > > ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 > -hwaccel_output_format vaapi -i input.264 -vf "rotation_vaapi=angle=180" > -c:v h264_vaapi output.h264 > > Signed-off-by: Zachary Zhou > --- > configure | 4 + > libavfilter/Makefile | 1 + > libavfilter/allfilters.c | 1 + > libavfilter/vaapi_vpp.h | 1 + > libavfilter/vf_rotate_vaapi.c | 252 ++ > 5 files changed, 259 insertions(+) > create mode 100644 libavfilter/vf_rotate_vaapi.c Referencing other discussion, I think this filter should do both the rotation and mirroring features. I don't know what the filter should be called, though - matching the transpose filter as transpose_vaapi seems the most logical choice to me, but I admit the exact options aren't quite right. The effect of rotating by one or three right angles surprised me - I would expect the size to be changed as well, so a 1280x720 input becomes a 720x1280 output rather than squishing the video. > diff --git a/configure b/configure > index 85d5dd5962..4b5718135e 100755 > --- a/configure > +++ b/configure > @@ -3439,6 +3439,7 @@ scale_filter_deps="swscale" > scale_qsv_filter_deps="libmfx" > select_filter_select="pixelutils" > sharpness_vaapi_filter_deps="vaapi" > +rotation_vaapi_filter_deps="vaapi" > showcqt_filter_deps="avcodec avformat swscale" > showcqt_filter_suggest="libfontconfig libfreetype" > showcqt_filter_select="fft" > @@ -6390,6 +6391,9 @@ if enabled vaapi; then > fi > > check_cpp_condition vaapi_1 "va/va.h" "VA_CHECK_VERSION(1, 0, 0)" > +if ! check_struct "va/va.h" "struct _VAProcPipelineCaps" rotation_flags; > then > +disable rotation_vaapi_filter > +fi Use the dependencies instead like other components. (See vp9_vaapi_hwaccel for a check_struct like this one.) > fi > > if enabled_all opencl libdrm ; then > diff --git a/libavfilter/Makefile b/libavfilter/Makefile > index 108a2f87d7..534650364a 100644 > --- a/libavfilter/Makefile > +++ b/libavfilter/Makefile > @@ -349,6 +349,7 @@ OBJS-$(CONFIG_SETRANGE_FILTER) += > vf_setparams.o > OBJS-$(CONFIG_SETSAR_FILTER) += vf_aspect.o > OBJS-$(CONFIG_SETTB_FILTER) += settb.o > OBJS-$(CONFIG_SHARPNESS_VAAPI_FILTER)+= vf_misc_vaapi.o vaapi_vpp.o > +OBJS-$(CONFIG_ROTATION_VAAPI_FILTER) += vf_rotate_vaapi.o vaapi_vpp.o > OBJS-$(CONFIG_SHOWINFO_FILTER) += vf_showinfo.o > OBJS-$(CONFIG_SHOWPALETTE_FILTER)+= vf_showpalette.o > OBJS-$(CONFIG_SHUFFLEFRAMES_FILTER) += vf_shuffleframes.o > diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c > index 557590850b..4b90a7f440 100644 > --- a/libavfilter/allfilters.c > +++ b/libavfilter/allfilters.c > @@ -333,6 +333,7 @@ extern AVFilter ff_vf_setrange; > extern AVFilter ff_vf_setsar; > extern AVFilter ff_vf_settb; > extern AVFilter ff_vf_sharpness_vaapi; > +extern AVFilter ff_vf_rotation_vaapi; > extern AVFilter ff_vf_showinfo; > extern AVFilter ff_vf_showpalette; > extern AVFilter ff_vf_shuffleframes; > diff --git a/libavfilter/vaapi_vpp.h b/libavfilter/vaapi_vpp.h > index 0bc31018d4..cfe19b689f 100644 > --- a/libavfilter/vaapi_vpp.h > +++ b/libavfilter/vaapi_vpp.h > @@ -44,6 +44,7 @@ typedef struct VAAPIVPPContext { > int output_width; // computed width > int output_height; // computed height > > +int rotation_state; No reason to put this in the common context, it can be in the rotate-specific one. > VABufferID filter_buffers[VAProcFilterCount]; > intnb_filter_buffers; > > diff --git a/libavfilter/vf_rotate_vaapi.c b/libavfilter/vf_rotate_vaapi.c > new file mode 100644 > index 00..82e2a0fce4 > --- /dev/null > +++ b/libavfilter/vf_rotate_vaapi.c > @@ -0,0 +1,252 @@ > +/* > + * 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 should have received a copy of the GNU Lesser General Public > + * License along with FFmpeg; if not, write to the Free
[FFmpeg-devel] [PATCH V3] libavfilter/vaapi: enable vaapi rotation feature via call Intel iHD driver
It supports clockwise rotation by 0/90/180/270 degrees defined in va/va_vpp.h, tested following command line on SKL platform ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i input.264 -vf "rotation_vaapi=angle=180" -c:v h264_vaapi output.h264 Signed-off-by: Zachary Zhou --- configure | 4 + libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vaapi_vpp.h | 1 + libavfilter/vf_rotate_vaapi.c | 252 ++ 5 files changed, 259 insertions(+) create mode 100644 libavfilter/vf_rotate_vaapi.c diff --git a/configure b/configure index 85d5dd5962..4b5718135e 100755 --- a/configure +++ b/configure @@ -3439,6 +3439,7 @@ scale_filter_deps="swscale" scale_qsv_filter_deps="libmfx" select_filter_select="pixelutils" sharpness_vaapi_filter_deps="vaapi" +rotation_vaapi_filter_deps="vaapi" showcqt_filter_deps="avcodec avformat swscale" showcqt_filter_suggest="libfontconfig libfreetype" showcqt_filter_select="fft" @@ -6390,6 +6391,9 @@ if enabled vaapi; then fi check_cpp_condition vaapi_1 "va/va.h" "VA_CHECK_VERSION(1, 0, 0)" +if ! check_struct "va/va.h" "struct _VAProcPipelineCaps" rotation_flags; then +disable rotation_vaapi_filter +fi fi if enabled_all opencl libdrm ; then diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 108a2f87d7..534650364a 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -349,6 +349,7 @@ OBJS-$(CONFIG_SETRANGE_FILTER) += vf_setparams.o OBJS-$(CONFIG_SETSAR_FILTER) += vf_aspect.o OBJS-$(CONFIG_SETTB_FILTER) += settb.o OBJS-$(CONFIG_SHARPNESS_VAAPI_FILTER)+= vf_misc_vaapi.o vaapi_vpp.o +OBJS-$(CONFIG_ROTATION_VAAPI_FILTER) += vf_rotate_vaapi.o vaapi_vpp.o OBJS-$(CONFIG_SHOWINFO_FILTER) += vf_showinfo.o OBJS-$(CONFIG_SHOWPALETTE_FILTER)+= vf_showpalette.o OBJS-$(CONFIG_SHUFFLEFRAMES_FILTER) += vf_shuffleframes.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 557590850b..4b90a7f440 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -333,6 +333,7 @@ extern AVFilter ff_vf_setrange; extern AVFilter ff_vf_setsar; extern AVFilter ff_vf_settb; extern AVFilter ff_vf_sharpness_vaapi; +extern AVFilter ff_vf_rotation_vaapi; extern AVFilter ff_vf_showinfo; extern AVFilter ff_vf_showpalette; extern AVFilter ff_vf_shuffleframes; diff --git a/libavfilter/vaapi_vpp.h b/libavfilter/vaapi_vpp.h index 0bc31018d4..cfe19b689f 100644 --- a/libavfilter/vaapi_vpp.h +++ b/libavfilter/vaapi_vpp.h @@ -44,6 +44,7 @@ typedef struct VAAPIVPPContext { int output_width; // computed width int output_height; // computed height +int rotation_state; VABufferID filter_buffers[VAProcFilterCount]; intnb_filter_buffers; diff --git a/libavfilter/vf_rotate_vaapi.c b/libavfilter/vf_rotate_vaapi.c new file mode 100644 index 00..82e2a0fce4 --- /dev/null +++ b/libavfilter/vf_rotate_vaapi.c @@ -0,0 +1,252 @@ +/* + * 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 should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include + +#include "libavutil/avassert.h" +#include "libavutil/mem.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" + +#include "avfilter.h" +#include "formats.h" +#include "internal.h" +#include "vaapi_vpp.h" + +// Rotation angle values +enum RotationAngle { +ROTATION_0 = 0, +ROTATION_90 = 90, +ROTATION_180 = 180, +ROTATION_270 = 270, + +ROTATION_MIN = ROTATION_0, +ROTATION_MAX = ROTATION_270, +ROTATION_DEFAULT = ROTATION_0, +}; + +typedef struct RotationVAAPIContext { +VAAPIVPPContext vpp_ctx; // must be the first field + +int rotation; +} RotationVAAPIContext; + +static int rotation_vaapi_build_filter_params(AVFilterContext *avctx) +{ +VAAPIVPPContext *vpp_ctx = avctx->priv; +RotationVAAPIContext *ctx = avctx->priv; + +VAStatus vas; +int support_flag; + +VAProcPipelineCaps pipeline_caps; + +memset(_caps, 0, sizeof(pipeline_caps)); +vas = vaQueryVideoProcPipelineCaps(vpp_ctx->hwctx->display, + vpp_ctx->va_context, +