@@ -339,6 +339,21 @@ void BetaCudaDeviceInterface::initialize(
339339 parserParams.pfnDecodePicture = pfnDecodePictureCallback;
340340 parserParams.pfnDisplayPicture = pfnDisplayPictureCallback;
341341
342+ // Some containers (e.g. MP4/MOV) store codec config (H.264 SPS/PPS,
343+ // MPEG-4 VOS/VOL, etc.) in extradata rather than inline in the
344+ // bitstream. The NVCUVID parser needs this data to initialize, so we
345+ // pass it via pExtVideoInfo. Same approach as DALI and FFmpeg cuviddec.
346+ // DALI does the same thing
347+ // https://github.com/NVIDIA/DALI/blob/ae79f316ae9b14c464d9cb98465f7f783da9ea89/dali/operators/video/frames_decoder_gpu.cc#L402-L408
348+ if (codecPar->extradata_size > 0 ) {
349+ auto seqhdrSize = std::min (
350+ static_cast <size_t >(codecPar->extradata_size ),
351+ sizeof (parserExtInfo_.raw_seqhdr_data ));
352+ parserExtInfo_.format .seqhdr_data_length = seqhdrSize;
353+ memcpy (parserExtInfo_.raw_seqhdr_data , codecPar->extradata , seqhdrSize);
354+ parserParams.pExtVideoInfo = &parserExtInfo_;
355+ }
356+
342357 CUresult result = cuvidCreateVideoParser (&videoParser_, &parserParams);
343358 STD_TORCH_CHECK (
344359 result == CUDA_SUCCESS , " Failed to create video parser: " , result);
@@ -390,12 +405,6 @@ void BetaCudaDeviceInterface::initializeBSF(
390405 avFormatCtx->iformat ->name ? avFormatCtx->iformat ->name : " " ;
391406 if (formatName == " avi" ) {
392407 filterName = " mpeg4_unpack_bframes" ;
393- } else {
394- // For MPEG-4 Part 2 in MP4/MOV/etc., codec configuration (VOS/VOL)
395- // lives only in extradata. Unlike H.264/HEVC there's no codec-specific
396- // BSF that injects it inline, so use dump_extra to prepend extradata
397- // to keyframe packets — the NVCUVID parser needs this to initialize.
398- filterName = " dump_extra" ;
399408 }
400409 break ;
401410 }
0 commit comments