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).
Unified · Split
| @@ -77,6 +77,7 @@ typedef struct CuvidContext · 76 unmodified lines | |||
| 77 | int deint_mode; | 77 | int deint_mode; |
| 78 | int deint_mode_current; | 78 | int deint_mode_current; |
| 79 | int64_t prev_pts; | 79 | int64_t prev_pts; |
| 80 | int progressive_sequence; | ||
| 80 | 81 | ||
| 81 | int internal_error; | 82 | int internal_error; |
| 82 | int decoder_flushing; | 83 | int decoder_flushing; |
| @@ -216,6 +217,8 @@ static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form · 133 unmodified lines | |||
| 216 | ? cudaVideoDeinterlaceMode_Weave | 217 | ? cudaVideoDeinterlaceMode_Weave |
| 217 | : ctx->deint_mode; | 218 | : ctx->deint_mode; |
| 218 | 219 | ||
| 220 | ctx->progressive_sequence = format->progressive_sequence; | ||
| 221 | |||
| 219 | if (!format->progressive_sequence && ctx->deint_mode_current == cudaVideoDeinterlaceMode_Weave) | 222 | if (!format->progressive_sequence && ctx->deint_mode_current == cudaVideoDeinterlaceMode_Weave) |
| 220 | avctx->flags |= AV_CODEC_FLAG_INTERLACED_DCT; | 223 | avctx->flags |= AV_CODEC_FLAG_INTERLACED_DCT; |
| 221 | else | 224 | else |
| @@ -349,6 +352,9 @@ static int CUDAAPI cuvid_handle_picture_display(void *opaque, CUVIDPARSERDISPINF · 127 unmodified lines | |||
| 349 | parsed_frame.dispinfo = *dispinfo; | 352 | parsed_frame.dispinfo = *dispinfo; |
| 350 | ctx->internal_error = 0; | 353 | ctx->internal_error = 0; |
| 351 | 354 | ||
| 355 | // For some reason, dispinfo->progressive_frame is sometimes wrong. | ||
| 356 | parsed_frame.dispinfo.progressive_frame = ctx->progressive_sequence; | ||
| 357 | |||
| 352 | if (ctx->deint_mode_current == cudaVideoDeinterlaceMode_Weave) { | 358 | if (ctx->deint_mode_current == cudaVideoDeinterlaceMode_Weave) { |
| 353 | av_fifo_generic_write(ctx->frame_queue, &parsed_frame, sizeof(CuvidParsedFrame), NULL); | 359 | av_fifo_generic_write(ctx->frame_queue, &parsed_frame, sizeof(CuvidParsedFrame), NULL); |
| 354 | } else { | 360 | } else { |