Hi, > -----Original Message----- > From: ffmpeg-devel <ffmpeg-devel-boun...@ffmpeg.org> On Behalf Of > Xinpeng Sun > Sent: Tuesday, November 12, 2019 17:00 > To: ffmpeg-devel@ffmpeg.org > Cc: Sun, Xinpeng <xinpeng....@intel.com>; Zhou, Zachary > <zachary.z...@intel.com> > Subject: [FFmpeg-devel] [PATCH v1] avfilter: Add tonemap vaapi filter for > H2S > > It performs HDR(High Dynamic Range) to SDR(Standard Dynamic Range) > conversion > with tone-mapping. It supports HDR10 only as input temporarily. > > H2S: P010 -> NV12 > > An example command to use this filter with vaapi codecs: > FFMPEG -hwaccel vaapi -vaapi_device /dev/dri/renderD128 - > hwaccel_output_format vaapi \ > -i INPUT -vf 'tonemap_vaapi=h2s,hwdownload,format=nv12' -pix_fmt nv12 \ > -f rawvideo -y OUTPUT > > Signed-off-by: Xinpeng Sun <xinpeng....@intel.com> > Signed-off-by: Zachary Zhou <zachary.z...@intel.com> > --- > doc/filters.texi | 30 ++++ > libavfilter/Makefile | 1 + > libavfilter/allfilters.c | 1 + > libavfilter/vaapi_vpp.c | 5 + > libavfilter/vf_tonemap_vaapi.c | 272 > +++++++++++++++++++++++++++++++++ > 5 files changed, 309 insertions(+) > create mode 100644 libavfilter/vf_tonemap_vaapi.c > > diff --git a/doc/filters.texi b/doc/filters.texi > index 6800124574..b1c466ba24 100644 > --- a/doc/filters.texi > +++ b/doc/filters.texi > @@ -20754,6 +20754,36 @@ Convert HDR(PQ/HLG) video to bt2020-transfer- > characteristic p010 format using li > @end example > @end itemize > > +@section tonemap_vappi > + > +Perform HDR(High Dynamic Range) to SDR(Standard Dynamic Range) > conversion with tone-mapping. > +It maps the dynamic range of HDR10 content to the SDR content. > +It only accepts HDR10 as input temporarilly.
Typo: temporarilly -> temporarily > + > +It accepts the following parameters: > + > +@table @option > +@item type > +Specify the tone-mapping operator to be used. > + > +Possible values are: > +@table @var > +@item h2s > +Perform H2S(HDR to SDR), convert from p010 to nv12 > +@end table > + > +@end table > + > +@subsection Example > + > +@itemize > +@item > +Convert HDR video to SDR video from p010 format to nv12 format. > +@example > +-i INPUT -vf "tonemap_vaapi=h2s" OUTPUT > +@end example > +@end itemize > + > @section unsharp_opencl > > Sharpen or blur the input video. > diff --git a/libavfilter/Makefile b/libavfilter/Makefile > index fce930360d..90a0e9945e 100644 > --- a/libavfilter/Makefile > +++ b/libavfilter/Makefile > @@ -410,6 +410,7 @@ OBJS-$(CONFIG_TMIX_FILTER) += vf_mix.o > framesync.o > OBJS-$(CONFIG_TONEMAP_FILTER) += vf_tonemap.o colorspace.o > OBJS-$(CONFIG_TONEMAP_OPENCL_FILTER) += vf_tonemap_opencl.o > colorspace.o opencl.o \ > opencl/tonemap.o > opencl/colorspace_common.o > +OBJS-$(CONFIG_TONEMAP_VAAPI_FILTER) += vf_tonemap_vaapi.o > vaapi_vpp.o > OBJS-$(CONFIG_TPAD_FILTER) += vf_tpad.o > OBJS-$(CONFIG_TRANSPOSE_FILTER) += vf_transpose.o > OBJS-$(CONFIG_TRANSPOSE_NPP_FILTER) += vf_transpose_npp.o > diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c > index 7c1e19e1da..b2fb1f8a98 100644 > --- a/libavfilter/allfilters.c > +++ b/libavfilter/allfilters.c > @@ -390,6 +390,7 @@ extern AVFilter ff_vf_tlut2; > extern AVFilter ff_vf_tmix; > extern AVFilter ff_vf_tonemap; > extern AVFilter ff_vf_tonemap_opencl; > +extern AVFilter ff_vf_tonemap_vaapi; > extern AVFilter ff_vf_tpad; > extern AVFilter ff_vf_transpose; > extern AVFilter ff_vf_transpose_npp; > diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c > index b5b245c8af..5776243fa0 100644 > --- a/libavfilter/vaapi_vpp.c > +++ b/libavfilter/vaapi_vpp.c > @@ -257,6 +257,11 @@ static const VAAPIColourProperties > vaapi_colour_standard_map[] = { > { VAProcColorStandardSMPTE170M, 6, 6, 6 }, > { VAProcColorStandardSMPTE240M, 7, 7, 7 }, > { VAProcColorStandardGenericFilm, 8, 1, 1 }, > + > +#if VA_CHECK_VERSION(2, 3, 0) VA-API version should be checked instead of LIBVA version, and I believe what you mean is (1,3,0) since the latest libva version is (1, 6, 0). > + { VAProcColorStandardExplicit, 9, 16, AVCOL_SPC_BT2020_NCL}, > +#endif > + > #if VA_CHECK_VERSION(1, 1, 0) > { VAProcColorStandardSRGB, 1, 13, 0 }, > { VAProcColorStandardXVYCC601, 1, 11, 5 }, > diff --git a/libavfilter/vf_tonemap_vaapi.c b/libavfilter/vf_tonemap_vaapi.c > new file mode 100644 > index 0000000000..27ee17bf00 > --- /dev/null > +++ b/libavfilter/vf_tonemap_vaapi.c > @@ -0,0 +1,272 @@ > +/* > + * 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 <string.h> > + > +#include "libavutil/avassert.h" > +#include "libavutil/mem.h" > +#include "libavutil/opt.h" > +#include "libavutil/pixdesc.h" > +#include "libavutil/mastering_display_metadata.h" > + > +#include "avfilter.h" > +#include "formats.h" > +#include "internal.h" > +#include "vaapi_vpp.h" > + > +typedef enum { > + HDR_VAAPI_H2S, > +} HDRType; > + > +typedef struct HDRVAAPIContext { > + VAAPIVPPContext vpp_ctx; // must be the first field > + > + int hdr_type; > + > + char *master_display; > + char *content_light; > + > + VAHdrMetaDataHDR10 in_metadata; > + > + AVFrameSideData *src_display; > + AVFrameSideData *src_light; > +} HDRVAAPIContext; > + > +static int tonemap_vaapi_set_filter_params(AVFilterContext *avctx, > AVFrame *input_frame) > +{ > + VAAPIVPPContext *vpp_ctx = avctx->priv; > + HDRVAAPIContext *ctx = avctx->priv; > + VAStatus vas; > + VAProcFilterParameterBufferHDRToneMapping *hdrtm_param; IMHO, LIBVA version check is needed for structures like VAProcFilterParameterBufferHDRToneMapping since it's added in commit cf11abe5e1 in VA-API 1.4.0(the exact version could be double checked), otherwise it'll encounter compatible problem and break build with early libva version. > + vas = vaMapBuffer(vpp_ctx->hwctx->display, vpp_ctx->filter_buffers[0], > + (void**)&hdrtm_param); > + if (vas != VA_STATUS_SUCCESS) { > + av_log(avctx, AV_LOG_ERROR, "Failed to map " > + "buffer (%d): %d (%s).\n", > + vpp_ctx->filter_buffers[0], vas, vaErrorStr(vas)); > + return AVERROR(EIO); > + } > + > + memcpy(hdrtm_param->data.metadata, &ctx->in_metadata, > sizeof(VAHdrMetaDataHDR10)); > + > + vas = vaUnmapBuffer(vpp_ctx->hwctx->display, vpp_ctx- > >filter_buffers[0]); > + if (vas != VA_STATUS_SUCCESS) { > + av_log(avctx, AV_LOG_ERROR, "Failed to unmap output buffers: " > + "%d (%s).\n", vas, vaErrorStr(vas)); > + return AVERROR(EIO); > + } > + > + return 0; > +} > + > +static int tonemap_vaapi_build_filter_params(AVFilterContext *avctx) > +{ > + VAAPIVPPContext *vpp_ctx = avctx->priv; > + HDRVAAPIContext *ctx = avctx->priv; > + VAStatus vas; > + VAProcFilterCapHighDynamicRange hdr_cap; > + int num_query_caps; > + VAProcFilterParameterBufferHDRToneMapping hdrtm_param; > + vas = vaQueryVideoProcFilterCaps(vpp_ctx->hwctx->display, > + vpp_ctx->va_context, > + VAProcFilterHighDynamicRangeToneMapping, > + &hdr_cap, &num_query_caps); > + if (vas != VA_STATUS_SUCCESS) { > + av_log(avctx, AV_LOG_ERROR, "Failed to query HDR caps " > + "context: %d (%s).\n", vas, vaErrorStr(vas)); > + return AVERROR(EIO); > + } > + > + if (hdr_cap.metadata_type == VAProcHighDynamicRangeMetadataNone) > { > + av_log(avctx, AV_LOG_ERROR, "VAAPI driver doesn't support HDR\n"); > + return AVERROR(EINVAL); > + } > + > + switch (ctx->hdr_type) { > + case HDR_VAAPI_H2S: > + if (!(VA_TONE_MAPPING_HDR_TO_SDR & hdr_cap.caps_flag)) { > + av_log(avctx, AV_LOG_ERROR, > + "VAAPI driver doesn't support H2S\n"); > + return AVERROR(EINVAL); > + } > + break; > + default: > + av_assert0(0); How about assert with some error message to give more information? > + } - linjie _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".