Re: [FFmpeg-devel] [PATCH v2] libavfilter: add transpose_vaapi filter
The patch optimized the ffmpeg transcode pipeline, it saves hwdownload/hwupload filters in the pipeline. It can get about 2.7x performance against software transpose filter as my test on 1080P. time ffmpeg -loglevel verbose -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i crowd_run_1080p.264 -vf transpose_vaapi=rotate=90:vflip -c:v h264_vaapi -y out-a.h264 real0m3.326s user0m1.225s sys 0m0.744s time ffmpeg -loglevel verbose -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i crowd_run_1080p.264 -vf hwdownload,transpose=clock_flip,format=nv12,hwupload -c:v h264_vaapi -y out-b.h264 real0m4.132s user0m4.815s sys0m0.534s (/ (+ 4.815 0.534) (+ 1.225 0.744)) = 2.7166074149314374 > -Original Message- > From: Zhou, Zachary > Sent: Wednesday, November 14, 2018 9:37 AM > To: ffmpeg-devel@ffmpeg.org > Cc: Zhou, Zachary > Subject: [PATCH v2] libavfilter: add transpose_vaapi filter > > It supports clockwise rotation by 0/90/180/270 degrees and mirroring by > horizontal/vertical. video size is changed when rotation by 90/270. > > ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 - > hwaccel_output_format vaapi -i input.264 -vf > "transpose_vaapi=rotate=90:mirror=1" > -c:v h264_vaapi output.h264 > > Signed-off-by: Zachary Zhou > --- > configure| 2 + > libavfilter/Makefile | 1 + > libavfilter/allfilters.c | 1 + > libavfilter/vf_transpose_vaapi.c | 337 +++ > 4 files changed, 341 insertions(+) > create mode 100644 libavfilter/vf_transpose_vaapi.c > > diff --git a/configure b/configure > index 85d5dd5962..f62d2a27ca 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" > +transpose_vaapi_filter_deps="vaapi VAProcPipelineCaps_rotation_flags" > showcqt_filter_deps="avcodec avformat swscale" > showcqt_filter_suggest="libfontconfig libfreetype" > showcqt_filter_select="fft" > @@ -5961,6 +5962,7 @@ check_type "d3d9.h dxva2api.h" > DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602 > > check_type "va/va.h va/va_dec_hevc.h" "VAPictureParameterBufferHEVC" > check_struct "va/va.h" "VADecPictureParameterBufferVP9" bit_depth > +check_struct "va/va.h" "VAProcPipelineCaps" rotation_flags > check_type "va/va.h va/va_enc_hevc.h" > "VAEncPictureParameterBufferHEVC" > check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG" > check_type "va/va.h va/va_enc_vp8.h" "VAEncPictureParameterBufferVP8" > diff --git a/libavfilter/Makefile b/libavfilter/Makefile index > 62cc2f561f..813b174ddd 100644 > --- a/libavfilter/Makefile > +++ b/libavfilter/Makefile > @@ -346,6 +346,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_TRANSPOSE_VAAPI_FILTER)+= vf_transpose_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 > 5e72803b13..e5b0571aa8 100644 > --- a/libavfilter/allfilters.c > +++ b/libavfilter/allfilters.c > @@ -330,6 +330,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_transpose_vaapi; > extern AVFilter ff_vf_showinfo; > extern AVFilter ff_vf_showpalette; > extern AVFilter ff_vf_shuffleframes; > diff --git a/libavfilter/vf_transpose_vaapi.c > b/libavfilter/vf_transpose_vaapi.c > new file mode 100644 > index 00..fcb99fc866 > --- /dev/null > +++ b/libavfilter/vf_transpose_vaapi.c > @@ -0,0 +1,337 @@ > +/* > + * 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
[FFmpeg-devel] [PATCH v2] libavfilter: add transpose_vaapi filter
It supports clockwise rotation by 0/90/180/270 degrees and mirroring by horizontal/vertical. video size is changed when rotation by 90/270. ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i input.264 -vf "transpose_vaapi=rotate=90:mirror=1" -c:v h264_vaapi output.h264 Signed-off-by: Zachary Zhou --- configure| 2 + libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_transpose_vaapi.c | 337 +++ 4 files changed, 341 insertions(+) create mode 100644 libavfilter/vf_transpose_vaapi.c diff --git a/configure b/configure index 85d5dd5962..f62d2a27ca 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" +transpose_vaapi_filter_deps="vaapi VAProcPipelineCaps_rotation_flags" showcqt_filter_deps="avcodec avformat swscale" showcqt_filter_suggest="libfontconfig libfreetype" showcqt_filter_select="fft" @@ -5961,6 +5962,7 @@ check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602 check_type "va/va.h va/va_dec_hevc.h" "VAPictureParameterBufferHEVC" check_struct "va/va.h" "VADecPictureParameterBufferVP9" bit_depth +check_struct "va/va.h" "VAProcPipelineCaps" rotation_flags check_type "va/va.h va/va_enc_hevc.h" "VAEncPictureParameterBufferHEVC" check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG" check_type "va/va.h va/va_enc_vp8.h" "VAEncPictureParameterBufferVP8" diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 62cc2f561f..813b174ddd 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -346,6 +346,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_TRANSPOSE_VAAPI_FILTER)+= vf_transpose_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 5e72803b13..e5b0571aa8 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -330,6 +330,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_transpose_vaapi; extern AVFilter ff_vf_showinfo; extern AVFilter ff_vf_showpalette; extern AVFilter ff_vf_shuffleframes; diff --git a/libavfilter/vf_transpose_vaapi.c b/libavfilter/vf_transpose_vaapi.c new file mode 100644 index 00..fcb99fc866 --- /dev/null +++ b/libavfilter/vf_transpose_vaapi.c @@ -0,0 +1,337 @@ +/* + * 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, +}; + +// Mirroring directions +enum MirroringDirections { +MIRROR_NONE = 0, +MIRROR_HORIZONTAL = 1, +MIRROR_VERTICAL = 2, + +MIRROR_MIN = MIRROR_NONE, +MIRROR_MAX = MIRROR_VERTICAL, +MIRROR_DEFAULT = MIRROR_NONE, +}; + +typedef struct TransposeVAAPIContext { +VAAPIVPPContext vpp_ctx; // must be the first field + +int rotate; +int mirror; + +int rotation_state; +int mirror_state; +} TransposeVAAPIContext; + +static int transpose_vaapi_build_filter_params(AVFilterContext *avctx) +{ +VAAPIVPPContext *vpp_ctx = avctx->priv; +TransposeVAAPIContext *ctx = avctx->priv; + +VAStatus vas; +int support_flag; + +VAProcPipelineCaps pipeline_caps; + +memset(_caps, 0,