History

lavfi/vf_vpp_qsv: allow special values for the output video dimensions

Special values are: 0 = original width/height -1 = keep original aspect This is in preparation for reusing the code for other QSV filters.

Haihao Xiang committed 3 years ago

Commit eb71c671 parent 129530e1 file · +40 −7Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_vpp_qsv.c+40−7
@@ -59,6 +59,11 @@ typedef struct VPPContext{ · 58 unmodified lines
5959 mfxExtVPPMirroring mirroring_conf;
6060 mfxExtVPPScaling scale_conf;
6161
62+ /**
63+ * New dimensions. Special values are:
64+ * 0 = original width/height
65+ * -1 = keep original aspect
66+ */
6267 int out_width;
6368 int out_height;
6469 /**
@@ -127,10 +132,10 @@ static const AVOption options[] = { · 62 unmodified lines
127132 { "cx", "set the x crop area expression", OFFSET(cx), AV_OPT_TYPE_STRING, { .str = "(in_w-out_w)/2" }, 0, 0, FLAGS },
128133 { "cy", "set the y crop area expression", OFFSET(cy), AV_OPT_TYPE_STRING, { .str = "(in_h-out_h)/2" }, 0, 0, FLAGS },
129134
130− { "w", "Output video width", OFFSET(ow), AV_OPT_TYPE_STRING, { .str="cw" }, 0, 255, .flags = FLAGS },
131− { "width", "Output video width", OFFSET(ow), AV_OPT_TYPE_STRING, { .str="cw" }, 0, 255, .flags = FLAGS },
132− { "h", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS },
133− { "height", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS },
135+ { "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 },
136+ { "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 },
137+ { "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 },
138+ { "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 },
134139 { "format", "Output pixel format", OFFSET(output_format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS },
135140 { "async_depth", "Internal parallelization depth, the higher the value the higher the latency.", OFFSET(async_depth), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, .flags = FLAGS },
136141 { "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" },
@@ -276,6 +281,7 @@ static int config_input(AVFilterLink *inlink) · 139 unmodified lines
276281 AVFilterContext *ctx = inlink->dst;
277282 VPPContext *vpp = ctx->priv;
278283 int ret;
284+ int64_t ow, oh;
279285
280286 if (vpp->framerate.den == 0 || vpp->framerate.num == 0)
281287 vpp->framerate = inlink->frame_rate;
@@ -289,11 +295,38 @@ static int config_input(AVFilterLink *inlink) · 7 unmodified lines
289295 return ret;
290296 }
291297
292− if (vpp->out_height == 0 || vpp->out_width == 0) {
293− vpp->out_width = inlink->w;
294− vpp->out_height = inlink->h;
298+ ow = vpp->out_width;
299+ oh = vpp->out_height;
300+
301+ /* sanity check params */
302+ if (ow < -1 || oh < -1) {
303+ av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n");
304+ return AVERROR(EINVAL);
295305 }
296306
307+ if (ow == -1 && oh == -1)
308+ vpp->out_width = vpp->out_height = 0;
309+
310+ if (!(ow = vpp->out_width))
311+ ow = inlink->w;
312+
313+ if (!(oh = vpp->out_height))
314+ oh = inlink->h;
315+
316+ if (ow == -1)
317+ ow = av_rescale(oh, inlink->w, inlink->h);
318+
319+ if (oh == -1)
320+ oh = av_rescale(ow, inlink->h, inlink->w);
321+
322+ if (ow > INT_MAX || oh > INT_MAX ||
323+ (oh * inlink->w) > INT_MAX ||
324+ (ow * inlink->h) > INT_MAX)
325+ av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
326+
327+ vpp->out_width = ow;
328+ vpp->out_height = oh;
329+
297330 if (vpp->use_crop) {
298331 vpp->crop_x = FFMAX(vpp->crop_x, 0);
299332 vpp->crop_y = FFMAX(vpp->crop_y, 0);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t