From patchwork Thu Jul 29 05:25:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 29109 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5d:965a:0:0:0:0:0 with SMTP id d26csp5500586ios; Wed, 28 Jul 2021 22:27:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUmtfrooea8LSknA83x13lTwntEMNy9jkLFy9khNdvVVju/2hby8x/l1ipNB3EGj8oAF0g X-Received: by 2002:a05:6402:49a:: with SMTP id k26mr3876455edv.279.1627536431111; Wed, 28 Jul 2021 22:27:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627536431; cv=none; d=google.com; s=arc-20160816; b=htwT9MYcdJZ2T5M6yH6OED1hEGaFl7yztj8YsWdAdMaxsgTL/vWY6lohSwkHFTdb7o HH94N5o3QDrS7tYXYq5ipd9wQUf8udjcYWMZjlSP8y9Sz2QtG5s3cSaRwj/d9z0MqpwI b7uZ/nJYB8M0v2taV1QnmziFiExJtdV0Ra6c1Tz9hgcEwUbTFD/VMqK8J12e5C/isyUO Mm7FTPrke9JIXMpAry+ccC5rKoX/VaziMvtupVFpNnUu1HaIXAh8kmjAk2IbmpEq21Lm WOJvpwIizkL+2uIW+NNVoac7+jHP2Uw8BHRQEqHvAXTOYKpD8g8zNNg/SoWmGsDCfW22 z6gw== 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=rLy/pM/wIlzvms0B3QnXMB8QADF3ccICMTVAmGAspG8=; b=vWssiE3CFk1I5CxK5LdcIBNb3ciwGScW9rnal0X6ww9ctPsZPqIOHzqhDI45r1QPgW 4V8EhCrJXpv7SSJvecgiDhg2cMTlVlyriIzGUf/3fJZf4ht9CmFb8Kg6Xa6Y9s1fEUOm /mS/iAY3U1N6E+4DhqXbmy8z+Ju4RnJu9iDmslSC3Q6axKUAq04vYf0CbASBoZ7u6kkG q8M3SwdBRyDzlOl/LxH2nr9zyD0LAr/YjYy5vmAcn9tUbol4JoZWbJv/Uwxy/SlTKyvt 4m24q9zw2If77TeErYQp+wuWIE1pJFc8Z5tHAsqrMxS1aJv+3btOa/oJCTAKpb6HOz/A Y5Ig== 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 da22si1756345edb.500.2021.07.28.22.27.10; Wed, 28 Jul 2021 22:27:11 -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 C0A5668A3E8; Thu, 29 Jul 2021 08:26:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9F4EC689D48 for ; Thu, 29 Jul 2021 08:26:13 +0300 (EEST) X-IronPort-AV: E=McAfee;i="6200,9189,10059"; a="210922207" X-IronPort-AV: E=Sophos;i="5.84,278,1620716400"; d="scan'208";a="210922207" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2021 22:26:04 -0700 X-IronPort-AV: E=Sophos;i="5.84,278,1620716400"; d="scan'208";a="456730166" Received: from xhh-dg164.sh.intel.com ([10.239.159.167]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2021 22:26:02 -0700 From: Haihao Xiang To: ffmpeg-devel@ffmpeg.org Date: Thu, 29 Jul 2021 13:25:03 +0800 Message-Id: <20210729052509.30992-16-haihao.xiang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210729052509.30992-1-haihao.xiang@intel.com> References: <20210729052509.30992-1-haihao.xiang@intel.com> Subject: [FFmpeg-devel] [PATCH v4 15/21] 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: NBCr1yNsfAlC 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 e16bd09585..b234417663 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 ?