[FFmpeg-devel] cuvid: add drop_second_field as input option v2

Submitted by Miroslav Slugeň on Feb. 12, 2017, 8:22 p.m.

Details

Message ID 58A0C416.207@email.cz
State New
Headers show

Commit Message

Miroslav Slugeň Feb. 12, 2017, 8:22 p.m.
Add drop_second_field for CUVID input. It is not enabled by default this 
time and will fix reporting correct frame_rate

Comments

Timo Rothenpieler Feb. 18, 2017, 12:27 p.m.
applied

Patch hide | download patch | download mbox

From c5277c84eba2b1f7b6ee92cf7cb4a2df23a9b536 Mon Sep 17 00:00:00 2001
From: Miroslav Slugen <thunder.m@email.cz>
Date: Sun, 12 Feb 2017 21:20:56 +0100
Subject: [PATCH 1/1] cuvid: add drop_second_field as input option v2

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

diff --git a/libavcodec/cuvid.c b/libavcodec/cuvid.c
index 9b35476..a90552b 100644
--- a/libavcodec/cuvid.c
+++ b/libavcodec/cuvid.c
@@ -42,6 +42,7 @@  typedef struct CuvidContext
 
     char *cu_gpu;
     int nb_surfaces;
+    int drop_second_field;
 
     AVBufferRef *hwdevice;
     AVBufferRef *hwframe;
@@ -248,7 +249,7 @@  static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form
         cuinfo.DeinterlaceMode = ctx->deint_mode;
     }
 
-    if (ctx->deint_mode != cudaVideoDeinterlaceMode_Weave)
+    if (ctx->deint_mode != cudaVideoDeinterlaceMode_Weave && !ctx->drop_second_field)
         avctx->framerate = av_mul_q(avctx->framerate, (AVRational){2, 1});
 
     ctx->internal_error = CHECK_CU(ctx->cvdl->cuvidCreateDecoder(&ctx->cudecoder, &cuinfo));
@@ -298,8 +299,10 @@  static int CUDAAPI cuvid_handle_picture_display(void *opaque, CUVIDPARSERDISPINF
     } else {
         parsed_frame.is_deinterlacing = 1;
         av_fifo_generic_write(ctx->frame_queue, &parsed_frame, sizeof(CuvidParsedFrame), NULL);
-        parsed_frame.second_field = 1;
-        av_fifo_generic_write(ctx->frame_queue, &parsed_frame, sizeof(CuvidParsedFrame), NULL);
+        if (!ctx->drop_second_field) {
+            parsed_frame.second_field = 1;
+            av_fifo_generic_write(ctx->frame_queue, &parsed_frame, sizeof(CuvidParsedFrame), NULL);
+        }
     }
 
     return 1;
@@ -930,6 +933,7 @@  static const AVOption options[] = {
     { "adaptive", "Adaptive deinterlacing",                  0, AV_OPT_TYPE_CONST, { .i64 = cudaVideoDeinterlaceMode_Adaptive }, 0, 0, VD, "deint" },
     { "gpu",      "GPU to be used for decoding", OFFSET(cu_gpu), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VD },
     { "surfaces", "Maximum surfaces to be used for decoding", OFFSET(nb_surfaces), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, INT_MAX, VD },
+    { "drop_second_field", "Drop second field when deinterlacing", OFFSET(drop_second_field), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
     { NULL }
 };
 
-- 
2.1.4