@@ -57,22 +57,53 @@ void cv::cudacodec::detail::VideoDecoder::create(const FormatInfo& videoFormat)
57
57
cudaVideoCreate_PreferCUVID;
58
58
59
59
// Validate video format. These are the currently supported formats via NVCUVID
60
- CV_Assert (cudaVideoCodec_MPEG1 == _codec ||
61
- cudaVideoCodec_MPEG2 == _codec ||
62
- cudaVideoCodec_MPEG4 == _codec ||
63
- cudaVideoCodec_VC1 == _codec ||
64
- cudaVideoCodec_H264 == _codec ||
65
- cudaVideoCodec_JPEG == _codec ||
66
- cudaVideoCodec_YUV420== _codec ||
67
- cudaVideoCodec_YV12 == _codec ||
68
- cudaVideoCodec_NV12 == _codec ||
69
- cudaVideoCodec_YUYV == _codec ||
70
- cudaVideoCodec_UYVY == _codec );
71
-
72
- CV_Assert (cudaVideoChromaFormat_Monochrome == _chromaFormat ||
73
- cudaVideoChromaFormat_420 == _chromaFormat ||
74
- cudaVideoChromaFormat_422 == _chromaFormat ||
75
- cudaVideoChromaFormat_444 == _chromaFormat);
60
+ bool codecSupported = cudaVideoCodec_MPEG1 == _codec ||
61
+ cudaVideoCodec_MPEG2 == _codec ||
62
+ cudaVideoCodec_MPEG4 == _codec ||
63
+ cudaVideoCodec_VC1 == _codec ||
64
+ cudaVideoCodec_H264 == _codec ||
65
+ cudaVideoCodec_JPEG == _codec ||
66
+ cudaVideoCodec_H264_SVC == _codec ||
67
+ cudaVideoCodec_H264_MVC == _codec ||
68
+ cudaVideoCodec_YV12 == _codec ||
69
+ cudaVideoCodec_NV12 == _codec ||
70
+ cudaVideoCodec_YUYV == _codec ||
71
+ cudaVideoCodec_UYVY == _codec;
72
+
73
+ #if defined (HAVE_CUDA)
74
+ #if (CUDART_VERSION >= 6500)
75
+ codecSupported |= cudaVideoCodec_HEVC == _codec;
76
+ #endif
77
+ #if ((CUDART_VERSION == 7500) || (CUDART_VERSION >= 9000))
78
+ codecSupported |= cudaVideoCodec_VP8 == _codec ||
79
+ cudaVideoCodec_VP9 == _codec ||
80
+ cudaVideoCodec_YUV420 == _codec;
81
+ #endif
82
+ #endif
83
+
84
+ CV_Assert (codecSupported);
85
+ CV_Assert ( cudaVideoChromaFormat_Monochrome == _chromaFormat ||
86
+ cudaVideoChromaFormat_420 == _chromaFormat ||
87
+ cudaVideoChromaFormat_422 == _chromaFormat ||
88
+ cudaVideoChromaFormat_444 == _chromaFormat);
89
+
90
+ #if (CUDART_VERSION >= 9000)
91
+ // Check video format is supported by GPU's hardware video decoder
92
+ if (videoFormat.nBitDepthMinus8 != -1 ) { // info not available call to create CuvidVideoSource() failed
93
+ CUVIDDECODECAPS decodeCaps = {};
94
+ decodeCaps.eCodecType = _codec;
95
+ decodeCaps.eChromaFormat = _chromaFormat;
96
+ decodeCaps.nBitDepthMinus8 = videoFormat.nBitDepthMinus8 ;
97
+ cuSafeCall (cuvidGetDecoderCaps (&decodeCaps));
98
+ if (!decodeCaps.bIsSupported )
99
+ CV_Error (Error::StsUnsupportedFormat, " Video source is not supported by hardware video decoder" );
100
+
101
+ CV_Assert (videoFormat.width >= decodeCaps.nMinWidth &&
102
+ videoFormat.height >= decodeCaps.nMinHeight &&
103
+ videoFormat.width <= decodeCaps.nMaxWidth &&
104
+ videoFormat.height <= decodeCaps.nMaxHeight );
105
+ }
106
+ #endif
76
107
77
108
// Fill the decoder-create-info struct from the given video-format struct.
78
109
std::memset (&createInfo_, 0 , sizeof (CUVIDDECODECREATEINFO));
0 commit comments