From patchwork Tue Jun 15 06:13:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 28315 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp3527260iol; Mon, 14 Jun 2021 23:16:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxk5e/f4LOwOuJUdlEIPzi8aN5pBC7DuzrF9DxZoHWVKEvApUm3Ym8kwtZai/usPrQLOhIV X-Received: by 2002:a17:907:9617:: with SMTP id gb23mr19067887ejc.483.1623737797041; Mon, 14 Jun 2021 23:16:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623737797; cv=none; d=google.com; s=arc-20160816; b=nkns4xafruRtHd5PGuaoLGJC4RJuiDpoZT+PFyIsKqRTXA+vxht51DYa++x0TeRV4s fggbydYDqDV4C5gBoCyx9dXj68ldTJvJtkp/2dyeSYRNjIXUB9Za4ip/MwQ29Wf9mO84 ugfksT7hK6lAyFYV4F8J+90plwb1PMbtJ1kUOwnrH/X34IrOnsuIYaukakmNpNVn3iQa Ys/bqSncxiXFqR6NecHP4vljUk48YxermiQLjpJD73WF8wVmC+7O+vYfMoHcNXmtdkIc xhoPd+ytCqZ/e69DIEnEFIhvqItVHuGcIlu2CArNw0h/6mbG8aYBnM4lyxlB/ixxP1JH ETDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:ironport-sdr:ironport-sdr:delivered-to; bh=QgRn3bxZ5qeZtNppIHNSF9IFACv7VNkUwt1EbK/++8Q=; b=IgfXD7o1a0i2XHKGJsf3/twzR07olg1QjYTZXpUwNKqz+MQVX/K7CVRbKaCL3emdg8 xoJy+ja/9sZ4DpJTFEfqe3+H+9kTdZAus3euqFrPxHYb77BenK4atGJpE4+2cYrsxzkZ bvhvQDbS3c77jIJYUq0sNHjir5GeQwaqkdbh+GTPgRg8MyQOgK4oe5ycpWSnvnDZnRXm Kzb2uKkiYP1mi8QQ4Ni5vG/24ZkgLr9d5FQ9H1BFCZZpbikpGcgYFAAlLBJoBJaqlPqE gZRxYPTULJsPrRjeud6Gh+fcjdNUD1V0Ll6AKnNuUw/yAwEV54Kre2+wbOUOatMzdUug eFqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id n9si13882007edw.373.2021.06.14.23.16.36; Mon, 14 Jun 2021 23:16:37 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6BF336897E7; Tue, 15 Jun 2021 09:15:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DF3C4687F2A for ; Tue, 15 Jun 2021 09:15:43 +0300 (EEST) IronPort-SDR: h6gc+Qla7pNmT2knHoeogt5Jg7YYDTLqUp04H0m8w51xB+cYCVYx7Zb+hxUEgaOLaoxO0WkEyc PcbTYsLPOsaQ== X-IronPort-AV: E=McAfee;i="6200,9189,10015"; a="227395414" X-IronPort-AV: E=Sophos;i="5.83,275,1616482800"; d="scan'208";a="227395414" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2021 23:15:33 -0700 IronPort-SDR: 0TA8U96vXIThrGtQd2DUoIAZgT9VwIbsBK0lqS1lmL1VUatgRXDv7iFTqvOwfurVsvf68dxw8n Al+cH+ksHAeA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,275,1616482800"; d="scan'208";a="451857139" Received: from xhh-tgl64.sh.intel.com ([10.239.159.53]) by fmsmga008.fm.intel.com with ESMTP; 14 Jun 2021 23:15:32 -0700 From: Haihao Xiang To: ffmpeg-devel@ffmpeg.org Date: Tue, 15 Jun 2021 14:13:47 +0800 Message-Id: <20210615061403.1576282-7-haihao.xiang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210615061403.1576282-1-haihao.xiang@intel.com> References: <20210615061403.1576282-1-haihao.xiang@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 06/22] lavfi/vpp_qsv: allow special values for the output dimensions X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Haihao Xiang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Pq6VvzhYHc0E Special values are: 0 = original width/height -1 = keep original aspect This is in preparation for re-using VPPContext for scale_qsv filter --- libavfilter/vf_vpp_qsv.c | 47 ++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c index adcfd0484d..7afbb3c983 100644 --- a/libavfilter/vf_vpp_qsv.c +++ b/libavfilter/vf_vpp_qsv.c @@ -59,6 +59,11 @@ typedef struct VPPContext{ mfxExtVPPRotation rotation_conf; mfxExtVPPMirroring mirroring_conf; + /** + * New dimensions. Special values are: + * 0 = original width/height + * -1 = keep original aspect + */ int out_width; int out_height; /** @@ -122,10 +127,10 @@ static const AVOption options[] = { { "cx", "set the x crop area expression", OFFSET(cx), AV_OPT_TYPE_STRING, { .str = "(in_w-out_w)/2" }, 0, 0, FLAGS }, { "cy", "set the y crop area expression", OFFSET(cy), AV_OPT_TYPE_STRING, { .str = "(in_h-out_h)/2" }, 0, 0, FLAGS }, - { "w", "Output video width", OFFSET(ow), AV_OPT_TYPE_STRING, { .str="cw" }, 0, 255, .flags = FLAGS }, - { "width", "Output video width", OFFSET(ow), AV_OPT_TYPE_STRING, { .str="cw" }, 0, 255, .flags = FLAGS }, - { "h", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS }, - { "height", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS }, + { "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 }, + { "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 }, + { "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 }, + { "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 }, { "format", "Output pixel format", OFFSET(output_format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS }, { "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 }, @@ -267,6 +272,7 @@ static int config_input(AVFilterLink *inlink) AVFilterContext *ctx = inlink->dst; VPPContext *vpp = ctx->priv; int ret; + int64_t ow, oh; if (vpp->framerate.den == 0 || vpp->framerate.num == 0) vpp->framerate = inlink->frame_rate; @@ -280,11 +286,38 @@ static int config_input(AVFilterLink *inlink) return ret; } - if (vpp->out_height == 0 || vpp->out_width == 0) { - vpp->out_width = inlink->w; - vpp->out_height = inlink->h; + ow = vpp->out_width; + oh = vpp->out_height; + + /* sanity check params */ + if (ow < -1 || oh < -1) { + av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n"); + return AVERROR(EINVAL); } + if (ow == -1 && oh == -1) + vpp->out_width = vpp->out_height = 0; + + if (!(ow = vpp->out_width)) + ow = inlink->w; + + if (!(oh = vpp->out_height)) + oh = inlink->h; + + if (ow == -1) + ow = av_rescale(oh, inlink->w, inlink->h); + + if (oh == -1) + oh = av_rescale(ow, inlink->h, inlink->w); + + if (ow > INT_MAX || oh > INT_MAX || + (oh * inlink->w) > INT_MAX || + (ow * inlink->h) > INT_MAX) + av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n"); + + vpp->out_width = ow; + vpp->out_height = oh; + if (vpp->use_crop) { vpp->crop_x = FFMAX(vpp->crop_x, 0); vpp->crop_y = FFMAX(vpp->crop_y, 0);