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 enum AMF_MEMORY_TYPE mem_type = AMF_MEMORY_UNKNOWN;
98
99 int err;
100 AMF_RESULT res;
101 enum AVPixelFormat in_format;
102
103 err = amf_init_filter_config(outlink, &in_format);
104 if (err < 0)
105 return err;
106
107 device_ctx = amf_ctx->amf_device_ctx;
108
109 res = AMF_IFACE_CALL(device_ctx->factory, CreateComponent, device_ctx->context, AMFVQEnhancer, &amf_ctx->component);
110 AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR_FILTER_NOT_FOUND, "CreateComponent(%ls) failed with error %d\n", AMFVQEnhancer, res);
111
112 amf_filter = amf_ctx->component;
113
114 mem_type = av_amf_get_memory_type(device_ctx);
115 if (vqe_ctx->engine_type != -1) {
116 AMF_ASSIGN_PROPERTY_INT64(res, amf_filter, AMF_VIDEO_ENHANCER_ENGINE_TYPE, vqe_ctx->engine_type);
117 } else if (mem_type != AMF_MEMORY_UNKNOWN)
118 AMF_ASSIGN_PROPERTY_INT64(res, amf_filter, AMF_VIDEO_ENHANCER_ENGINE_TYPE, mem_type);
119
120 AMF_ASSIGN_PROPERTY_DOUBLE(res, amf_filter, AMF_VE_FCR_ATTENUATION, vqe_ctx->attenuation);
121 AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR_UNKNOWN, "Failed to set VQ enhancer attenuation: %d\n", res);
122
123 res = AMF_IFACE_CALL(amf_filter, Init, av_av_to_amf_format(in_format), inlink->w, inlink->h);
124 AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR_UNKNOWN, "AMFVQEnhancer-Init() failed with error %d\n", res);
125
126 return 0;
127}
128
129#define OFFSET(x) offsetof(AMFVQEFilterContext, x)
130#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
131static const AVOption vqe_amf_options[] = {
132 { "engine_type", "Engine type", OFFSET(engine_type), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, AMF_MEMORY_DX12, .flags = FLAGS, "engine_type" },
133 { "dx11", "DirectX 11", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_MEMORY_DX11 }, 0, 0, FLAGS, "engine_type" },
134 { "vulkan", "Vulkan", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_MEMORY_VULKAN }, 0, 0, FLAGS, "engine_type" },
135 { "dx12", "DirectX 12", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_MEMORY_DX12 }, 0, 0, FLAGS, "engine_type" },
136
137 { "attenuation", "Control VQEnhancer strength", OFFSET(attenuation), AV_OPT_TYPE_DOUBLE, { .dbl = 0.1 }, 0.02, 0.4, FLAGS, "attenuation" },
138
139 { NULL },
140};
141
143
145 {
146 .name = "default",
147 .type = AVMEDIA_TYPE_VIDEO,
148 .filter_frame = amf_filter_filter_frame,
149 }
150};
151
153 {
154 .name = "default",
155 .type = AVMEDIA_TYPE_VIDEO,
156 .config_props = amf_vqe_filter_config_output,
157 }
158};
159
161 .p.name = "vqe_amf",
162 .p.description = NULL_IF_CONFIG_SMALL("AMD AMF VQ Enhancer"),
163 .p.priv_class = &vqe_amf_class,
164 .p.flags = AVFILTER_FLAG_HWDEVICE,
165 .priv_size = sizeof(AMFVQEFilterContext),
171 .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
172};
const FFFilter ff_vf_vqe_amf
Definition vf_vqe_amf.c:160
#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_MEMORY_TYPE av_amf_get_memory_type(AVAMFDeviceContext *amf_ctx)
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:129
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:131
static int amf_vqe_init(AVFilterContext *avctx)
Definition vf_vqe_amf.c:53