From patchwork Mon Apr 22 17:26:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Svechnikov X-Patchwork-Id: 12865 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 9502E44914A for ; Mon, 22 Apr 2019 20:34:19 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7515268082E; Mon, 22 Apr 2019 20:34:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2A89968052F for ; Mon, 22 Apr 2019 20:34:13 +0300 (EEST) Received: by mail-lf1-f65.google.com with SMTP id t11so9525437lfl.12 for ; Mon, 22 Apr 2019 10:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=biYGgYw0WrULb42OVkx7cgEJSfTQBYVz1CfkwqLbqRE=; b=Sr1ClvOLRDC6E1YBaXi5cJrt2g+9kQAoCV/wLyxEpT8FOSkwjn91YuXtXQA0zh1aI2 xHkHMXunf2R5E4NcxtkWGf9UPNJBDbcnILAE39LPOi5wdl8kdGpx1yHCqmYKvRwrIW70 4IeKoymz+QLy55PXXsWljmsjaf8ENbWdF+pJ3Mmg4Bi2EVpbn/uQl03GuuM72BZ2d9S5 dNWBaWQEGaphcLqT2a4oJtxO8ZnIAmtTlVH7csqAc4Ku7uhOCfPJ9GHqADlWQrZhDrkj 4b992ZL1uDaA+hWAZjdSQXkwNE8RT167ee4+WpKvcTSlYTkEAl5Q6LaeBVJaSidjVC/f Lk/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=biYGgYw0WrULb42OVkx7cgEJSfTQBYVz1CfkwqLbqRE=; b=Y4AXodFouKrBu8jdpAQpaFaxyb+I2Q4JllWJDP7w9sTPaFLMFcV5PKbDVpn0Yt0FMC /zlTqOUNvV5Fqr60l4/owZ1eN+JinkhacPeFbdFRjPZeX+5GCl6xSl8c+p9O+SZ/tgNR XgaDdIH9VAFp0+BXL3+lGIzfT4pZrfvZo9HfUY9WrwKHmZcp93+iBypokH3+EMJfVNf9 Qv4N81FPrUUrkYUUbFzlItRhCcye7dCoxBDZb4ySpxQ1Yx0IAVws5YG5uOHQGYowA4ar Am8GjWI7QUUBNwDd/Zy+Kl4pxqJRrQ2ANmgEFRNNElFCeyUA+bL0ovE39OtP9SRa6bvK axuA== X-Gm-Message-State: APjAAAUPhDeAOcpPta0tEl5UP7gkaLdvpUvucAvJCfQ5EqN2E7GPHhzn 1Y7VkIrc37H0OdPUChDCHu7SQsYSs68= X-Google-Smtp-Source: APXvYqxzEDcMmlERRI43CwRxNiEZc8vfdap7pOVO4Ch/03p+BGCqE5NFnm2x//u3BQAWffYY74kC7w== X-Received: by 2002:a19:a5d4:: with SMTP id o203mr1861035lfe.40.1555953995083; Mon, 22 Apr 2019 10:26:35 -0700 (PDT) Received: from localhost.localdomain ([2a02:17d0:4a9:1800:867:6e7f:b0e9:492b]) by smtp.googlemail.com with ESMTPSA id v4sm2813603ljv.4.2019.04.22.10.26.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Apr 2019 10:26:34 -0700 (PDT) From: Sergey Svechnikov To: ffmpeg-devel@ffmpeg.org Date: Mon, 22 Apr 2019 22:26:24 +0500 Message-Id: <1555953984-25841-1-git-send-email-svechnikov66@gmail.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH] cuviddec: improved way of finding out if a frame is interlaced or progressive 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: Sergey Svechnikov MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" There are 2 types of problems when using adaptive deinterlace with cuvid: 1. Sometimes, in the middle of transcoding, cuvid outputs frames with visible horizontal lines (as though weave deinterlace method was chosen); 2. Occasionally, on scene changes, cuvid outputs a wrong frame, which should have been shown several seconds before (as if the frame was assigned some wrong PTS value). The reason is that sometimes CUVIDPARSERDISPINFO has property progressive_frame equal to 1 with interlaced videos. In order to fix the problem we should check if the video is interlaced or progressive in the beginning of a video sequence (cuvid_handle_video_sequence). And then we just use this information instead of the property progressive_frame in CUVIDPARSERDISPINFO (which is unreliable). More info, samples and reproduction steps are here https://github.com/Svechnikov/ffmpeg-cuda-deinterlace-problems --- libavcodec/cuviddec.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c index 2aecb45..671fc8c 100644 --- a/libavcodec/cuviddec.c +++ b/libavcodec/cuviddec.c @@ -77,6 +77,7 @@ typedef struct CuvidContext int deint_mode; int deint_mode_current; int64_t prev_pts; + unsigned char progressive_sequence; int internal_error; int decoder_flushing; @@ -216,6 +217,8 @@ static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form ? cudaVideoDeinterlaceMode_Weave : ctx->deint_mode; + ctx->progressive_sequence = format->progressive_sequence; + if (!format->progressive_sequence && ctx->deint_mode_current == cudaVideoDeinterlaceMode_Weave) avctx->flags |= AV_CODEC_FLAG_INTERLACED_DCT; else @@ -509,6 +512,8 @@ static int cuvid_output_frame(AVCodecContext *avctx, AVFrame *frame) av_fifo_generic_read(ctx->frame_queue, &parsed_frame, sizeof(CuvidParsedFrame), NULL); + parsed_frame.dispinfo.progressive_frame = ctx->progressive_sequence; + memset(¶ms, 0, sizeof(params)); params.progressive_frame = parsed_frame.dispinfo.progressive_frame; params.second_field = parsed_frame.second_field;