FFmpeg
Loading...
Searching...
No Matches
vf_vqe_amf.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19/**
20 * @file
21 * Quality Enhancer video filter with AMF hardware acceleration
22 */
23
24#include "libavutil/opt.h"
25
26#include "libavutil/hwcontext.h"
29
30#include "AMF/components/VQEnhancer.h"
31#include "vf_amf_common.h"
32
33#include "avfilter.h"
34#include "avfilter_internal.h"
35#include "formats.h"
36#include "video.h"
37
38#if CONFIG_D3D11VA
39#include <d3d11.h>
40#endif
41
42#if CONFIG_D3D12VA
43#include <d3d12.h>
44#endif
45
52
53static int amf_vqe_init(AVFilterContext *avctx) {
55
56 ctx->common.format = AV_PIX_FMT_NONE;
57
58 return 0;
59}
60
62{
63 const enum AVPixelFormat *output_pix_fmts;
64 static const enum AVPixelFormat input_pix_fmts[] = {
73 };
74 static const enum AVPixelFormat output_pix_fmts_default[] = {
83 };
84 output_pix_fmts = output_pix_fmts_default;
85
86 return amf_setup_input_output_formats(avctx, input_pix_fmts, output_pix_fmts);
87}
88
90{
91 AVFilterContext *avctx = outlink->src;
92 AMFComponent *amf_filter = NULL;
93 AVFilterLink *inlink = avctx->inputs[0];
94 AMFVQEFilterContext *vqe_ctx = avctx->priv;
95 AMFFilterContext *amf_ctx = &vqe_ctx->common;
96 AVAMFDeviceContext *device_ctx = NULL;
97
98 int err;
99 AMF_RESULT res;
100 enum AVPixelFormat in_format;
101
102 err = amf_init_filter_config(outlink, &in_format);
103 if (err < 0)
104 return err;
105
106 device_ctx = amf_ctx->amf_device_ctx;
107
108 res = AMF_IFACE_CALL(device_ctx->factory, CreateComponent, device_ctx->context, AMFVQEnhancer, &amf_ctx->component);
109 AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR_FILTER_NOT_FOUND, "CreateComponent(%ls) failed with error %d\n", AMFVQEnhancer, res);
110
111 amf_filter = amf_ctx->component;
112
113 if (vqe_ctx->engine_type != -1)
114 AMF_ASSIGN_PROPERTY_INT64(res, amf_filter, AMF_VIDEO_ENHANCER_ENGINE_TYPE, vqe_ctx->engine_type);
115
116 AMF_ASSIGN_PROPERTY_DOUBLE(res, amf_filter, AMF_VE_FCR_ATTENUATION, vqe_ctx->attenuation);
117 AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR_UNKNOWN, "Failed to set VQ enhancer attenuation: %d\n", res);
118
119 res = AMF_IFACE_CALL(amf_filter, Init, av_av_to_amf_format(in_format), inlink->w, inlink->h);
120 AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR_UNKNOWN, "AMFVQEnhancer-Init() failed with error %d\n", res);
121
122 return 0;
123}
124
125#define OFFSET(x) offsetof(AMFVQEFilterContext, x)
126#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
127static const AVOption vqe_amf_options[] = {
128 { "engine_type", "Engine type", OFFSET(engine_type), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, AMF_MEMORY_DX12, .flags = FLAGS, "engine_type" },
129 { "dx11", "DirectX 11", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_MEMORY_DX11 }, 0, 0, FLAGS, "engine_type" },
130 { "vulkan", "Vulkan", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_MEMORY_VULKAN }, 0, 0, FLAGS, "engine_type" },
131 { "dx12", "DirectX 12", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_MEMORY_DX12 }, 0, 0, FLAGS, "engine_type" },
132
133 { "attenuation", "Control VQEnhancer strength", OFFSET(attenuation), AV_OPT_TYPE_DOUBLE, { .dbl = 0.1 }, 0.02, 0.4, FLAGS, "attenuation" },
134
135 { NULL },
136};
137
139
141 {
142 .name = "default",
143 .type = AVMEDIA_TYPE_VIDEO,
144 .filter_frame = amf_filter_filter_frame,
145 }
146};
147
149 {
150 .name = "default",
151 .type = AVMEDIA_TYPE_VIDEO,
152 .config_props = amf_vqe_filter_config_output,
153 }
154};
155
157 .p.name = "vqe_amf",
158 .p.description = NULL_IF_CONFIG_SMALL("AMD AMF VQ Enhancer"),
159 .p.priv_class = &vqe_amf_class,
160 .p.flags = AVFILTER_FLAG_HWDEVICE,
161 .priv_size = sizeof(AMFVQEFilterContext),
167 .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
168};
const FFFilter ff_vf_vqe_amf
Definition vf_vqe_amf.c:156
#define AMF_RETURN_IF_FALSE(avctx, exp, ret_value,...)
Error handling helper.
Definition amfenc.h:169
static AVFormatContext * ctx
Main libavfilter public API header.
#define FLAGS
Definition cmdutils.c:598
#define NULL
Definition coverity.c:32
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition opt.h:266
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
Definition avfilter.h:187
#define AVERROR_FILTER_NOT_FOUND
Filter not found.
Definition error.h:60
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition error.h:73
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
enum AMF_SURFACE_FORMAT av_av_to_amf_format(enum AVPixelFormat fmt)
#define AMF_IFACE_CALL(this, function,...)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition filters.h:208
#define FILTER_QUERY_FUNC(func)
Definition filters.h:238
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:478
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
AVOptions.
#define AV_PIX_FMT_RGBAF16
Definition pixfmt.h:630
#define AV_PIX_FMT_P010
Definition pixfmt.h:608
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition pixfmt.h:96
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition pixfmt.h:102
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
@ AV_PIX_FMT_AMF_SURFACE
HW acceleration through AMF.
Definition pixfmt.h:477
#define AV_PIX_FMT_X2BGR10
Definition pixfmt.h:620
static const float attenuation[10]
Definition speexdata.h:768
AVAMFDeviceContext * amf_device_ctx
AMFComponent * component
AMFFilterContext common
Definition vf_vqe_amf.c:47
This struct is allocated as AVHWDeviceContext.hwctx.
AMFContext * context
AMFFactory * factory
An instance of a filter.
Definition avfilter.h:273
AVFilterLink ** inputs
array of pointers to input links
Definition avfilter.h:281
void * priv
private data for use by the filter
Definition avfilter.h:288
A filter pad used for either input or output.
Definition filters.h:40
AVOption.
Definition opt.h:428
int amf_init_filter_config(AVFilterLink *outlink, enum AVPixelFormat *in_format)
int amf_filter_filter_frame(AVFilterLink *inlink, AVFrame *in)
int amf_setup_input_output_formats(AVFilterContext *avctx, const enum AVPixelFormat *input_pix_fmts, const enum AVPixelFormat *output_pix_fmts)
void amf_filter_uninit(AVFilterContext *avctx)
static const AVFilterPad amf_filter_inputs[]
Definition vf_frc_amf.c:264
static int amf_filter_query_formats(AVFilterContext *avctx)
Definition vf_frc_amf.c:68
static const AVFilterPad amf_filter_outputs[]
Definition vf_frc_amf.c:273
static int amf_vqe_filter_config_output(AVFilterLink *outlink)
Definition vf_vqe_amf.c:89
#define OFFSET(x)
Definition vf_vqe_amf.c:125
static int amf_filter_query_formats(AVFilterContext *avctx)
Definition vf_vqe_amf.c:61
static const AVOption vqe_amf_options[]
Definition vf_vqe_amf.c:127
static int amf_vqe_init(AVFilterContext *avctx)
Definition vf_vqe_amf.c:53