Re: [FFmpeg-devel] [PATCH v3 5/5] libavfilter: VAAPI surface converter
On Tue, 19 Jan 2016 14:10:59 + Mark Thompsonwrote: > ... > >> +static int vaapi_conv_config_input(AVFilterLink *inlink) > >> +{ > >> +AVFilterContext *avctx = inlink->dst; > >> +VAAPIConvContext *ctx = avctx->priv; > >> +AVVAAPISurfaceConfig *config = >input_config; > >> + > >> +if(inlink->format == AV_PIX_FMT_VAAPI) { > >> +av_log(ctx, AV_LOG_INFO, "Input is VAAPI (using incoming > >> surfaces).\n"); > >> +ctx->input_is_vaapi = 1; > >> +return 0; > >> +} > >> +ctx->input_is_vaapi = 0; > >> + > >> +config->rt_format = VA_RT_FORMAT_YUV420; > >> +config->av_format = AV_PIX_FMT_VAAPI; > >> + > >> +switch(inlink->format) { > >> +case AV_PIX_FMT_BGR0: > >> +case AV_PIX_FMT_BGRA: > >> +config->image_format.fourcc = VA_FOURCC_BGRX; > >> +config->image_format.byte_order = VA_LSB_FIRST; > >> +config->image_format.bits_per_pixel = 32; > >> +config->image_format.depth = 8; > >> +config->image_format.red_mask = 0x00ff; > >> +config->image_format.green_mask = 0xff00; > >> +config->image_format.blue_mask = 0x00ff; > >> +config->image_format.alpha_mask = 0x; > >> +break; > >> + > >> +case AV_PIX_FMT_RGB0: > >> +case AV_PIX_FMT_RGBA: > >> +config->image_format.fourcc = VA_FOURCC_RGBX; > >> +config->image_format.byte_order = VA_LSB_FIRST; > >> +config->image_format.bits_per_pixel = 32; > >> +config->image_format.depth = 8; > >> +config->image_format.red_mask = 0x00ff; > >> +config->image_format.green_mask = 0xff00; > >> +config->image_format.blue_mask = 0x00ff; > >> +config->image_format.alpha_mask = 0x; > >> +break; > >> + > >> +case AV_PIX_FMT_NV12: > >> +config->image_format.fourcc = VA_FOURCC_NV12; > >> +config->image_format.bits_per_pixel = 12; > >> +break; > >> +case AV_PIX_FMT_YUV420P: > >> +config->image_format.fourcc = VA_FOURCC_YV12; > >> +config->image_format.bits_per_pixel = 12; > >> +break; > > > > Doesn't this duplicate what vaQueryImageFormats() returns? > > > > Also I think your AV_PIX_FMT <-> VA_FOURCC mappings are duplicated > > somewhere else to a degree. > > Hmm, yes. I didn't put much thought into this part, because it was only a > token set of things to make my two initial use-cases work (RGB > colour-conversion, YV12/NV12 scale). > > I'll leave it for now and come back to it when looking at expanding the > inputs and outputs to be able to accept anything the hardware supports. > OK. Well, there is the impending HEVC 10 bit support, which will likely require adding 1 or 2 new formats all over the place. > ... > >> + > >> +#define OFFSET(member) offsetof(VAAPIConvContext, options.member) > >> +#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM) > >> +static const AVOption vaapi_conv_options[] = { > >> +{ "hardware_context", "VAAPI hardware context", > >> + OFFSET(hardware_context), AV_OPT_TYPE_INT64, > >> + { .i64 = 0 }, INT64_MIN, INT64_MAX, AV_OPT_FLAG_VIDEO_PARAM }, > > > > Setting it this way is not ideal, but I guess there's no proper way yet. > > Yeah. Maybe there should be an AV_OPT_TYPE_POINTER for the user to cleanly > do naughty things like this... Or it's made first class and somehow added to libavfilter directly. I don't know. Does anyone else have suggestions? ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH v3 5/5] libavfilter: VAAPI surface converter
On 19/01/16 12:27, wm4 wrote: > On Mon, 18 Jan 2016 22:53:33 + > Mark Thompsonwrote: > >> --- >> configure | 1 + >> libavfilter/Makefile| 1 + >> libavfilter/allfilters.c| 1 + >> libavfilter/vf_vaapi_conv.c | 480 >> >> 4 files changed, 483 insertions(+) >> create mode 100644 libavfilter/vf_vaapi_conv.c >> >> diff --git a/configure b/configure >> index 9da8e8b..71c0bc0 100755 >> --- a/configure >> +++ b/configure >> @@ -2913,6 +2913,7 @@ stereo3d_filter_deps="gpl" >> subtitles_filter_deps="avformat avcodec libass" >> super2xsai_filter_deps="gpl" >> tinterlace_filter_deps="gpl" >> +vaapi_conv_filter_deps="vaapi" >> vidstabdetect_filter_deps="libvidstab" >> vidstabtransform_filter_deps="libvidstab" >> pixfmts_super2xsai_test_deps="super2xsai_filter" >> diff --git a/libavfilter/Makefile b/libavfilter/Makefile >> index e3e3561..9a4ca12 100644 >> --- a/libavfilter/Makefile >> +++ b/libavfilter/Makefile >> @@ -246,6 +246,7 @@ OBJS-$(CONFIG_TRANSPOSE_FILTER) += >> vf_transpose.o >> OBJS-$(CONFIG_TRIM_FILTER) += trim.o >> OBJS-$(CONFIG_UNSHARP_FILTER)+= vf_unsharp.o >> OBJS-$(CONFIG_USPP_FILTER) += vf_uspp.o >> +OBJS-$(CONFIG_VAAPI) += vf_vaapi_conv.o >> OBJS-$(CONFIG_VECTORSCOPE_FILTER)+= vf_vectorscope.o >> OBJS-$(CONFIG_VFLIP_FILTER) += vf_vflip.o >> OBJS-$(CONFIG_VIDSTABDETECT_FILTER) += vidstabutils.o >> vf_vidstabdetect.o >> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c >> index 1faf393..cfbfdca 100644 >> --- a/libavfilter/allfilters.c >> +++ b/libavfilter/allfilters.c >> @@ -266,6 +266,7 @@ void avfilter_register_all(void) >> REGISTER_FILTER(TRIM, trim, vf); >> REGISTER_FILTER(UNSHARP,unsharp,vf); >> REGISTER_FILTER(USPP, uspp, vf); >> +REGISTER_FILTER(VAAPI_CONV, vaapi_conv, vf); >> REGISTER_FILTER(VECTORSCOPE,vectorscope,vf); >> REGISTER_FILTER(VFLIP, vflip, vf); >> REGISTER_FILTER(VIDSTABDETECT, vidstabdetect, vf); >> diff --git a/libavfilter/vf_vaapi_conv.c b/libavfilter/vf_vaapi_conv.c >> new file mode 100644 >> index 000..5180e7c >> --- /dev/null >> +++ b/libavfilter/vf_vaapi_conv.c >> @@ -0,0 +1,480 @@ >> +/* >> + * VAAPI converter (scaling and colour conversion). >> + * >> + * Copyright (C) 2016 Mark Thompson >> + * >> + * 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 "avfilter.h" >> +#include "formats.h" >> +#include "internal.h" >> + >> +#include "libavutil/avassert.h" >> +#include "libavutil/opt.h" >> +#include "libavutil/pixdesc.h" >> +#include "libavutil/vaapi.h" >> + >> +#include >> + >> +typedef struct VAAPIConvContext { >> +const AVClass *class; >> + >> +AVVAAPIHardwareContext *hardware_context; >> +AVVAAPIPipelineConfig va_config; >> +AVVAAPIPipelineContext va_context; >> +int pipeline_initialised; >> + >> +int input_is_vaapi; >> +AVVAAPISurfaceConfig input_config; >> +AVVAAPISurfaceConfig output_config; >> + >> +int output_width; >> +int output_height; >> + >> +struct { >> +int64_t hardware_context; >> +int output_size[2]; >> +} options; >> + >> +} VAAPIConvContext; >> + >> + >> +static int vaapi_conv_query_formats(AVFilterContext *avctx) >> +{ >> +VAAPIConvContext *ctx = avctx->priv; >> +VAStatus vas; >> +VAConfigAttrib rt_format = { >> +.type = VAConfigAttribRTFormat >> +}; >> +enum AVPixelFormat pix_fmt_list[16] = { >> +AV_PIX_FMT_VAAPI, >> +}; >> +int pix_fmt_count = 1, err; >> + >> +#if 0 >> +// The Intel driver doesn't return anything useful here - it only >> +// declares support for YUV 4:2:0 formats, despite working perfectly >> +// with 32-bit RGB ones. Given another usable platform, this will >> +// need to be updated. >> +vas = vaGetConfigAttributes(ctx->hardware_context->display, >> +VAProfileNone, VAEntrypointVideoProc, >> +
Re: [FFmpeg-devel] [PATCH v3 5/5] libavfilter: VAAPI surface converter
On Mon, 18 Jan 2016 22:53:33 + Mark Thompsonwrote: > --- > configure | 1 + > libavfilter/Makefile| 1 + > libavfilter/allfilters.c| 1 + > libavfilter/vf_vaapi_conv.c | 480 > > 4 files changed, 483 insertions(+) > create mode 100644 libavfilter/vf_vaapi_conv.c > > diff --git a/configure b/configure > index 9da8e8b..71c0bc0 100755 > --- a/configure > +++ b/configure > @@ -2913,6 +2913,7 @@ stereo3d_filter_deps="gpl" > subtitles_filter_deps="avformat avcodec libass" > super2xsai_filter_deps="gpl" > tinterlace_filter_deps="gpl" > +vaapi_conv_filter_deps="vaapi" > vidstabdetect_filter_deps="libvidstab" > vidstabtransform_filter_deps="libvidstab" > pixfmts_super2xsai_test_deps="super2xsai_filter" > diff --git a/libavfilter/Makefile b/libavfilter/Makefile > index e3e3561..9a4ca12 100644 > --- a/libavfilter/Makefile > +++ b/libavfilter/Makefile > @@ -246,6 +246,7 @@ OBJS-$(CONFIG_TRANSPOSE_FILTER) += > vf_transpose.o > OBJS-$(CONFIG_TRIM_FILTER) += trim.o > OBJS-$(CONFIG_UNSHARP_FILTER)+= vf_unsharp.o > OBJS-$(CONFIG_USPP_FILTER) += vf_uspp.o > +OBJS-$(CONFIG_VAAPI) += vf_vaapi_conv.o > OBJS-$(CONFIG_VECTORSCOPE_FILTER)+= vf_vectorscope.o > OBJS-$(CONFIG_VFLIP_FILTER) += vf_vflip.o > OBJS-$(CONFIG_VIDSTABDETECT_FILTER) += vidstabutils.o > vf_vidstabdetect.o > diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c > index 1faf393..cfbfdca 100644 > --- a/libavfilter/allfilters.c > +++ b/libavfilter/allfilters.c > @@ -266,6 +266,7 @@ void avfilter_register_all(void) > REGISTER_FILTER(TRIM, trim, vf); > REGISTER_FILTER(UNSHARP,unsharp,vf); > REGISTER_FILTER(USPP, uspp, vf); > +REGISTER_FILTER(VAAPI_CONV, vaapi_conv, vf); > REGISTER_FILTER(VECTORSCOPE,vectorscope,vf); > REGISTER_FILTER(VFLIP, vflip, vf); > REGISTER_FILTER(VIDSTABDETECT, vidstabdetect, vf); > diff --git a/libavfilter/vf_vaapi_conv.c b/libavfilter/vf_vaapi_conv.c > new file mode 100644 > index 000..5180e7c > --- /dev/null > +++ b/libavfilter/vf_vaapi_conv.c > @@ -0,0 +1,480 @@ > +/* > + * VAAPI converter (scaling and colour conversion). > + * > + * Copyright (C) 2016 Mark Thompson > + * > + * 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 "avfilter.h" > +#include "formats.h" > +#include "internal.h" > + > +#include "libavutil/avassert.h" > +#include "libavutil/opt.h" > +#include "libavutil/pixdesc.h" > +#include "libavutil/vaapi.h" > + > +#include > + > +typedef struct VAAPIConvContext { > +const AVClass *class; > + > +AVVAAPIHardwareContext *hardware_context; > +AVVAAPIPipelineConfig va_config; > +AVVAAPIPipelineContext va_context; > +int pipeline_initialised; > + > +int input_is_vaapi; > +AVVAAPISurfaceConfig input_config; > +AVVAAPISurfaceConfig output_config; > + > +int output_width; > +int output_height; > + > +struct { > +int64_t hardware_context; > +int output_size[2]; > +} options; > + > +} VAAPIConvContext; > + > + > +static int vaapi_conv_query_formats(AVFilterContext *avctx) > +{ > +VAAPIConvContext *ctx = avctx->priv; > +VAStatus vas; > +VAConfigAttrib rt_format = { > +.type = VAConfigAttribRTFormat > +}; > +enum AVPixelFormat pix_fmt_list[16] = { > +AV_PIX_FMT_VAAPI, > +}; > +int pix_fmt_count = 1, err; > + > +#if 0 > +// The Intel driver doesn't return anything useful here - it only > +// declares support for YUV 4:2:0 formats, despite working perfectly > +// with 32-bit RGB ones. Given another usable platform, this will > +// need to be updated. > +vas = vaGetConfigAttributes(ctx->hardware_context->display, > +VAProfileNone, VAEntrypointVideoProc, > +_format, 1); > +#else > +vas = VA_STATUS_SUCCESS; > +rt_format.value = VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_RGB32; > +#endif > +
[FFmpeg-devel] [PATCH v3 5/5] libavfilter: VAAPI surface converter
--- configure | 1 + libavfilter/Makefile| 1 + libavfilter/allfilters.c| 1 + libavfilter/vf_vaapi_conv.c | 480 4 files changed, 483 insertions(+) create mode 100644 libavfilter/vf_vaapi_conv.c diff --git a/configure b/configure index 9da8e8b..71c0bc0 100755 --- a/configure +++ b/configure @@ -2913,6 +2913,7 @@ stereo3d_filter_deps="gpl" subtitles_filter_deps="avformat avcodec libass" super2xsai_filter_deps="gpl" tinterlace_filter_deps="gpl" +vaapi_conv_filter_deps="vaapi" vidstabdetect_filter_deps="libvidstab" vidstabtransform_filter_deps="libvidstab" pixfmts_super2xsai_test_deps="super2xsai_filter" diff --git a/libavfilter/Makefile b/libavfilter/Makefile index e3e3561..9a4ca12 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -246,6 +246,7 @@ OBJS-$(CONFIG_TRANSPOSE_FILTER) += vf_transpose.o OBJS-$(CONFIG_TRIM_FILTER) += trim.o OBJS-$(CONFIG_UNSHARP_FILTER)+= vf_unsharp.o OBJS-$(CONFIG_USPP_FILTER) += vf_uspp.o +OBJS-$(CONFIG_VAAPI) += vf_vaapi_conv.o OBJS-$(CONFIG_VECTORSCOPE_FILTER)+= vf_vectorscope.o OBJS-$(CONFIG_VFLIP_FILTER) += vf_vflip.o OBJS-$(CONFIG_VIDSTABDETECT_FILTER) += vidstabutils.o vf_vidstabdetect.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 1faf393..cfbfdca 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -266,6 +266,7 @@ void avfilter_register_all(void) REGISTER_FILTER(TRIM, trim, vf); REGISTER_FILTER(UNSHARP,unsharp,vf); REGISTER_FILTER(USPP, uspp, vf); +REGISTER_FILTER(VAAPI_CONV, vaapi_conv, vf); REGISTER_FILTER(VECTORSCOPE,vectorscope,vf); REGISTER_FILTER(VFLIP, vflip, vf); REGISTER_FILTER(VIDSTABDETECT, vidstabdetect, vf); diff --git a/libavfilter/vf_vaapi_conv.c b/libavfilter/vf_vaapi_conv.c new file mode 100644 index 000..5180e7c --- /dev/null +++ b/libavfilter/vf_vaapi_conv.c @@ -0,0 +1,480 @@ +/* + * VAAPI converter (scaling and colour conversion). + * + * Copyright (C) 2016 Mark Thompson+ * + * 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 "avfilter.h" +#include "formats.h" +#include "internal.h" + +#include "libavutil/avassert.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" +#include "libavutil/vaapi.h" + +#include + +typedef struct VAAPIConvContext { +const AVClass *class; + +AVVAAPIHardwareContext *hardware_context; +AVVAAPIPipelineConfig va_config; +AVVAAPIPipelineContext va_context; +int pipeline_initialised; + +int input_is_vaapi; +AVVAAPISurfaceConfig input_config; +AVVAAPISurfaceConfig output_config; + +int output_width; +int output_height; + +struct { +int64_t hardware_context; +int output_size[2]; +} options; + +} VAAPIConvContext; + + +static int vaapi_conv_query_formats(AVFilterContext *avctx) +{ +VAAPIConvContext *ctx = avctx->priv; +VAStatus vas; +VAConfigAttrib rt_format = { +.type = VAConfigAttribRTFormat +}; +enum AVPixelFormat pix_fmt_list[16] = { +AV_PIX_FMT_VAAPI, +}; +int pix_fmt_count = 1, err; + +#if 0 +// The Intel driver doesn't return anything useful here - it only +// declares support for YUV 4:2:0 formats, despite working perfectly +// with 32-bit RGB ones. Given another usable platform, this will +// need to be updated. +vas = vaGetConfigAttributes(ctx->hardware_context->display, +VAProfileNone, VAEntrypointVideoProc, +_format, 1); +#else +vas = VA_STATUS_SUCCESS; +rt_format.value = VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_RGB32; +#endif +if(vas != VA_STATUS_SUCCESS) { +av_log(ctx, AV_LOG_ERROR, "Failed to get config attributes: " + "%d (%s).\n", vas, vaErrorStr(vas)); +} else { +if(rt_format.value & VA_RT_FORMAT_YUV420) { +av_log(ctx, AV_LOG_DEBUG, "YUV420 formats supported.\n"); +pix_fmt_list[pix_fmt_count++] =