FFmpeg
Loading...
Searching...
No Matches
vf_vpp_qsv.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 ** Hardware accelerated common filters based on Intel Quick Sync Video VPP
22 **/
23
24#include <float.h>
25
26#include "config_components.h"
27
28#include "libavutil/opt.h"
29#include "libavutil/eval.h"
30#include "libavutil/hwcontext.h"
32#include "libavutil/pixdesc.h"
35
36#include "formats.h"
37#include "avfilter.h"
38#include "filters.h"
39
40#include "qsvvpp.h"
41#include "transpose.h"
42
43#define OFFSET(x) offsetof(VPPContext, x)
44#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM)
45
46/* number of video enhancement filters */
47#define ENH_FILTERS_COUNT (8)
48
49typedef struct VPPContext{
51
52 /* Video Enhancement Algorithms */
53 mfxExtVPPDeinterlacing deinterlace_conf;
54 mfxExtVPPFrameRateConversion frc_conf;
55 mfxExtVPPDenoise denoise_conf;
56 mfxExtVPPDetail detail_conf;
57 mfxExtVPPProcAmp procamp_conf;
58 mfxExtVPPRotation rotation_conf;
59 mfxExtVPPMirroring mirroring_conf;
60 mfxExtVPPScaling scale_conf;
61#if QSV_ONEVPL
62 /** Video signal info attached on the input frame */
63 mfxExtVideoSignalInfo invsi_conf;
64 /** Video signal info attached on the output frame */
65 mfxExtVideoSignalInfo outvsi_conf;
66 /** HDR parameters attached on the input frame */
67 mfxExtMasteringDisplayColourVolume mdcv_conf;
68 mfxExtContentLightLevelInfo clli_conf;
69#endif
70
71 /**
72 * New dimensions. Special values are:
73 * 0 = original width/height
74 * -1 = keep original aspect
75 */
78 /**
79 * Output sw format. AV_PIX_FMT_NONE for no conversion.
80 */
82
83 AVRational framerate; /* target framerate */
84 int use_frc; /* use framerate conversion */
85 int deinterlace; /* deinterlace mode : 0=off, 1=bob, 2=advanced */
86 int denoise; /* Enable Denoise algorithm. Value [0, 100] */
87 int detail; /* Enable Detail Enhancement algorithm. */
88 /* Level is the optional, value [0, 100] */
89 int use_crop; /* 1 = use crop; 0=none */
90 int crop_w;
91 int crop_h;
92 int crop_x;
93 int crop_y;
94
96 int rotate; /* rotate angle : [0, 90, 180, 270] */
97 int hflip; /* flip mode : 0 = off, 1 = HORIZONTAL flip */
98
99 int scale_mode; /* scale mode : 0 = auto, 1 = low power, 2 = high quality */
100
101 /* param for the procamp */
102 int procamp; /* enable procamp */
103 float hue;
105 float contrast;
107
108 char *cx, *cy, *cw, *ch;
109 char *ow, *oh;
111
112 /** The color properties for output */
116
121
122 int has_passthrough; /* apply pass through mode if possible */
123 int field_rate; /* Generate output at frame rate or field rate for deinterlace mode, 0: frame, 1: field */
124 int tonemap; /* 1: perform tonemapping if the input has HDR metadata, 0: always disable tonemapping */
125} VPPContext;
126
127static const char *const var_names[] = {
128 "iw", "in_w",
129 "ih", "in_h",
130 "ow", "out_w", "w",
131 "oh", "out_h", "h",
132 "cw",
133 "ch",
134 "cx",
135 "cy",
136 "a", "dar",
137 "sar",
138 NULL
139};
140
154
156{
157#define PASS_EXPR(e, s) {\
158 if (s) {\
159 ret = av_expr_parse(&e, s, var_names, NULL, NULL, NULL, NULL, 0, ctx); \
160 if (ret < 0) { \
161 av_log(ctx, AV_LOG_ERROR, "Error when passing '%s'.\n", s); \
162 goto release; \
163 } \
164 }\
165}
166#define CALC_EXPR(e, v, i, d) {\
167 if (e)\
168 i = v = av_expr_eval(e, var_values, NULL); \
169 else\
170 i = v = d;\
171}
172 VPPContext *vpp = ctx->priv;
173 double var_values[VAR_VARS_NB] = { NAN };
174 AVExpr *w_expr = NULL, *h_expr = NULL;
175 AVExpr *cw_expr = NULL, *ch_expr = NULL;
176 AVExpr *cx_expr = NULL, *cy_expr = NULL;
177 int ret = 0;
178
179 PASS_EXPR(cw_expr, vpp->cw);
180 PASS_EXPR(ch_expr, vpp->ch);
181
182 PASS_EXPR(w_expr, vpp->ow);
183 PASS_EXPR(h_expr, vpp->oh);
184
185 PASS_EXPR(cx_expr, vpp->cx);
186 PASS_EXPR(cy_expr, vpp->cy);
187
188 var_values[VAR_IW] =
189 var_values[VAR_IN_W] = ctx->inputs[0]->w;
190
191 var_values[VAR_IH] =
192 var_values[VAR_IN_H] = ctx->inputs[0]->h;
193
194 var_values[VAR_A] = (double)var_values[VAR_IN_W] / var_values[VAR_IN_H];
195 var_values[VAR_SAR] = ctx->inputs[0]->sample_aspect_ratio.num ?
196 (double)ctx->inputs[0]->sample_aspect_ratio.num / ctx->inputs[0]->sample_aspect_ratio.den : 1;
197 var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
198
199 /* crop params */
200 CALC_EXPR(cw_expr, var_values[VAR_CW], vpp->crop_w, var_values[VAR_IW]);
201 CALC_EXPR(ch_expr, var_values[VAR_CH], vpp->crop_h, var_values[VAR_IH]);
202
203 /* calc again in case cw is relative to ch */
204 CALC_EXPR(cw_expr, var_values[VAR_CW], vpp->crop_w, var_values[VAR_IW]);
205
206 CALC_EXPR(w_expr,
207 var_values[VAR_OUT_W] = var_values[VAR_OW] = var_values[VAR_W],
208 vpp->out_width, var_values[VAR_CW]);
209 CALC_EXPR(h_expr,
210 var_values[VAR_OUT_H] = var_values[VAR_OH] = var_values[VAR_H],
211 vpp->out_height, var_values[VAR_CH]);
212
213 /* calc again in case ow is relative to oh */
214 CALC_EXPR(w_expr,
215 var_values[VAR_OUT_W] = var_values[VAR_OW] = var_values[VAR_W],
216 vpp->out_width, var_values[VAR_CW]);
217
218 CALC_EXPR(cx_expr, var_values[VAR_CX], vpp->crop_x, (var_values[VAR_IW] - var_values[VAR_OW]) / 2);
219 CALC_EXPR(cy_expr, var_values[VAR_CY], vpp->crop_y, (var_values[VAR_IH] - var_values[VAR_OH]) / 2);
220
221 /* calc again in case cx is relative to cy */
222 CALC_EXPR(cx_expr, var_values[VAR_CX], vpp->crop_x, (var_values[VAR_IW] - var_values[VAR_OW]) / 2);
223
224 if ((vpp->crop_w != var_values[VAR_IW]) || (vpp->crop_h != var_values[VAR_IH]))
225 vpp->use_crop = 1;
226
227release:
228 av_expr_free(w_expr);
229 av_expr_free(h_expr);
230 av_expr_free(cw_expr);
231 av_expr_free(ch_expr);
232 av_expr_free(cx_expr);
233 av_expr_free(cy_expr);
234#undef PASS_EXPR
235#undef CALC_EXPR
236
237 return ret;
238}
239
241{
242 VPPContext *vpp = ctx->priv;
243 /* For AV_OPT_TYPE_STRING options, NULL is handled in other way so
244 * we needn't set default value here
245 */
246 vpp->saturation = 1.0;
247 vpp->contrast = 1.0;
248 vpp->transpose = -1;
249
254
255 vpp->has_passthrough = 1;
256
257 return 0;
258}
259
261{
262 VPPContext *vpp = ctx->priv;
263
264 if (!vpp->output_format_str || !strcmp(vpp->output_format_str, "same")) {
266 } else {
268 if (vpp->out_format == AV_PIX_FMT_NONE) {
269 av_log(ctx, AV_LOG_ERROR, "Unrecognized output pixel format: %s\n", vpp->output_format_str);
270 return AVERROR(EINVAL);
271 }
272 }
273
274#define STRING_OPTION(var_name, func_name, default_value) do { \
275 if (vpp->var_name ## _str) { \
276 int var = av_ ## func_name ## _from_name(vpp->var_name ## _str); \
277 if (var < 0) { \
278 av_log(ctx, AV_LOG_ERROR, "Invalid %s.\n", #var_name); \
279 return AVERROR(EINVAL); \
280 } \
281 vpp->var_name = var; \
282 } else { \
283 vpp->var_name = default_value; \
284 } \
285 } while (0)
286
288 STRING_OPTION(color_transfer, color_transfer, AVCOL_TRC_UNSPECIFIED);
289 STRING_OPTION(color_matrix, color_space, AVCOL_SPC_UNSPECIFIED);
290
291#undef STRING_OPTION
292 return 0;
293}
294
295static int config_input(AVFilterLink *inlink)
296{
297 AVFilterContext *ctx = inlink->dst;
298 VPPContext *vpp = ctx->priv;
299 FilterLink *inl = ff_filter_link(inlink);
300 int ret;
301 int64_t ow, oh;
302
303 if (vpp->framerate.den == 0 || vpp->framerate.num == 0) {
304 vpp->framerate = inl->frame_rate;
305
306 if (vpp->deinterlace && vpp->field_rate)
307 vpp->framerate = av_mul_q(inl->frame_rate,
308 (AVRational){ 2, 1 });
309 }
310
311 if (av_cmp_q(vpp->framerate, inl->frame_rate))
312 vpp->use_frc = 1;
313
314 ret = eval_expr(ctx);
315 if (ret != 0) {
316 av_log(ctx, AV_LOG_ERROR, "Fail to eval expr.\n");
317 return ret;
318 }
319
320 ow = vpp->out_width;
321 oh = vpp->out_height;
322
323 /* sanity check params */
324 if (ow < -1 || oh < -1) {
325 av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n");
326 return AVERROR(EINVAL);
327 }
328
329 if (ow == -1 && oh == -1)
330 vpp->out_width = vpp->out_height = 0;
331
332 if (!(ow = vpp->out_width))
333 ow = inlink->w;
334
335 if (!(oh = vpp->out_height))
336 oh = inlink->h;
337
338 if (ow == -1)
339 ow = av_rescale(oh, inlink->w, inlink->h);
340
341 if (oh == -1)
342 oh = av_rescale(ow, inlink->h, inlink->w);
343
344 if (ow > INT_MAX || oh > INT_MAX ||
345 (oh * inlink->w) > INT_MAX ||
346 (ow * inlink->h) > INT_MAX)
347 av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
348
349 vpp->out_width = ow;
350 vpp->out_height = oh;
351
352 if (vpp->use_crop) {
353 vpp->crop_x = FFMAX(vpp->crop_x, 0);
354 vpp->crop_y = FFMAX(vpp->crop_y, 0);
355
356 if(vpp->crop_w + vpp->crop_x > inlink->w)
357 vpp->crop_x = inlink->w - vpp->crop_w;
358 if(vpp->crop_h + vpp->crop_y > inlink->h)
359 vpp->crop_y = inlink->h - vpp->crop_h;
360 }
361
362 return 0;
363}
364
365static mfxStatus get_mfx_version(const AVFilterContext *ctx, mfxVersion *mfx_version)
366{
367 const FilterLink *l = ff_filter_link(ctx->inputs[0]);
368 AVBufferRef *device_ref;
369 AVHWDeviceContext *device_ctx;
370 AVQSVDeviceContext *device_hwctx;
371
372 if (l->hw_frames_ctx) {
374 device_ref = frames_ctx->device_ref;
375 } else if (ctx->hw_device_ctx) {
376 device_ref = ctx->hw_device_ctx;
377 } else {
378 // Unavailable hw context doesn't matter in pass-through mode,
379 // so don't error here but let runtime version checks fail by setting to 0.0
380 mfx_version->Major = 0;
381 mfx_version->Minor = 0;
382 return MFX_ERR_NONE;
383 }
384
385 device_ctx = (AVHWDeviceContext *)device_ref->data;
386 device_hwctx = device_ctx->hwctx;
387
388 return MFXQueryVersion(device_hwctx->session, mfx_version);
389}
390
392{
393#if QSV_ONEVPL
394 VPPContext *vpp = ctx->priv;
395 QSVVPPContext *qsvvpp = &vpp->qsv;
396 mfxExtVideoSignalInfo invsi_conf, outvsi_conf;
397 mfxExtMasteringDisplayColourVolume mdcv_conf;
398 mfxExtContentLightLevelInfo clli_conf;
399 AVFrameSideData *sd;
400 int tm = 0;
401
402 fp->num_ext_buf = 0;
403
404 if (!in || !out ||
405 !QSV_RUNTIME_VERSION_ATLEAST(qsvvpp->ver, 2, 0))
406 return 0;
407
408 memset(&invsi_conf, 0, sizeof(mfxExtVideoSignalInfo));
409 invsi_conf.Header.BufferId = MFX_EXTBUFF_VIDEO_SIGNAL_INFO_IN;
410 invsi_conf.Header.BufferSz = sizeof(mfxExtVideoSignalInfo);
411 invsi_conf.VideoFullRange = (in->color_range == AVCOL_RANGE_JPEG);
412 invsi_conf.ColourPrimaries = (in->color_primaries == AVCOL_PRI_UNSPECIFIED) ? AVCOL_PRI_BT709 : in->color_primaries;
413 invsi_conf.TransferCharacteristics = (in->color_trc == AVCOL_TRC_UNSPECIFIED) ? AVCOL_TRC_BT709 : in->color_trc;
414 invsi_conf.MatrixCoefficients = (in->colorspace == AVCOL_SPC_UNSPECIFIED) ? AVCOL_SPC_BT709 : in->colorspace;
415 invsi_conf.ColourDescriptionPresent = 1;
416
417 memset(&mdcv_conf, 0, sizeof(mfxExtMasteringDisplayColourVolume));
419 if (vpp->tonemap && sd) {
421
422 if (mdm->has_primaries && mdm->has_luminance) {
423 const int mapping[3] = {1, 2, 0};
424 const int chroma_den = 50000;
425 const int luma_den = 10000;
426 int i;
427
428 mdcv_conf.Header.BufferId = MFX_EXTBUFF_MASTERING_DISPLAY_COLOUR_VOLUME_IN;
429 mdcv_conf.Header.BufferSz = sizeof(mfxExtMasteringDisplayColourVolume);
430
431 for (i = 0; i < 3; i++) {
432 const int j = mapping[i];
433
434 mdcv_conf.DisplayPrimariesX[i] =
435 FFMIN(lrint(chroma_den *
436 av_q2d(mdm->display_primaries[j][0])),
437 chroma_den);
438 mdcv_conf.DisplayPrimariesY[i] =
439 FFMIN(lrint(chroma_den *
440 av_q2d(mdm->display_primaries[j][1])),
441 chroma_den);
442 }
443
444 mdcv_conf.WhitePointX =
445 FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[0])),
446 chroma_den);
447 mdcv_conf.WhitePointY =
448 FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[1])),
449 chroma_den);
450
451 /* MaxDisplayMasteringLuminance is in the unit of 1 nits however
452 * MinDisplayMasteringLuminance is in the unit of 0.0001 nits
453 */
454 mdcv_conf.MaxDisplayMasteringLuminance =
456 mdcv_conf.MinDisplayMasteringLuminance =
457 lrint(luma_den * av_q2d(mdm->min_luminance));
458 tm = 1;
459 }
460 }
461
462 memset(&clli_conf, 0, sizeof(mfxExtContentLightLevelInfo));
464 if (vpp->tonemap && sd) {
466
467 clli_conf.Header.BufferId = MFX_EXTBUFF_CONTENT_LIGHT_LEVEL_INFO;
468 clli_conf.Header.BufferSz = sizeof(mfxExtContentLightLevelInfo);
469 clli_conf.MaxContentLightLevel = FFMIN(clm->MaxCLL, 65535);
470 clli_conf.MaxPicAverageLightLevel = FFMIN(clm->MaxFALL, 65535);
471 tm = 1;
472 }
473
474 if (tm) {
477
478 out->color_primaries = AVCOL_PRI_BT709;
479 out->color_trc = AVCOL_TRC_BT709;
480 out->colorspace = AVCOL_SPC_BT709;
481 out->color_range = AVCOL_RANGE_MPEG;
482 }
483
485 out->color_range = vpp->color_range;
487 out->color_primaries = vpp->color_primaries;
489 out->color_trc = vpp->color_transfer;
491 out->colorspace = vpp->color_matrix;
492
493 memset(&outvsi_conf, 0, sizeof(mfxExtVideoSignalInfo));
494 outvsi_conf.Header.BufferId = MFX_EXTBUFF_VIDEO_SIGNAL_INFO_OUT;
495 outvsi_conf.Header.BufferSz = sizeof(mfxExtVideoSignalInfo);
496 outvsi_conf.VideoFullRange = (out->color_range == AVCOL_RANGE_JPEG);
497 outvsi_conf.ColourPrimaries = (out->color_primaries == AVCOL_PRI_UNSPECIFIED) ? AVCOL_PRI_BT709 : out->color_primaries;
498 outvsi_conf.TransferCharacteristics = (out->color_trc == AVCOL_TRC_UNSPECIFIED) ? AVCOL_TRC_BT709 : out->color_trc;
499 outvsi_conf.MatrixCoefficients = (out->colorspace == AVCOL_SPC_UNSPECIFIED) ? AVCOL_SPC_BT709 : out->colorspace;
500 outvsi_conf.ColourDescriptionPresent = 1;
501
502 if (memcmp(&vpp->invsi_conf, &invsi_conf, sizeof(mfxExtVideoSignalInfo)) ||
503 memcmp(&vpp->mdcv_conf, &mdcv_conf, sizeof(mfxExtMasteringDisplayColourVolume)) ||
504 memcmp(&vpp->clli_conf, &clli_conf, sizeof(mfxExtContentLightLevelInfo)) ||
505 memcmp(&vpp->outvsi_conf, &outvsi_conf, sizeof(mfxExtVideoSignalInfo))) {
506 vpp->invsi_conf = invsi_conf;
507 fp->ext_buf[fp->num_ext_buf++] = (mfxExtBuffer*)&vpp->invsi_conf;
508
509 vpp->outvsi_conf = outvsi_conf;
510 fp->ext_buf[fp->num_ext_buf++] = (mfxExtBuffer*)&vpp->outvsi_conf;
511
512 vpp->mdcv_conf = mdcv_conf;
513 if (mdcv_conf.Header.BufferId)
514 fp->ext_buf[fp->num_ext_buf++] = (mfxExtBuffer*)&vpp->mdcv_conf;
515
516 vpp->clli_conf = clli_conf;
517 if (clli_conf.Header.BufferId)
518 fp->ext_buf[fp->num_ext_buf++] = (mfxExtBuffer*)&vpp->clli_conf;
519 }
520#endif
521
522 return 0;
523}
524
525static int config_output(AVFilterLink *outlink)
526{
527 FilterLink *outl = ff_filter_link(outlink);
528 AVFilterContext *ctx = outlink->src;
529 VPPContext *vpp = ctx->priv;
530 QSVVPPParam param = { NULL };
531 QSVVPPCrop crop = { 0 };
532 mfxExtBuffer *ext_buf[ENH_FILTERS_COUNT];
533 mfxVersion mfx_version;
534 AVFilterLink *inlink = ctx->inputs[0];
535 FilterLink *inl = ff_filter_link(inlink);
536 FilterLink *ol = ff_filter_link(outlink);
537 enum AVPixelFormat in_format;
538
539 outlink->w = vpp->out_width;
540 outlink->h = vpp->out_height;
541 ol->frame_rate = vpp->framerate;
542 if (vpp->framerate.num == 0 || vpp->framerate.den == 0)
543 outlink->time_base = inlink->time_base;
544 else
545 outlink->time_base = av_inv_q(vpp->framerate);
546
547 param.filter_frame = NULL;
549 param.num_ext_buf = 0;
550 param.ext_buf = ext_buf;
551
552 if (get_mfx_version(ctx, &mfx_version) != MFX_ERR_NONE) {
553 av_log(ctx, AV_LOG_ERROR, "Failed to query mfx version.\n");
554 return AVERROR(EINVAL);
555 }
556
557 if (inlink->format == AV_PIX_FMT_QSV) {
558 if (!inl->hw_frames_ctx || !inl->hw_frames_ctx->data)
559 return AVERROR(EINVAL);
560 else
561 in_format = ((AVHWFramesContext*)inl->hw_frames_ctx->data)->sw_format;
562 } else
563 in_format = inlink->format;
564
565 if (vpp->out_format == AV_PIX_FMT_NONE)
566 vpp->out_format = in_format;
567 param.out_sw_format = vpp->out_format;
568
569 if (vpp->use_crop) {
570 crop.in_idx = 0;
571 crop.x = vpp->crop_x;
572 crop.y = vpp->crop_y;
573 crop.w = vpp->crop_w;
574 crop.h = vpp->crop_h;
575
576 param.num_crop = 1;
577 param.crop = &crop;
578 }
579
580#define INIT_MFX_EXTBUF(extbuf, id) do { \
581 memset(&vpp->extbuf, 0, sizeof(vpp->extbuf)); \
582 vpp->extbuf.Header.BufferId = id; \
583 vpp->extbuf.Header.BufferSz = sizeof(vpp->extbuf); \
584 param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->extbuf; \
585 } while (0)
586
587#define SET_MFX_PARAM_FIELD(extbuf, field, value) do { \
588 vpp->extbuf.field = value; \
589 } while (0)
590
591 if (vpp->deinterlace) {
592 INIT_MFX_EXTBUF(deinterlace_conf, MFX_EXTBUFF_VPP_DEINTERLACING);
593 SET_MFX_PARAM_FIELD(deinterlace_conf, Mode, (vpp->deinterlace == 1 ?
594 MFX_DEINTERLACING_BOB : MFX_DEINTERLACING_ADVANCED));
595 }
596
597 if (vpp->use_frc) {
598 INIT_MFX_EXTBUF(frc_conf, MFX_EXTBUFF_VPP_FRAME_RATE_CONVERSION);
599 SET_MFX_PARAM_FIELD(frc_conf, Algorithm, MFX_FRCALGM_DISTRIBUTED_TIMESTAMP);
600 }
601
602 if (vpp->denoise) {
603 INIT_MFX_EXTBUF(denoise_conf, MFX_EXTBUFF_VPP_DENOISE);
604 SET_MFX_PARAM_FIELD(denoise_conf, DenoiseFactor, vpp->denoise);
605 }
606
607 if (vpp->detail) {
608 INIT_MFX_EXTBUF(detail_conf, MFX_EXTBUFF_VPP_DETAIL);
609 SET_MFX_PARAM_FIELD(detail_conf, DetailFactor, vpp->detail);
610 }
611
612 if (vpp->procamp) {
613 INIT_MFX_EXTBUF(procamp_conf, MFX_EXTBUFF_VPP_PROCAMP);
614 SET_MFX_PARAM_FIELD(procamp_conf, Hue, vpp->hue);
615 SET_MFX_PARAM_FIELD(procamp_conf, Saturation, vpp->saturation);
616 SET_MFX_PARAM_FIELD(procamp_conf, Contrast, vpp->contrast);
617 SET_MFX_PARAM_FIELD(procamp_conf, Brightness, vpp->brightness);
618 }
619
620 if (vpp->transpose >= 0) {
621 if (QSV_RUNTIME_VERSION_ATLEAST(mfx_version, 1, 17)) {
622 switch (vpp->transpose) {
624 vpp->rotate = MFX_ANGLE_270;
625 vpp->hflip = MFX_MIRRORING_HORIZONTAL;
626 break;
627 case TRANSPOSE_CLOCK:
628 vpp->rotate = MFX_ANGLE_90;
629 vpp->hflip = MFX_MIRRORING_DISABLED;
630 break;
631 case TRANSPOSE_CCLOCK:
632 vpp->rotate = MFX_ANGLE_270;
633 vpp->hflip = MFX_MIRRORING_DISABLED;
634 break;
636 vpp->rotate = MFX_ANGLE_90;
637 vpp->hflip = MFX_MIRRORING_HORIZONTAL;
638 break;
640 vpp->rotate = MFX_ANGLE_180;
641 vpp->hflip = MFX_MIRRORING_DISABLED;
642 break;
643 case TRANSPOSE_HFLIP:
644 vpp->rotate = MFX_ANGLE_0;
645 vpp->hflip = MFX_MIRRORING_HORIZONTAL;
646 break;
647 case TRANSPOSE_VFLIP:
648 vpp->rotate = MFX_ANGLE_180;
649 vpp->hflip = MFX_MIRRORING_HORIZONTAL;
650 break;
651 default:
652 av_log(ctx, AV_LOG_ERROR, "Failed to set transpose mode to %d.\n", vpp->transpose);
653 return AVERROR(EINVAL);
654 }
655 } else {
656 av_log(ctx, AV_LOG_WARNING, "The QSV VPP transpose option is "
657 "not supported with this MSDK version.\n");
658 vpp->transpose = 0;
659 }
660 }
661
662 if (vpp->rotate) {
663 if (QSV_RUNTIME_VERSION_ATLEAST(mfx_version, 1, 17)) {
664 INIT_MFX_EXTBUF(rotation_conf, MFX_EXTBUFF_VPP_ROTATION);
665 SET_MFX_PARAM_FIELD(rotation_conf, Angle, vpp->rotate);
666
667 if (MFX_ANGLE_90 == vpp->rotate || MFX_ANGLE_270 == vpp->rotate) {
668 FFSWAP(int, vpp->out_width, vpp->out_height);
669 FFSWAP(int, outlink->w, outlink->h);
670 av_log(ctx, AV_LOG_DEBUG, "Swap width and height for clock/cclock rotation.\n");
671 }
672 } else {
673 av_log(ctx, AV_LOG_WARNING, "The QSV VPP rotate option is "
674 "not supported with this MSDK version.\n");
675 vpp->rotate = 0;
676 }
677 }
678
679 if (vpp->hflip) {
680 if (QSV_RUNTIME_VERSION_ATLEAST(mfx_version, 1, 19)) {
681 INIT_MFX_EXTBUF(mirroring_conf, MFX_EXTBUFF_VPP_MIRRORING);
682 SET_MFX_PARAM_FIELD(mirroring_conf, Type, vpp->hflip);
683 } else {
684 av_log(ctx, AV_LOG_WARNING, "The QSV VPP hflip option is "
685 "not supported with this MSDK version.\n");
686 vpp->hflip = 0;
687 }
688 }
689
690 if (inlink->w != outlink->w || inlink->h != outlink->h || in_format != vpp->out_format) {
691 if (QSV_RUNTIME_VERSION_ATLEAST(mfx_version, 1, 19)) {
692 int mode = vpp->scale_mode;
693
694#if QSV_ONEVPL
695 if (mode > 2)
696 mode = MFX_SCALING_MODE_VENDOR + mode - 2;
697#endif
698
699 INIT_MFX_EXTBUF(scale_conf, MFX_EXTBUFF_VPP_SCALING);
700 SET_MFX_PARAM_FIELD(scale_conf, ScalingMode, mode);
701 } else
702 av_log(ctx, AV_LOG_WARNING, "The QSV VPP Scale & format conversion "
703 "option is not supported with this MSDK version.\n");
704 }
705
706#undef INIT_MFX_EXTBUF
707#undef SET_MFX_PARAM_FIELD
708
709 if (vpp->use_frc || vpp->use_crop || vpp->deinterlace || vpp->denoise ||
710 vpp->detail || vpp->procamp || vpp->rotate || vpp->hflip ||
711 inlink->w != outlink->w || inlink->h != outlink->h || in_format != vpp->out_format ||
716 vpp->tonemap ||
717 !vpp->has_passthrough)
718 return ff_qsvvpp_init(ctx, &param);
719 else {
720 /* No MFX session is created in this case */
721 av_log(ctx, AV_LOG_VERBOSE, "qsv vpp pass through mode.\n");
722 if (inl->hw_frames_ctx)
724 }
725
726 return 0;
727}
728
730{
731 AVFilterLink *inlink = ctx->inputs[0];
732 AVFilterLink *outlink = ctx->outputs[0];
733 QSVVPPContext *qsv = ctx->priv;
734 AVFrame *in = NULL;
735 int ret, status = 0;
737
738 FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
739
740 if (!qsv->eof) {
741 ret = ff_inlink_consume_frame(inlink, &in);
742 if (ret < 0)
743 return ret;
744
745 if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
746 if (status == AVERROR_EOF) {
747 qsv->eof = 1;
748 }
749 }
750 }
751
752 if (qsv->session) {
753 if (in || qsv->eof) {
754 ret = ff_qsvvpp_filter_frame(qsv, inlink, in, in);
755 av_frame_free(&in);
756 if (ret == AVERROR(EAGAIN))
757 goto not_ready;
758 else if (ret < 0)
759 return ret;
760
761 if (qsv->eof)
762 goto eof;
763
764 if (qsv->got_frame) {
765 qsv->got_frame = 0;
766 return 0;
767 }
768 }
769 } else {
770 /* No MFX session is created in pass-through mode */
771 if (in) {
772 FilterLink *ol = ff_filter_link(outlink);
773 if (in->pts != AV_NOPTS_VALUE)
774 in->pts = av_rescale_q(in->pts, inlink->time_base, outlink->time_base);
775
776 if (ol->frame_rate.num && ol->frame_rate.den)
777 in->duration = av_rescale_q(1, av_inv_q(ol->frame_rate), outlink->time_base);
778 else
779 in->duration = 0;
780
781 ret = ff_filter_frame(outlink, in);
782 if (ret < 0)
783 return ret;
784
785 if (qsv->eof)
786 goto eof;
787
788 return 0;
789 }
790 }
791
792not_ready:
793 if (qsv->eof)
794 goto eof;
795
796 FF_FILTER_FORWARD_WANTED(outlink, inlink);
797
798 return FFERROR_NOT_READY;
799
800eof:
801 pts = av_rescale_q(pts, inlink->time_base, outlink->time_base);
802 ff_outlink_set_status(outlink, status, pts);
803 return 0;
804}
805
810
811static const AVFilterPad vpp_inputs[] = {
812 {
813 .name = "default",
814 .type = AVMEDIA_TYPE_VIDEO,
815 .config_props = config_input,
816 .get_buffer.video = ff_qsvvpp_get_video_buffer,
817 },
818};
819
820static const AVFilterPad vpp_outputs[] = {
821 {
822 .name = "default",
823 .type = AVMEDIA_TYPE_VIDEO,
824 .config_props = config_output,
825 },
826};
827
828#define DEFINE_QSV_FILTER(x, sn, ln, fmts) \
829static const AVClass x##_class = { \
830 .class_name = #sn "_qsv", \
831 .item_name = av_default_item_name, \
832 .option = x##_options, \
833 .version = LIBAVUTIL_VERSION_INT, \
834}; \
835const FFFilter ff_vf_##sn##_qsv = { \
836 .p.name = #sn "_qsv", \
837 .p.description = NULL_IF_CONFIG_SMALL("Quick Sync Video " #ln), \
838 .p.priv_class = &x##_class, \
839 .p.flags = AVFILTER_FLAG_HWDEVICE, \
840 .preinit = x##_preinit, \
841 .init = vpp_init, \
842 .uninit = vpp_uninit, \
843 .priv_size = sizeof(VPPContext), \
844 FILTER_INPUTS(vpp_inputs), \
845 FILTER_OUTPUTS(vpp_outputs), \
846 fmts, \
847 .activate = activate, \
848 .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE, \
849};
850
851#if CONFIG_VPP_QSV_FILTER
852
853static const AVOption vpp_options[] = {
854 { "deinterlace", "deinterlace mode: 0=off, 1=bob, 2=advanced", OFFSET(deinterlace), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, MFX_DEINTERLACING_ADVANCED, .flags = FLAGS, .unit = "deinterlace" },
855 { "bob", "Bob deinterlace mode.", 0, AV_OPT_TYPE_CONST, { .i64 = MFX_DEINTERLACING_BOB }, .flags = FLAGS, .unit = "deinterlace" },
856 { "advanced", "Advanced deinterlace mode. ", 0, AV_OPT_TYPE_CONST, { .i64 = MFX_DEINTERLACING_ADVANCED }, .flags = FLAGS, .unit = "deinterlace" },
857
858 { "denoise", "denoise level [0, 100]", OFFSET(denoise), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100, .flags = FLAGS },
859 { "detail", "enhancement level [0, 100]", OFFSET(detail), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100, .flags = FLAGS },
860 { "framerate", "output framerate", OFFSET(framerate), AV_OPT_TYPE_RATIONAL, { .dbl = 0.0 },0, DBL_MAX, .flags = FLAGS },
861 { "procamp", "Enable ProcAmp", OFFSET(procamp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = FLAGS},
862 { "hue", "ProcAmp hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, { .dbl = 0.0 }, -180.0, 180.0, .flags = FLAGS},
863 { "saturation", "ProcAmp saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, { .dbl = 1.0 }, 0.0, 10.0, .flags = FLAGS},
864 { "contrast", "ProcAmp contrast", OFFSET(contrast), AV_OPT_TYPE_FLOAT, { .dbl = 1.0 }, 0.0, 10.0, .flags = FLAGS},
865 { "brightness", "ProcAmp brightness", OFFSET(brightness), AV_OPT_TYPE_FLOAT, { .dbl = 0.0 }, -100.0, 100.0, .flags = FLAGS},
866
867 { "transpose", "set transpose direction", OFFSET(transpose), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 6, FLAGS, .unit = "transpose"},
868 { "cclock_hflip", "rotate counter-clockwise with horizontal flip", 0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CCLOCK_FLIP }, .flags=FLAGS, .unit = "transpose" },
869 { "clock", "rotate clockwise", 0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CLOCK }, .flags=FLAGS, .unit = "transpose" },
870 { "cclock", "rotate counter-clockwise", 0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CCLOCK }, .flags=FLAGS, .unit = "transpose" },
871 { "clock_hflip", "rotate clockwise with horizontal flip", 0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CLOCK_FLIP }, .flags=FLAGS, .unit = "transpose" },
872 { "reversal", "rotate by half-turn", 0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_REVERSAL }, .flags=FLAGS, .unit = "transpose" },
873 { "hflip", "flip horizontally", 0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_HFLIP }, .flags=FLAGS, .unit = "transpose" },
874 { "vflip", "flip vertically", 0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_VFLIP }, .flags=FLAGS, .unit = "transpose" },
875
876 { "cw", "set the width crop area expression", OFFSET(cw), AV_OPT_TYPE_STRING, { .str = "iw" }, 0, 0, FLAGS },
877 { "ch", "set the height crop area expression", OFFSET(ch), AV_OPT_TYPE_STRING, { .str = "ih" }, 0, 0, FLAGS },
878 { "cx", "set the x crop area expression", OFFSET(cx), AV_OPT_TYPE_STRING, { .str = "(in_w-out_w)/2" }, 0, 0, FLAGS },
879 { "cy", "set the y crop area expression", OFFSET(cy), AV_OPT_TYPE_STRING, { .str = "(in_h-out_h)/2" }, 0, 0, FLAGS },
880
881 { "w", "Output video width(0=input video width, -1=keep input video aspect)", OFFSET(ow), AV_OPT_TYPE_STRING, { .str="cw" }, 0, 255, .flags = FLAGS },
882 { "width", "Output video width(0=input video width, -1=keep input video aspect)", OFFSET(ow), AV_OPT_TYPE_STRING, { .str="cw" }, 0, 255, .flags = FLAGS },
883 { "h", "Output video height(0=input video height, -1=keep input video aspect)", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS },
884 { "height", "Output video height(0=input video height, -1=keep input video aspect)", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS },
885 { "format", "Output pixel format", OFFSET(output_format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS },
886 { "async_depth", "Internal parallelization depth, the higher the value the higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = 4 }, 0, INT_MAX, .flags = FLAGS },
887#if QSV_ONEVPL
888 { "scale_mode", "scaling & format conversion mode (mode compute(3), vd(4) and ve(5) are only available on some platforms)", OFFSET(scale_mode), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 5, .flags = FLAGS, .unit = "scale mode" },
889#else
890 { "scale_mode", "scaling & format conversion mode", OFFSET(scale_mode), AV_OPT_TYPE_INT, { .i64 = MFX_SCALING_MODE_DEFAULT }, MFX_SCALING_MODE_DEFAULT, MFX_SCALING_MODE_QUALITY, .flags = FLAGS, .unit = "scale mode" },
891#endif
892 { "auto", "auto mode", 0, AV_OPT_TYPE_CONST, { .i64 = MFX_SCALING_MODE_DEFAULT}, INT_MIN, INT_MAX, FLAGS, .unit = "scale mode"},
893 { "low_power", "low power mode", 0, AV_OPT_TYPE_CONST, { .i64 = MFX_SCALING_MODE_LOWPOWER}, INT_MIN, INT_MAX, FLAGS, .unit = "scale mode"},
894 { "hq", "high quality mode", 0, AV_OPT_TYPE_CONST, { .i64 = MFX_SCALING_MODE_QUALITY}, INT_MIN, INT_MAX, FLAGS, .unit = "scale mode"},
895#if QSV_ONEVPL
896 { "compute", "compute", 0, AV_OPT_TYPE_CONST, { .i64 = 3}, INT_MIN, INT_MAX, FLAGS, .unit = "scale mode"},
897 { "vd", "vd", 0, AV_OPT_TYPE_CONST, { .i64 = 4}, INT_MIN, INT_MAX, FLAGS, .unit = "scale mode"},
898 { "ve", "ve", 0, AV_OPT_TYPE_CONST, { .i64 = 5}, INT_MIN, INT_MAX, FLAGS, .unit = "scale mode"},
899#endif
900
901 { "rate", "Generate output at frame rate or field rate, available only for deinterlace mode",
902 OFFSET(field_rate), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS, .unit = "rate" },
903 { "frame", "Output at frame rate (one frame of output for each field-pair)",
904 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, FLAGS, .unit = "rate" },
905 { "field", "Output at field rate (one frame of output for each field)",
906 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, FLAGS, .unit = "rate" },
907
908 { "out_range", "Output color range",
911 { "full", "Full range",
912 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_JPEG }, 0, 0, FLAGS, .unit = "range" },
913 { "limited", "Limited range",
914 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, .unit = "range" },
915 { "jpeg", "Full range",
916 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_JPEG }, 0, 0, FLAGS, .unit = "range" },
917 { "mpeg", "Limited range",
918 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, .unit = "range" },
919 { "tv", "Limited range",
920 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, .unit = "range" },
921 { "pc", "Full range",
922 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_JPEG }, 0, 0, FLAGS, .unit = "range" },
923 { "out_color_matrix", "Output color matrix coefficient set",
924 OFFSET(color_matrix_str), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
925 { "out_color_primaries", "Output color primaries",
926 OFFSET(color_primaries_str), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
927 { "out_color_transfer", "Output color transfer characteristics",
928 OFFSET(color_transfer_str), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
929
930 {"tonemap", "Perform tonemapping (0=disable tonemapping, 1=perform tonemapping if the input has HDR metadata)", OFFSET(tonemap), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, .flags = FLAGS},
931
932 { NULL }
933};
934
935static int vpp_query_formats(const AVFilterContext *ctx,
936 AVFilterFormatsConfig **cfg_in,
937 AVFilterFormatsConfig **cfg_out)
938{
939 const VPPContext *vpp = ctx->priv;
940 int ret, i = 0;
941 static const enum AVPixelFormat in_pix_fmts[] = {
947#if CONFIG_VAAPI
949#endif
952 };
953 static enum AVPixelFormat out_pix_fmts[4];
954
956 &cfg_in[0]->formats);
957 if (ret < 0)
958 return ret;
959
960 /* User specifies the output format */
961 if (vpp->out_format == AV_PIX_FMT_NV12 ||
963 out_pix_fmts[i++] = vpp->out_format;
964 else {
967 }
968
971
973 &cfg_out[0]->formats);
974}
975
976DEFINE_QSV_FILTER(vpp, vpp, "VPP", FILTER_QUERY_FUNC2(vpp_query_formats));
977
978#endif
979
980#if CONFIG_SCALE_QSV_FILTER
981
982static const AVOption qsvscale_options[] = {
983 { "w", "Output video width(0=input video width, -1=keep input video aspect)", OFFSET(ow), AV_OPT_TYPE_STRING, { .str = "iw" }, .flags = FLAGS },
984 { "h", "Output video height(0=input video height, -1=keep input video aspect)", OFFSET(oh), AV_OPT_TYPE_STRING, { .str = "ih" }, .flags = FLAGS },
985 { "format", "Output pixel format", OFFSET(output_format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS },
986
987#if QSV_ONEVPL
988 { "mode", "scaling & format conversion mode (mode compute(3), vd(4) and ve(5) are only available on some platforms)", OFFSET(scale_mode), AV_OPT_TYPE_INT, { .i64 = 0}, 0, 5, FLAGS, .unit = "mode"},
989#else
990 { "mode", "scaling & format conversion mode", OFFSET(scale_mode), AV_OPT_TYPE_INT, { .i64 = MFX_SCALING_MODE_DEFAULT}, MFX_SCALING_MODE_DEFAULT, MFX_SCALING_MODE_QUALITY, FLAGS, .unit = "mode"},
991#endif
992 { "low_power", "low power mode", 0, AV_OPT_TYPE_CONST, { .i64 = MFX_SCALING_MODE_LOWPOWER}, INT_MIN, INT_MAX, FLAGS, .unit = "mode"},
993 { "hq", "high quality mode", 0, AV_OPT_TYPE_CONST, { .i64 = MFX_SCALING_MODE_QUALITY}, INT_MIN, INT_MAX, FLAGS, .unit = "mode"},
994#if QSV_ONEVPL
995 { "compute", "compute", 0, AV_OPT_TYPE_CONST, { .i64 = 3}, INT_MIN, INT_MAX, FLAGS, .unit = "mode"},
996 { "vd", "vd", 0, AV_OPT_TYPE_CONST, { .i64 = 4}, INT_MIN, INT_MAX, FLAGS, .unit = "mode"},
997 { "ve", "ve", 0, AV_OPT_TYPE_CONST, { .i64 = 5}, INT_MIN, INT_MAX, FLAGS, .unit = "mode"},
998#endif
999
1000 { NULL },
1001};
1002
1003static av_cold int qsvscale_preinit(AVFilterContext *ctx)
1004{
1005 VPPContext *vpp = ctx->priv;
1006
1008 vpp->has_passthrough = 0;
1009
1010 return 0;
1011}
1012
1013DEFINE_QSV_FILTER(qsvscale, scale, "scaling and format conversion", FILTER_SINGLE_PIXFMT(AV_PIX_FMT_QSV));
1014
1015#endif
1016
1017#if CONFIG_DEINTERLACE_QSV_FILTER
1018
1019static const AVOption qsvdeint_options[] = {
1020 { "mode", "set deinterlace mode", OFFSET(deinterlace), AV_OPT_TYPE_INT, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, .unit = "mode"},
1021 { "bob", "bob algorithm", 0, AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_BOB}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, .unit = "mode"},
1022 { "advanced", "Motion adaptive algorithm", 0, AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED, FLAGS, .unit = "mode"},
1023
1024 { NULL },
1025};
1026
1027static av_cold int qsvdeint_preinit(AVFilterContext *ctx)
1028{
1029 VPPContext *vpp = ctx->priv;
1030
1032 vpp->has_passthrough = 0;
1033 vpp->field_rate = 1;
1034
1035 return 0;
1036}
1037
1038DEFINE_QSV_FILTER(qsvdeint, deinterlace, "deinterlacing", FILTER_SINGLE_PIXFMT(AV_PIX_FMT_QSV))
1039
1040#endif
@ VAR_CH
Definition aeval.c:49
static int config_input(AVFilterLink *inlink)
Mode
Frame type (Table 1a in 3GPP TS 26.101)
Definition amrnbdata.h:39
static FILE * out
static AVFormatContext * ctx
@ VAR_H
Definition avfilter.c:565
@ VAR_W
Definition avfilter.c:564
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition avfilter.c:1467
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Definition avfilter.c:1520
Main libavfilter public API header.
@ VAR_CW
Definition boxblur.c:39
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define FLAGS
Definition cmdutils.c:598
static IPT saturation(const CmsCtx *ctx, IPT ipt)
Definition cms.c:559
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static const AVColorPrimariesDesc color_primaries[AVCOL_PRI_NB]
Definition csp.c:76
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition eval.c:368
simple arithmetic expression evaluator
@ VAR_IW
Definition f_select.c:147
@ VAR_IH
Definition f_select.c:146
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add ref as a new reference to formats.
Definition formats.c:756
av_warn_unused_result AVFilterFormats * ff_make_pixel_format_list(const enum AVPixelFormat *fmts)
Create a list of supported pixel formats.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_RATIONAL
Underlying C type is AVRational.
Definition opt.h:279
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition opt.h:270
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition buffer.c:103
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition frame.c:659
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type.
Definition frame.c:725
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition frame.h:137
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
Definition frame.h:120
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition rational.c:80
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition rational.h:89
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition rational.h:159
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
An API-specific header for AV_HWDEVICE_TYPE_QSV.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition intra.c:278
static int config_output(AVBitStreamFilterLink *outlink)
#define transpose(x)
#define FF_FILTER_FORWARD_WANTED(outlink, inlink)
Forward the frame_wanted_out flag from an output link to an input link.
Definition filters.h:694
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition filters.h:629
#define FFERROR_NOT_READY
Filters implementation helper functions and internal structures.
Definition filters.h:34
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
Definition filters.h:639
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition filters.h:199
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition filters.h:254
#define FILTER_QUERY_FUNC2(func)
Definition filters.h:241
Type
Definition vf_idet.c:30
#define av_cold
Definition attributes.h:117
#define FFSWAP(type, a, b)
Definition macros.h:52
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define NAN
var_name
Definition noise.c:46
@ VAR_VARS_NB
Definition noise.c:59
static const char *const var_names[]
Definition noise.c:30
AVOptions.
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition pixdesc.c:3392
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:766
@ AVCOL_RANGE_UNSPECIFIED
Definition pixfmt.h:749
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:783
#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_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition pixfmt.h:88
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition pixfmt.h:74
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition pixfmt.h:247
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition pixfmt.h:642
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition pixfmt.h:644
@ AVCOL_PRI_UNSPECIFIED
Definition pixfmt.h:645
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition pixfmt.h:672
@ AVCOL_TRC_UNSPECIFIED
Definition pixfmt.h:675
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition pixfmt.h:674
#define AV_PIX_FMT_RGB32
Definition pixfmt.h:517
AVColorSpace
YUV colorspace type.
Definition pixfmt.h:706
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition pixfmt.h:708
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:709
#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR)
AVFrame * ff_qsvvpp_get_video_buffer(AVFilterLink *inlink, int w, int h)
Definition qsvvpp.c:1141
int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picref, AVFrame *propref)
Definition qsvvpp.c:959
int ff_qsvvpp_close(AVFilterContext *avctx)
Definition qsvvpp.c:935
int ff_qsvvpp_init(AVFilterContext *avctx, QSVVPPParam *param)
Definition qsvvpp.c:743
Intel Quick Sync Video VPP base function.
@ VAR_OUT_H
Definition scale_eval.c:47
@ VAR_SAR
Definition scale_eval.c:49
@ VAR_OH
Definition scale_eval.c:47
@ VAR_IN_W
Definition scale_eval.c:44
@ VAR_OW
Definition scale_eval.c:46
@ VAR_A
Definition scale_eval.c:48
@ VAR_OUT_W
Definition scale_eval.c:46
@ VAR_IN_H
Definition scale_eval.c:45
@ VAR_DAR
Definition scale_eval.c:50
formats
Definition signature.h:47
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
unsigned MaxFALL
Max average light level per frame (cd/m^2).
unsigned MaxCLL
Max content light level (cd/m^2).
Definition eval.c:171
An instance of a filter.
Definition avfilter.h:273
Lists of formats / etc.
Definition avfilter.h:120
A filter pad used for either input or output.
Definition filters.h:40
Structure to hold side data for an AVFrame.
Definition frame.h:327
uint8_t * data
Definition frame.h:329
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition frame.h:574
enum AVColorPrimaries color_primaries
Definition frame.h:725
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition frame.h:723
enum AVColorSpace colorspace
YUV colorspace type.
Definition frame.h:734
enum AVColorTransferCharacteristic color_trc
Definition frame.h:727
int64_t duration
Duration of the frame, in the same units as pts.
Definition frame.h:820
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition hwcontext.h:63
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition hwcontext.h:88
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition hwcontext.h:129
Mastering display metadata capable of representing the color volume of the display used to master the...
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
AVOption.
Definition opt.h:428
This struct is allocated as AVHWDeviceContext.hwctx.
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
mfxSession session
Definition qsvvpp.h:66
mfxVersion ver
Definition qsvvpp.h:101
int got_frame
Definition qsvvpp.h:95
int h
Crop rectangle.
Definition qsvvpp.h:107
int in_idx
Input index.
Definition qsvvpp.h:106
mfxExtBuffer ** ext_buf
Definition qsvvpp.h:60
int(* set_frame_ext_params)(AVFilterContext *ctx, const AVFrame *in, AVFrame *out, QSVVPPFrameParam *fp)
callback
Definition qsvvpp.h:113
int num_crop
Definition qsvvpp.h:123
QSVVPPCrop * crop
Definition qsvvpp.h:124
mfxExtBuffer ** ext_buf
Definition qsvvpp.h:117
int(* filter_frame)(AVFilterLink *outlink, AVFrame *frame)
Definition qsvvpp.h:112
enum AVPixelFormat out_sw_format
Definition qsvvpp.h:120
int num_ext_buf
Definition qsvvpp.h:116
mfxExtVPPRotation rotation_conf
Definition vf_vpp_qsv.c:58
char * color_transfer_str
Definition vf_vpp_qsv.c:114
char * ow
Definition vf_vpp_qsv.c:109
char * ch
Definition vf_vpp_qsv.c:108
int has_passthrough
Definition vf_vpp_qsv.c:122
int transpose
Definition vf_vpp_qsv.c:95
mfxExtVPPDeinterlacing deinterlace_conf
Definition vf_vpp_qsv.c:53
float saturation
Definition vf_vpp_qsv.c:104
char * cy
Definition vf_vpp_qsv.c:108
enum AVPixelFormat out_format
Output sw format.
Definition vf_vpp_qsv.c:81
mfxExtVPPFrameRateConversion frc_conf
Definition vf_vpp_qsv.c:54
char * color_primaries_str
The color properties for output.
Definition vf_vpp_qsv.c:113
mfxExtVPPProcAmp procamp_conf
Definition vf_vpp_qsv.c:57
enum AVColorSpace color_matrix
Definition vf_vpp_qsv.c:120
char * cw
Definition vf_vpp_qsv.c:108
enum AVColorTransferCharacteristic color_transfer
Definition vf_vpp_qsv.c:119
mfxExtVPPDenoise denoise_conf
Definition vf_vpp_qsv.c:55
char * cx
Definition vf_vpp_qsv.c:108
enum AVColorPrimaries color_primaries
Definition vf_vpp_qsv.c:118
int deinterlace
Definition vf_vpp_qsv.c:85
float contrast
Definition vf_vpp_qsv.c:105
int out_width
New dimensions.
Definition vf_vpp_qsv.c:76
int color_range
Definition vf_vpp_qsv.c:117
mfxExtVPPScaling scale_conf
Definition vf_vpp_qsv.c:60
char * oh
Definition vf_vpp_qsv.c:109
AVRational framerate
Definition vf_vpp_qsv.c:83
QSVVPPContext qsv
Definition vf_vpp_qsv.c:50
int out_height
Definition vf_vpp_qsv.c:77
float brightness
Definition vf_vpp_qsv.c:106
mfxExtVPPMirroring mirroring_conf
Definition vf_vpp_qsv.c:59
int scale_mode
Definition vf_vpp_qsv.c:99
char * color_matrix_str
Definition vf_vpp_qsv.c:115
char * output_format_str
Definition vf_vpp_qsv.c:110
mfxExtVPPDetail detail_conf
Definition vf_vpp_qsv.c:56
Definition swscale.c:71
#define lrint
Definition tablegen.h:53
#define av_log(a,...)
float framerate
Definition av1_levels.c:29
static int64_t pts
@ TRANSPOSE_CLOCK_FLIP
Definition transpose.h:34
@ TRANSPOSE_HFLIP
Definition transpose.h:36
@ TRANSPOSE_CCLOCK
Definition transpose.h:33
@ TRANSPOSE_CCLOCK_FLIP
Definition transpose.h:31
@ TRANSPOSE_VFLIP
Definition transpose.h:37
@ TRANSPOSE_REVERSAL
Definition transpose.h:35
@ TRANSPOSE_CLOCK
Definition transpose.h:32
static enum AVPixelFormat in_pix_fmts[]
static enum AVPixelFormat out_pix_fmts[]
@ VAR_CY
Y coordinate for current point.
Definition vf_drawvg.c:67
@ VAR_CX
X coordinate for current point.
Definition vf_drawvg.c:66
#define denoise(...)
Definition vf_hqdn3d.c:155
color_range
static void tonemap(TonemapContext *s, AVFrame *out, const AVFrame *in, const AVPixFmtDescriptor *desc, int x, int y, double peak)
Definition vf_tonemap.c:110
static av_cold int vpp_init(AVFilterContext *ctx)
Definition vf_vpp_qsv.c:260
static mfxStatus get_mfx_version(const AVFilterContext *ctx, mfxVersion *mfx_version)
Definition vf_vpp_qsv.c:365
#define INIT_MFX_EXTBUF(extbuf, id)
static int config_input(AVFilterLink *inlink)
Definition vf_vpp_qsv.c:295
static const AVFilterPad vpp_inputs[]
Definition vf_vpp_qsv.c:811
#define CALC_EXPR(e, v, i, d)
static const AVFilterPad vpp_outputs[]
Definition vf_vpp_qsv.c:820
#define PASS_EXPR(e, s)
static av_cold void vpp_uninit(AVFilterContext *ctx)
Definition vf_vpp_qsv.c:806
static int eval_expr(AVFilterContext *ctx)
Definition vf_vpp_qsv.c:155
static int activate(AVFilterContext *ctx)
Definition vf_vpp_qsv.c:729
static av_cold int vpp_preinit(AVFilterContext *ctx)
Definition vf_vpp_qsv.c:240
#define DEFINE_QSV_FILTER(x, sn, ln, fmts)
Definition vf_vpp_qsv.c:828
#define OFFSET(x)
Definition vf_vpp_qsv.c:43
static int config_output(AVFilterLink *outlink)
Definition vf_vpp_qsv.c:525
#define ENH_FILTERS_COUNT
Definition vf_vpp_qsv.c:47
#define SET_MFX_PARAM_FIELD(extbuf, field, value)
static int vpp_set_frame_ext_params(AVFilterContext *ctx, const AVFrame *in, AVFrame *out, QSVVPPFrameParam *fp)
Definition vf_vpp_qsv.c:391
#define STRING_OPTION(var_name, func_name, default_value)