a-3.ts (3.9 MB)
The 147th frame (starting as 0) of the H264 bitstream in the file a-3.ts cannot be output correctly.
This frame PTS of 440287 and no B frame. It is a code stream output by an unknown encoder. My customer told me that using soft decoding can record all images, but using NVDec cannot record all images.
The Computer Info:
System
OsName: Microsoft Windows 11
GPU
NVIDIA RTX A4000
Diver: 31.0.15.2667
Date: 2022/11/2
DirectX : 12 (FL 12.1)
CPU
Intel(R) Core™ i7-7820X CPU @ 3.60GHz
I use cuvidParseVideoData and cuvidDecodePicture to decode video sequences. Print frame information when decoding output:
int HandlePictureDisplay(CUVIDPARSERDISPINFO *pDispInfo)
{
CUVIDPROCPARAMS videoProcessingParameters = {};
videoProcessingParameters.progressive_frame = pDispInfo->progressive_frame;
videoProcessingParameters.second_field = pDispInfo->repeat_first_field + 1;
videoProcessingParameters.top_field_first = pDispInfo->top_field_first;
videoProcessingParameters.unpaired_field = pDispInfo->repeat_first_field < 0;
videoProcessingParameters.output_stream = m_cuvidStream;
CUdeviceptr dpSrcFrame = 0;
unsigned int nSrcPitch = 0;
CUDAAPI_CALL_CHECK(cuCtxPushCurrent(m_cuContext));
CUDAAPI_CALL_CHECK(cuvidMapVideoFrame(m_hDecoder, pDispInfo->picture_index, &dpSrcFrame, &nSrcPitch, &videoProcessingParameters));
CUVIDGETDECODESTATUS DecodeStatus;
memset(&DecodeStatus, 0, sizeof(DecodeStatus));
CUDAAPI_CALL_CHECK(cuvidGetDecodeStatus(m_hDecoder, pDispInfo->picture_index, &DecodeStatus));
printf("pts=%lld picture_index=%d status=%d \r\n", pDispInfo->timestamp, pDispInfo->picture_index, DecodeStatus.decodeStatus);
CUDAAPI_CALL_CHECK(cuvidUnmapVideoFrame(m_hDecoder, dpSrcFrame));
return 1;
}
440287 is not outputting correctly and has been delayed for a long time before outputting:
pts=433087 picture_index=3 status=9
pts=434887 picture_index=4 status=9
pts=436687 picture_index=0 status=2
pts=438487 picture_index=1 status=2
...
pts=528487 picture_index=1 status=2
pts=530287 picture_index=0 status=2
pts=440287 picture_index=2 status=2
I also tried using CUVID to decode a-3.ts (ffmpeg -c:v h264_cuvid -i C:\a-3.ts -f mpegts C:\a-3-nvdec.ts
) in FFmpeg, and the video can only output 468 frames; Try using NVDEC(ffmpeg -hwaccel nvdec -i C:\a-3.ts -f mpegts C:\a-3-nvdec.ts
) and soft decoding to output a complete 471 frames. The main difference between them is that NVDEC does not use cuvidParseVideoData.
I think this is probably a problem with the parsing of the Video Codec SDK bitstream, or there are some fields on the code stream that are incompatible with the SDK.