From patchwork Tue Jun 15 06:13:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 28314 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp3527711iol; Mon, 14 Jun 2021 23:17:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz27Q46tVJuxVHoC/nKW7HKM6k2PW1WNxu3cZy7VEvyWVssQaIjT21K+M0e4Q6DGgmC/ujI X-Received: by 2002:a05:6402:511:: with SMTP id m17mr21067878edv.1.1623737842716; Mon, 14 Jun 2021 23:17:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623737842; cv=none; d=google.com; s=arc-20160816; b=n90WewJnFyaxVKBtAadVKsYE1ePe3xgUWer1degZ2aiyrkmTMEeSUZ9NMz24kjLUwD K3A2dq7BBH5zpxjEcebMnN21pPc+nZvPUopvYPFND24bvL/ZXRN10sYWY+nRWW/oenqb f7FZsFQlpM9yBJV4hOA7eui0cTOu7MNcMjWbNr4aSmnry37aVX8DxJNn4gWsRt3mWoyw rIAWfu2ADjYU+0KqGWDYWHbMDlKufL1Z/h9bcezcQn9byXDTeQkr6ZUvWQsUyZeQaX5v l8e0O3ADdGtrIy/8qRXnBaH6Y2Emmfz65NMG+ovTC71MIdvurywB/tmTGz4bbP4Z7qMp wNBA== 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=7ZRGYPUA2Ho1DX7z5A3NUAZau4IjfdinC/mCeFTf5/4=; b=InOqes+LiLiYfkkW2KWNpSnMw5fzNNZLw7HUOrFCpECY1TFd6yoJ9VkPs0v1OSzDSB XgP5Ya58LYY9pESsWKV5KUgAGkf36rhbkzwKojFWRyO27RlelnXpWcIE8/xwLP8C92eb 16ob2S2FBYYPgKM9ErsVe2Ul6wOfb05HPWmodAubKMlQw7NFnbXNup6LTUchBVZNyvvG feIAk9UKYS8FHDPtNGknfkH0YXRry/DkVjGxHiD0Zq4LFlAlP3yq6yVdh+pMnfVb53X7 T5NI00rOUmAQ7j+PK0bqgOolbPYCisM0NvC0M78xL88DKSAhW0hh+jG4oBrDiPrv9Ezu HnNg== 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 dn21si13653787edb.483.2021.06.14.23.17.22; Mon, 14 Jun 2021 23:17:22 -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 75C98689815; Tue, 15 Jun 2021 09:15:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 85526687FC5 for ; Tue, 15 Jun 2021 09:15:44 +0300 (EEST) IronPort-SDR: 6rgCxXqyHwu0syxA+L0Dhw7Di9Wcwn4C3LaAtVeM4Xxtz2v8Y9Ouwa2BRmGoOU7uQG2KUXuj9z 9KUNdYhARWgQ== X-IronPort-AV: E=McAfee;i="6200,9189,10015"; a="205750770" X-IronPort-AV: E=Sophos;i="5.83,275,1616482800"; d="scan'208";a="205750770" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2021 23:15:43 -0700 IronPort-SDR: am6XtHX2BLSPwMdjItXEPc/yE+5eAifrE5Wt2+kuUgqKQ0J/O8V+djIFD0zInWUR4GcaXPVkf5 boBEOLMklpvw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,275,1616482800"; d="scan'208";a="451857212" Received: from xhh-tgl64.sh.intel.com ([10.239.159.53]) by fmsmga008.fm.intel.com with ESMTP; 14 Jun 2021 23:15:42 -0700 From: Haihao Xiang To: ffmpeg-devel@ffmpeg.org Date: Tue, 15 Jun 2021 14:13:57 +0800 Message-Id: <20210615061403.1576282-17-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 16/22] 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Br3/fIlH+RiE 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 cde1acdbb0..cdf1f61b0f 100644 --- a/libavfilter/vf_vpp_qsv.c +++ b/libavfilter/vf_vpp_qsv.c @@ -371,6 +371,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 ?