From patchwork Mon Jan 9 07:12:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 39931 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp2884161pzb; Sun, 8 Jan 2023 23:13:01 -0800 (PST) X-Google-Smtp-Source: AMrXdXuO8n+HvHfy541SMTYO2BbS314MgFI7B2MnRdUzpdUwwJwHgXrO8mZx4pVci+XNACf+dvuy X-Received: by 2002:a17:907:a705:b0:7bd:ece7:ae66 with SMTP id vw5-20020a170907a70500b007bdece7ae66mr59823054ejc.34.1673248380925; Sun, 08 Jan 2023 23:13:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673248380; cv=none; d=google.com; s=arc-20160816; b=C7RvTITRE1b5xWS6n/dqSTtmh0P8JsT1A6dDoOR5i5GT0uiwq4zfgD/YCQGZJk8rGV JZGV/OO9EY+eFg5wfA//hMDPrvE5dA2CaXSpKNZqJYNFm2HsqQTcw1K/JANg5ucyfHhd 8tAPNV1nYwpBC+qJOyaFiX+GI5tWS0atRvMfx1ARxnDeXL2CCLwKOQKftmbj34Au7nJp p4gYxFuP5thNaj5AUWGFicd3RlAKoeG48dXDSHddyKzHHMAY06rQcQhRIHn2YcR7CPfs FGmu4UF0rdkIoWwt9VqVOAxj7ZroHt6nYilgcuFPsGoZYEGs7bc+qf/5wCRMOYj19I3Z /uEA== 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:dkim-signature:delivered-to; bh=Pj3qcov0qmMZwZTQ7Z8fTg6KqPIdHyxQy7xx7tNQEJU=; b=baPqkQis4ViwAzekRtrFzuS4tvw42lNkbZXMUPqCXq0II5O6MoMRADOp1hOqx9KixC vpaF4szPdOQ59kaf29gmmzXwRjQlm05u+zjH2tlWxMmiZw6neceM/1wZi2o2bS0uomnx 4c1oUfKEr5uEJrd41dT0IzLMo0DOj3Pd2USoW2PX2JBqJDfZ6FwGPZ9qa0tPtbVKDN9e S27n1rUeQ+BbFrodXK+IP61ocEm9bXDJctTq+7/02QqOPX2Uy3GH0L12wqJCPBE6qFvb vM5wKEWWMv1fOfXflo1/YuIwTg57rRdQE0rbyB5pgcaxHR8v7b7HDaFkmUPsQRsFKh/I DnVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=mzJmqHks; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ht17-20020a170907609100b007adfe2889efsi8573106ejc.607.2023.01.08.23.13.00; Sun, 08 Jan 2023 23:13:00 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=mzJmqHks; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DDF1B68BA83; Mon, 9 Jan 2023 09:12:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3B5BC68B9F1 for ; Mon, 9 Jan 2023 09:12:33 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673248358; x=1704784358; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=15uv8NhLMm3Kx8Ynpn5SDjMlcnzFt1yo/MxRtvP6yyM=; b=mzJmqHkslOxSg/hGGd506vukjSWhpzYJOGnfEqwAUahKb9kXx+mzhG3d wx61xKnzUMI17F1JtaVHZjlUGdqU3MEIOOGCuTw3PGo0mtm2R7O/8RV68 d5pZGaFsGli35Aw6s/5Uu8IN24wusBJxm7att3HqOEI6w3Ze4PoRxKiTT SWv51Qt9/av1trPP3DIhDUOqTR/VrRtIi59cBK5qmLIB+t4mhHmgPeqGS JdKwzbkcwQgEmV+Ss6bm95g+RaF05DsjHeGE6h6IQivBk6NlhKgg80QQn 8HlcZUCaT/ftk9VB8IjY9xhCg8QvOaACWmOMMHDGidK36hwrrvhlpDtMV g==; X-IronPort-AV: E=McAfee;i="6500,9779,10584"; a="385110841" X-IronPort-AV: E=Sophos;i="5.96,311,1665471600"; d="scan'208";a="385110841" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jan 2023 23:12:28 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10584"; a="745262796" X-IronPort-AV: E=Sophos;i="5.96,311,1665471600"; d="scan'208";a="745262796" Received: from xhh-tgl64.sh.intel.com ([10.238.2.19]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jan 2023 23:12:27 -0800 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Mon, 9 Jan 2023 15:12:05 +0800 Message-Id: <20230109071210.1829699-3-haihao.xiang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230109071210.1829699-1-haihao.xiang@intel.com> References: <20230109071210.1829699-1-haihao.xiang@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/8] lavfi/vf_vpp_qsv: allow special values for the output video 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: DwCFr3Z0BU31 From: Haihao Xiang Special values are: 0 = original width/height -1 = keep original aspect This is in preparation for reusing the code for other QSV filters. Signed-off-by: Haihao Xiang --- 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 3a0a395732..cf11cd7fdc 100644 --- a/libavfilter/vf_vpp_qsv.c +++ b/libavfilter/vf_vpp_qsv.c @@ -59,6 +59,11 @@ typedef struct VPPContext{ mfxExtVPPMirroring mirroring_conf; mfxExtVPPScaling scale_conf; + /** + * New dimensions. Special values are: + * 0 = original width/height + * -1 = keep original aspect + */ int out_width; int out_height; /** @@ -127,10 +132,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(async_depth), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, .flags = FLAGS }, { "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) 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; @@ -289,11 +295,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);