diff mbox series

[FFmpeg-devel] BugFix #9283: correct setting of key_frame flag in AVFrame using cuviddec on interlaced h264

Message ID 20210611102730.21613-1-miro.stuhl@comprimato.com
State New
Headers show
Series [FFmpeg-devel] BugFix #9283: correct setting of key_frame flag in AVFrame using cuviddec on interlaced h264 | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

stuhlo June 11, 2021, 10:27 a.m. UTC
From: stuhlo <stuhlo@gmail.com>

This fixes setting of `key_frame` flag in AVFrame when input h264 packets represents individual fields of interlaced video.
In this case, pairs of two consecutive fields represents a single decoded picture and have identical `CurrPicIdx`, however, only
the first field is entirely intra-coded and has the flag `intra_pic_flag` set and the second field was resetting the flag before
it was even read in the function `cuvid_output_frame`.
---
 libavcodec/cuviddec.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Timo Rothenpieler June 11, 2021, 2:46 p.m. UTC | #1
On 11.06.2021 12:27, stuhlo wrote:
> From: stuhlo <stuhlo@gmail.com>
> 
> This fixes setting of `key_frame` flag in AVFrame when input h264 packets represents individual fields of interlaced video.
> In this case, pairs of two consecutive fields represents a single decoded picture and have identical `CurrPicIdx`, however, only
> the first field is entirely intra-coded and has the flag `intra_pic_flag` set and the second field was resetting the flag before
> it was even read in the function `cuvid_output_frame`.


Looks good to me, but please use proper commit messages in the future.
You can look at other commit messages for the general format.

Will test and apply with fixed message.
diff mbox series

Patch

diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index a5f33e6..f1cc9aa 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -336,7 +336,9 @@  static int CUDAAPI cuvid_handle_picture_decode(void *opaque, CUVIDPICPARAMS* pic
 
     av_log(avctx, AV_LOG_TRACE, "pfnDecodePicture\n");
 
-    ctx->key_frame[picparams->CurrPicIdx] = picparams->intra_pic_flag;
+    if(picparams->intra_pic_flag) {
+        ctx->key_frame[picparams->CurrPicIdx] = picparams->intra_pic_flag;
+    }
 
     ctx->internal_error = CHECK_CU(ctx->cvdl->cuvidDecodePicture(ctx->cudecoder, picparams));
     if (ctx->internal_error < 0)
@@ -593,6 +595,7 @@  static int cuvid_output_frame(AVCodecContext *avctx, AVFrame *frame)
         }
 
         frame->key_frame = ctx->key_frame[parsed_frame.dispinfo.picture_index];
+        ctx->key_frame[parsed_frame.dispinfo.picture_index] = 0;
         frame->width = avctx->width;
         frame->height = avctx->height;
         if (avctx->pkt_timebase.num && avctx->pkt_timebase.den)