From patchwork Fri May 31 00:44:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhong Li X-Patchwork-Id: 13353 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 761EF447E7A for ; Fri, 31 May 2019 11:01:31 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 434D368A7D3; Fri, 31 May 2019 11:01:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0C38B68A57A for ; Fri, 31 May 2019 11:01:23 +0300 (EEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 May 2019 01:01:21 -0700 X-ExtLoop1: 1 Received: from blue-kbl.sh.intel.com ([10.239.13.16]) by fmsmga004.fm.intel.com with ESMTP; 31 May 2019 01:01:20 -0700 From: Zhong Li To: ffmpeg-devel@ffmpeg.org Date: Fri, 31 May 2019 08:44:47 +0800 Message-Id: <20190531004449.16987-1-zhong.li@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/3] lavf/qsv_vpp: add frame format option X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Zhong Li MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 1. Currently output format is hard-coded as NV12, thus means CSC is always done for not NV12 input such as P010. Follow original input format as default output. 2. Add an option to specify output format. Signed-off-by: Zhong Li --- libavfilter/vf_vpp_qsv.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c index 41a9f38962..39079a410b 100644 --- a/libavfilter/vf_vpp_qsv.c +++ b/libavfilter/vf_vpp_qsv.c @@ -57,6 +57,10 @@ typedef struct VPPContext{ int out_width; int out_height; + /** + * Output sw format. AV_PIX_FMT_NONE for no conversion. + */ + enum AVPixelFormat out_format; AVRational framerate; /* target framerate */ int use_frc; /* use framerate conversion */ @@ -79,6 +83,7 @@ typedef struct VPPContext{ char *cx, *cy, *cw, *ch; char *ow, *oh; + char *output_format_str; } VPPContext; static const AVOption options[] = { @@ -104,6 +109,8 @@ static const AVOption options[] = { { "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 }, + { "format", "Output pixel format", OFFSET(output_format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS }, + { NULL } }; @@ -207,6 +214,23 @@ release: return ret; } +static av_cold int vpp_init(AVFilterContext *ctx) +{ + VPPContext *vpp = ctx->priv; + + if (!strcmp(vpp->output_format_str, "same")) { + vpp->out_format = AV_PIX_FMT_NONE; + } else { + vpp->out_format = av_get_pix_fmt(vpp->output_format_str); + if (vpp->out_format == AV_PIX_FMT_NONE) { + av_log(ctx, AV_LOG_ERROR, "Unrecognized output pixel format: %s\n", vpp->output_format_str); + return AVERROR(EINVAL); + } + } + + return 0; +} + static int config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; @@ -251,6 +275,7 @@ static int config_output(AVFilterLink *outlink) QSVVPPCrop crop = { 0 }; mfxExtBuffer *ext_buf[ENH_FILTERS_COUNT]; AVFilterLink *inlink = ctx->inputs[0]; + enum AVPixelFormat in_format; outlink->w = vpp->out_width; outlink->h = vpp->out_height; @@ -258,10 +283,19 @@ static int config_output(AVFilterLink *outlink) outlink->time_base = av_inv_q(vpp->framerate); param.filter_frame = NULL; - param.out_sw_format = AV_PIX_FMT_NV12; param.num_ext_buf = 0; param.ext_buf = ext_buf; + if (inlink->format == AV_PIX_FMT_QSV) { + if (!inlink->hw_frames_ctx || !inlink->hw_frames_ctx->data) + return AVERROR(EINVAL); + else + in_format = ((AVHWFramesContext*)inlink->hw_frames_ctx->data)->sw_format; + } else + in_format = inlink->format; + + param.out_sw_format = (vpp->out_format == AV_PIX_FMT_NONE) ? in_format : vpp->out_format; + if (vpp->use_crop) { crop.in_idx = 0; crop.x = vpp->crop_x; @@ -421,6 +455,7 @@ AVFilter ff_vf_vpp_qsv = { .description = NULL_IF_CONFIG_SMALL("Quick Sync Video VPP."), .priv_size = sizeof(VPPContext), .query_formats = query_formats, + .init = vpp_init, .uninit = vpp_uninit, .inputs = vpp_inputs, .outputs = vpp_outputs,