Go to the documentation of this file.
26 #include "config_components.h"
43 #define OFFSET(x) offsetof(VPPContext, x)
44 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM)
47 #define ENH_FILTERS_COUNT (8)
137 #define PASS_EXPR(e, s) {\
139 ret = av_expr_parse(&e, s, var_names, NULL, NULL, NULL, NULL, 0, ctx); \
141 av_log(ctx, AV_LOG_ERROR, "Error when passing '%s'.\n", s); \
146 #define CALC_EXPR(e, v, i, d) {\
148 i = v = av_expr_eval(e, var_values, NULL); \
175 var_values[
VAR_SAR] =
ctx->inputs[0]->sample_aspect_ratio.num ?
176 (
double)
ctx->inputs[0]->sample_aspect_ratio.num /
ctx->inputs[0]->sample_aspect_ratio.den : 1;
280 if (ow < -1 || oh < -1) {
285 if (ow == -1 && oh == -1)
300 if (ow > INT_MAX || oh > INT_MAX ||
301 (oh *
inlink->w) > INT_MAX ||
302 (ow *
inlink->h) > INT_MAX)
328 if (
inlink->hw_frames_ctx) {
331 }
else if (
ctx->hw_device_ctx) {
332 device_ref =
ctx->hw_device_ctx;
336 mfx_version->Major = 0;
337 mfx_version->Minor = 0;
342 device_hwctx = device_ctx->
hwctx;
344 return MFXQueryVersion(device_hwctx->
session, mfx_version);
354 mfxVersion mfx_version;
373 if (!
inlink->hw_frames_ctx || !
inlink->hw_frames_ctx->data)
378 in_format =
inlink->format;
395 #define INIT_MFX_EXTBUF(extbuf, id) do { \
396 memset(&vpp->extbuf, 0, sizeof(vpp->extbuf)); \
397 vpp->extbuf.Header.BufferId = id; \
398 vpp->extbuf.Header.BufferSz = sizeof(vpp->extbuf); \
399 param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->extbuf; \
402 #define SET_MFX_PARAM_FIELD(extbuf, field, value) do { \
403 vpp->extbuf.field = value; \
409 MFX_DEINTERLACING_BOB : MFX_DEINTERLACING_ADVANCED));
439 vpp->
rotate = MFX_ANGLE_270;
440 vpp->
hflip = MFX_MIRRORING_HORIZONTAL;
443 vpp->
rotate = MFX_ANGLE_90;
444 vpp->
hflip = MFX_MIRRORING_DISABLED;
447 vpp->
rotate = MFX_ANGLE_270;
448 vpp->
hflip = MFX_MIRRORING_DISABLED;
451 vpp->
rotate = MFX_ANGLE_90;
452 vpp->
hflip = MFX_MIRRORING_HORIZONTAL;
455 vpp->
rotate = MFX_ANGLE_180;
456 vpp->
hflip = MFX_MIRRORING_DISABLED;
459 vpp->
rotate = MFX_ANGLE_0;
460 vpp->
hflip = MFX_MIRRORING_HORIZONTAL;
463 vpp->
rotate = MFX_ANGLE_180;
464 vpp->
hflip = MFX_MIRRORING_HORIZONTAL;
472 "not supported with this MSDK version.\n");
482 if (MFX_ANGLE_90 == vpp->
rotate || MFX_ANGLE_270 == vpp->
rotate) {
484 FFSWAP(
int, outlink->
w, outlink->
h);
489 "not supported with this MSDK version.\n");
500 "not supported with this MSDK version.\n");
511 "option is not supported with this MSDK version.\n");
514 #undef INIT_MFX_EXTBUF
515 #undef SET_MFX_PARAM_FIELD
525 if (
inlink->hw_frames_ctx)
556 if (in || qsv->
eof) {
624 #define DEFINE_QSV_FILTER(x, sn, ln, fmts) \
625 static const AVClass x##_class = { \
626 .class_name = #sn "_qsv", \
627 .item_name = av_default_item_name, \
628 .option = x##_options, \
629 .version = LIBAVUTIL_VERSION_INT, \
631 const AVFilter ff_vf_##sn##_qsv = { \
632 .name = #sn "_qsv", \
633 .description = NULL_IF_CONFIG_SMALL("Quick Sync Video " #ln), \
634 .preinit = x##_preinit, \
636 .uninit = vpp_uninit, \
637 .priv_size = sizeof(VPPContext), \
638 .priv_class = &x##_class, \
639 FILTER_INPUTS(vpp_inputs), \
640 FILTER_OUTPUTS(vpp_outputs), \
642 .activate = activate, \
643 .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE, \
646 #if CONFIG_VPP_QSV_FILTER
648 static const AVOption vpp_options[] = {
649 {
"deinterlace",
"deinterlace mode: 0=off, 1=bob, 2=advanced",
OFFSET(deinterlace),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, MFX_DEINTERLACING_ADVANCED, .flags =
FLAGS,
"deinterlace" },
650 {
"bob",
"Bob deinterlace mode.", 0,
AV_OPT_TYPE_CONST, { .i64 = MFX_DEINTERLACING_BOB }, .flags =
FLAGS,
"deinterlace" },
651 {
"advanced",
"Advanced deinterlace mode. ", 0,
AV_OPT_TYPE_CONST, { .i64 = MFX_DEINTERLACING_ADVANCED }, .flags =
FLAGS,
"deinterlace" },
676 {
"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 },
677 {
"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 },
678 {
"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 },
679 {
"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 },
681 {
"async_depth",
"Internal parallelization depth, the higher the value the higher the latency.",
OFFSET(qsv.async_depth),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, .flags =
FLAGS },
682 {
"scale_mode",
"scale & format conversion mode: 0=auto, 1=low power, 2=high quality",
OFFSET(scale_mode),
AV_OPT_TYPE_INT, { .i64 = MFX_SCALING_MODE_DEFAULT }, MFX_SCALING_MODE_DEFAULT, MFX_SCALING_MODE_QUALITY, .flags =
FLAGS,
"scale mode" },
683 {
"auto",
"auto mode", 0,
AV_OPT_TYPE_CONST, { .i64 = MFX_SCALING_MODE_DEFAULT}, INT_MIN, INT_MAX,
FLAGS,
"scale mode"},
684 {
"low_power",
"low power mode", 0,
AV_OPT_TYPE_CONST, { .i64 = MFX_SCALING_MODE_LOWPOWER}, INT_MIN, INT_MAX,
FLAGS,
"scale mode"},
685 {
"hq",
"high quality mode", 0,
AV_OPT_TYPE_CONST, { .i64 = MFX_SCALING_MODE_QUALITY}, INT_MIN, INT_MAX,
FLAGS,
"scale mode"},
687 {
"rate",
"Generate output at frame rate or field rate, available only for deinterlace mode",
689 {
"frame",
"Output at frame rate (one frame of output for each field-pair)",
691 {
"field",
"Output at field rate (one frame of output for each field)",
717 &
ctx->inputs[0]->outcfg.formats);
721 &
ctx->outputs[0]->incfg.formats);
728 #if CONFIG_SCALE_QSV_FILTER
730 static const AVOption qsvscale_options[] = {
731 {
"w",
"Output video width(0=input video width, -1=keep input video aspect)",
OFFSET(ow),
AV_OPT_TYPE_STRING, { .str =
"iw" }, .flags =
FLAGS },
732 {
"h",
"Output video height(0=input video height, -1=keep input video aspect)",
OFFSET(oh),
AV_OPT_TYPE_STRING, { .str =
"ih" }, .flags =
FLAGS },
735 {
"mode",
"set scaling mode",
OFFSET(scale_mode),
AV_OPT_TYPE_INT, { .i64 = MFX_SCALING_MODE_DEFAULT}, MFX_SCALING_MODE_DEFAULT, MFX_SCALING_MODE_QUALITY,
FLAGS,
"mode"},
736 {
"low_power",
"low power mode", 0,
AV_OPT_TYPE_CONST, { .i64 = MFX_SCALING_MODE_LOWPOWER}, INT_MIN, INT_MAX,
FLAGS,
"mode"},
737 {
"hq",
"high quality mode", 0,
AV_OPT_TYPE_CONST, { .i64 = MFX_SCALING_MODE_QUALITY}, INT_MIN, INT_MAX,
FLAGS,
"mode"},
756 #if CONFIG_DEINTERLACE_QSV_FILTER
758 static const AVOption qsvdeint_options[] = {
759 {
"mode",
"set deinterlace mode",
OFFSET(deinterlace),
AV_OPT_TYPE_INT, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED,
FLAGS,
"mode"},
760 {
"bob",
"bob algorithm", 0,
AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_BOB}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED,
FLAGS,
"mode"},
761 {
"advanced",
"Motion adaptive algorithm", 0,
AV_OPT_TYPE_CONST, {.i64 = MFX_DEINTERLACING_ADVANCED}, MFX_DEINTERLACING_BOB, MFX_DEINTERLACING_ADVANCED,
FLAGS,
"mode"},
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
enum AVPixelFormat out_sw_format
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#define AVERROR_EOF
End of file.
uint8_t * data
The data buffer.
AVFrame * ff_qsvvpp_get_video_buffer(AVFilterLink *inlink, int w, int h)
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
This struct is allocated as AVHWDeviceContext.hwctx.
#define FILTER_QUERY_FUNC(func)
static av_cold void vpp_uninit(AVFilterContext *ctx)
#define AV_LOG_VERBOSE
Detailed information.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
A link between two filters.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
static av_always_inline float scale(float x, float s)
enum AVPixelFormat out_format
Output sw format.
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
A filter pad used for either input or output.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
int out_width
New dimensions.
static enum AVPixelFormat in_pix_fmts[]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Mode
Frame type (Table 1a in 3GPP TS 26.101)
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
mfxExtVPPDenoise denoise_conf
#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR)
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int activate(AVFilterContext *ctx)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
mfxExtVPPDetail detail_conf
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define INIT_MFX_EXTBUF(extbuf, id)
int ff_qsvvpp_close(AVFilterContext *avctx)
#define ENH_FILTERS_COUNT
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Rational number (pair of numerator and denominator).
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
mfxExtVPPDeinterlacing deinterlace_conf
mfxExtVPPFrameRateConversion frc_conf
static const AVFilterPad vpp_inputs[]
#define DEFINE_QSV_FILTER(x, sn, ln, fmts)
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
mfxExtVPPScaling scale_conf
static int config_input(AVFilterLink *inlink)
#define AV_NOPTS_VALUE
Undefined timestamp value.
AVFilterContext * src
source filter
mfxExtVPPProcAmp procamp_conf
FF_FILTER_FORWARD_WANTED(outlink, inlink)
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
static int config_output(AVFilterLink *outlink)
int w
agreed upon image width
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
mfxExtVPPRotation rotation_conf
static enum AVPixelFormat out_pix_fmts[]
static mfxStatus get_mfx_version(const AVFilterContext *ctx, mfxVersion *mfx_version)
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int(* filter_frame)(AVFilterLink *outlink, AVFrame *frame)
int ff_qsvvpp_init(AVFilterContext *avctx, QSVVPPParam *param)
const char * name
Pad name.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
static av_cold int vpp_init(AVFilterContext *ctx)
#define CALC_EXPR(e, v, i, d)
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
This struct describes a set or pool of "hardware" frames (i.e.
@ 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...
#define FFSWAP(type, a, b)
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picref)
static int eval_expr(AVFilterContext *ctx)
int h
agreed upon image height
static av_cold int vpp_preinit(AVFilterContext *ctx)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
#define SET_MFX_PARAM_FIELD(extbuf, field, value)
A reference to a data buffer.
static const char *const var_names[]
mfxExtVPPMirroring mirroring_conf
static const AVFilterPad vpp_outputs[]