From patchwork Thu Aug 5 08:19:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 29269 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6c0f:0:0:0:0:0 with SMTP id a15csp191746ioh; Thu, 5 Aug 2021 01:24:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5y3ygNRKYwqyzuKn8iy9RNgGTZ0YF3pNTUpfuDTEQHz0zHg6v7aVx63kf4uAhQ5Z4+kDm X-Received: by 2002:a17:906:839a:: with SMTP id p26mr3639136ejx.547.1628151848127; Thu, 05 Aug 2021 01:24:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628151848; cv=none; d=google.com; s=arc-20160816; b=LZHLSuzX+W1F9jgWe9guIZGJKMorXtbJmvpbnkysXtEj8sdCXKknHBIfgcLfaLsQ5N 9dyu7iAzJQevya8w6DIhzwKuHBRV7Ps0YC/V0pGTVuvgsYO71wjA0JKYMTwYL9fz2E++ 1JWL/dNgxfOD9c40/bpWs2LwUH0AMajIFWFTDxnI1DAEyaJlvV18ijPqaN/mpAsdtNpJ L5jMWBBeLbJUA+39qSZRlVTnPp0hPl8VGqJB7pHeuNndUortqAevKxJ44sVrabLPe4uH k+Suu1/t3wzYPFq032xUqteS3WqLoWXftNBFh9xrWCpB2/b3/fXUDNSj6xSAkVtwaWty n97w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=cXxTFokvW0L3/SgTqyNFQpyXLYIVhmR76I+qAY3pcLc=; b=SYTwA+YsocQnpJOCaIY1BoHVexBNanUbZQj5/Wt5O3RDJtvMKYO7W/oKP8ypHB70RL xI4E6ssSF6OwPJcJQP/oCLp9rd5mIPMqGaDqSlD4BP5jkDV5fbWOEhWt3dDhPStq2t0/ jrFitqgc4GVXB+PbLSKFhnVnmlxm7Uonq7aOX9fPid7eTqkgn2Y6Sjkowh6P/PIJduym upxOx1MdcYZ3NBUmL4JyE74sTk9sapAJtiTnc8hbh+TwHOXQbJBqCyPlujLbMRxMAqWM uCVPwbvMkz8cguKYY9G6BJjERWdb/P7pav5k/y09P/N5mFF040rACWMYQOiqmZU+DHMD aK4w== 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 ga26si4946861ejb.30.2021.08.05.01.24.07; Thu, 05 Aug 2021 01:24:08 -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 86AF168A59A; Thu, 5 Aug 2021 11:21:37 +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 D96B668A4D2 for ; Thu, 5 Aug 2021 11:21:30 +0300 (EEST) X-IronPort-AV: E=McAfee;i="6200,9189,10066"; a="236062060" X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="236062060" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Aug 2021 01:19:55 -0700 X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="522442428" Received: from xhh-dg164.sh.intel.com ([10.239.159.167]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Aug 2021 01:19:54 -0700 From: Haihao Xiang To: ffmpeg-devel@ffmpeg.org Date: Thu, 5 Aug 2021 16:19:05 +0800 Message-Id: <20210805081910.9386-16-haihao.xiang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210805081910.9386-1-haihao.xiang@intel.com> References: <20210805081910.9386-1-haihao.xiang@intel.com> Subject: [FFmpeg-devel] [PATCH v5 15/20] lavfi/qsvvpp: set PTS for output frame 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 4gM9grelwe/f When the SDK returns MFX_ERR_MORE_SURFACE, the PTS is not set for the output frame. We assign a PTS calculated from the input frame to the output frame. After applying this patch, we may avoid the error below: [null @ 0x56395cab4ae0] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 456 >= 0 Note this patch only fixes PTS issue when deinterlacing is enabled --- libavfilter/qsvvpp.c | 21 +++++++++++++++++++-- libavfilter/qsvvpp.h | 3 +++ libavfilter/vf_vpp_qsv.c | 2 ++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c index 82a8e29387..01d9d754d3 100644 --- a/libavfilter/qsvvpp.c +++ b/libavfilter/qsvvpp.c @@ -653,6 +653,7 @@ int ff_qsvvpp_init(AVFilterContext *avctx, QSVVPPParam *param) int ret; QSVVPPContext *s = avctx->priv; + s->last_in_pts = AV_NOPTS_VALUE; s->filter_frame = param->filter_frame; if (!s->filter_frame) s->filter_frame = ff_filter_frame; @@ -769,6 +770,8 @@ int ff_qsvvpp_close(AVFilterContext *avctx) s->session = NULL; } + s->last_in_pts = AV_NOPTS_VALUE; + /* release all the resources */ clear_frame_list(&s->in_frame_list); clear_frame_list(&s->out_frame_list); @@ -788,6 +791,7 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr mfxSyncPoint sync; QSVFrame *in_frame, *out_frame, *tmp; int ret, ret1, filter_ret; + int64_t dpts = 0; while (s->eof && qsv_fifo_size(s->async_fifo)) { av_fifo_generic_read(s->async_fifo, &tmp, sizeof(tmp), NULL); @@ -836,8 +840,19 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr ret = AVERROR(EAGAIN); break; } - out_frame->frame->pts = av_rescale_q(out_frame->surface.Data.TimeStamp, - default_tb, outlink->time_base); + + /* TODO: calculate the PTS for other cases */ + if (s->deinterlace_enabled && + s->last_in_pts != AV_NOPTS_VALUE && + ret == MFX_ERR_MORE_SURFACE && + out_frame->surface.Data.TimeStamp == MFX_TIMESTAMP_UNKNOWN) + dpts = (in_frame->frame->pts - s->last_in_pts) / 2; + else + dpts = 0; + + out_frame->frame->pts = av_rescale_q(in_frame->frame->pts - dpts, + inlink->time_base, + outlink->time_base); out_frame->queued++; av_fifo_generic_write(s->async_fifo, &out_frame, sizeof(out_frame), NULL); @@ -870,5 +885,7 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr } } while(ret == MFX_ERR_MORE_SURFACE); + s->last_in_pts = in_frame->frame->pts; + return ret; } diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h index b6fe0d3fa7..8627c8c868 100644 --- a/libavfilter/qsvvpp.h +++ b/libavfilter/qsvvpp.h @@ -74,8 +74,11 @@ typedef struct QSVVPPContext { int got_frame; int async_depth; int eof; + int deinterlace_enabled; /** order with frame_out, sync */ AVFifoBuffer *async_fifo; + + int64_t last_in_pts; } QSVVPPContext; typedef struct QSVVPPCrop { diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c index c642d4e2a4..3eddefea31 100644 --- a/libavfilter/vf_vpp_qsv.c +++ b/libavfilter/vf_vpp_qsv.c @@ -364,6 +364,8 @@ static int config_output(AVFilterLink *outlink) vpp->extbuf.field = value; \ } while (0) + vpp->qsv.deinterlace_enabled = !!vpp->deinterlace; + if (vpp->deinterlace) { INIT_MFX_EXTBUF(deinterlace_conf, MFX_EXTBUFF_VPP_DEINTERLACING); SET_MFX_PARAM_FIELD(deinterlace_conf, Mode, (vpp->deinterlace == 1 ?