diff mbox

[FFmpeg-devel] cuvid: don't overwrite deinterlace at progressive input

Message ID 58A09F9B.5030401@email.cz
State New
Headers show

Commit Message

Miroslav Slugeň Feb. 12, 2017, 5:47 p.m. UTC
If there is progressive input it will disable deinterlacing in cuvid for 
all future frames even those interlaced.

I suggest to backport this patch to stable, because deinterlacing of 
combined files (progressive+interlaced) is currently broken in cuvid.

Comments

Timo Rothenpieler Feb. 18, 2017, 12:27 p.m. UTC | #1
applied
diff mbox

Patch

From af263ad83ae555baa9cdab2f8b7c5f73ef51ff4d Mon Sep 17 00:00:00 2001
From: Miroslav Slugen <thunder.m@email.cz>
Date: Sun, 12 Feb 2017 18:44:10 +0100
Subject: [PATCH 1/1] cuvid: don't overwrite deinterlace at progressive input

---
 libavcodec/cuvid.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libavcodec/cuvid.c b/libavcodec/cuvid.c
index 9b35476..a99d7de 100644
--- a/libavcodec/cuvid.c
+++ b/libavcodec/cuvid.c
@@ -51,6 +51,7 @@  typedef struct CuvidContext
     AVFifoBuffer *frame_queue;
 
     int deint_mode;
+    int deint_mode_current;
     int64_t prev_pts;
 
     int internal_error;
@@ -150,7 +151,11 @@  static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form
         (AVRational){ format->display_aspect_ratio.x, format->display_aspect_ratio.y },
         (AVRational){ avctx->width, avctx->height }));
 
-    if (!format->progressive_sequence && ctx->deint_mode == cudaVideoDeinterlaceMode_Weave)
+    ctx->deint_mode_current = format->progressive_sequence
+                              ? cudaVideoDeinterlaceMode_Weave
+                              : ctx->deint_mode;
+
+    if (!format->progressive_sequence && ctx->deint_mode_current == cudaVideoDeinterlaceMode_Weave)
         avctx->flags |= AV_CODEC_FLAG_INTERLACED_DCT;
     else
         avctx->flags &= ~AV_CODEC_FLAG_INTERLACED_DCT;
@@ -241,14 +246,9 @@  static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form
     cuinfo.ulNumOutputSurfaces = 1;
     cuinfo.ulCreationFlags = cudaVideoCreate_PreferCUVID;
     cuinfo.bitDepthMinus8 = format->bit_depth_luma_minus8;
+    cuinfo.DeinterlaceMode = ctx->deint_mode_current;
 
-    if (format->progressive_sequence) {
-        ctx->deint_mode = cuinfo.DeinterlaceMode = cudaVideoDeinterlaceMode_Weave;
-    } else {
-        cuinfo.DeinterlaceMode = ctx->deint_mode;
-    }
-
-    if (ctx->deint_mode != cudaVideoDeinterlaceMode_Weave)
+    if (ctx->deint_mode_current != cudaVideoDeinterlaceMode_Weave)
         avctx->framerate = av_mul_q(avctx->framerate, (AVRational){2, 1});
 
     ctx->internal_error = CHECK_CU(ctx->cvdl->cuvidCreateDecoder(&ctx->cudecoder, &cuinfo));
@@ -293,7 +293,7 @@  static int CUDAAPI cuvid_handle_picture_display(void *opaque, CUVIDPARSERDISPINF
     parsed_frame.dispinfo = *dispinfo;
     ctx->internal_error = 0;
 
-    if (ctx->deint_mode == cudaVideoDeinterlaceMode_Weave) {
+    if (ctx->deint_mode_current == cudaVideoDeinterlaceMode_Weave) {
         av_fifo_generic_write(ctx->frame_queue, &parsed_frame, sizeof(CuvidParsedFrame), NULL);
     } else {
         parsed_frame.is_deinterlacing = 1;
@@ -564,7 +564,7 @@  static int cuvid_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
 
     av_log(avctx, AV_LOG_TRACE, "cuvid_decode_frame\n");
 
-    if (ctx->deint_mode != cudaVideoDeinterlaceMode_Weave) {
+    if (ctx->deint_mode_current != cudaVideoDeinterlaceMode_Weave) {
         av_log(avctx, AV_LOG_ERROR, "Deinterlacing is not supported via the old API\n");
         return AVERROR(EINVAL);
     }
-- 
2.1.4