Commit afad1029 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #2146 from cudawarped:update_codecs_nvcuvid

parents 74ea5dec 66aba496
......@@ -250,6 +250,9 @@ enum Codec
JPEG,
H264_SVC,
H264_MVC,
HEVC,
VP8,
VP9,
Uncompressed_YUV420 = (('I'<<24)|('Y'<<16)|('U'<<8)|('V')), //!< Y,U,V (4:2:0)
Uncompressed_YV12 = (('Y'<<24)|('V'<<16)|('1'<<8)|('2')), //!< Y,V,U (4:2:0)
......@@ -274,6 +277,7 @@ struct FormatInfo
{
Codec codec;
ChromaFormat chromaFormat;
int nBitDepthMinus8;
int width;
int height;
};
......
......@@ -51,7 +51,7 @@ DEF_PARAM_TEST_1(FileName, string);
//////////////////////////////////////////////////////
// VideoReader
#if defined(HAVE_NVCUVID) && defined(HAVE_VIDEO_INPUT)
#if defined(HAVE_NVCUVID)
PERF_TEST_P(FileName, VideoReader, Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"))
{
......
......@@ -70,6 +70,7 @@ cv::cudacodec::detail::CuvidVideoSource::CuvidVideoSource(const String& fname)
format_.codec = static_cast<Codec>(vidfmt.codec);
format_.chromaFormat = static_cast<ChromaFormat>(vidfmt.chroma_format);
format_.nBitDepthMinus8 = vidfmt.bit_depth_luma_minus8;
format_.width = vidfmt.coded_width;
format_.height = vidfmt.coded_height;
}
......
......@@ -111,6 +111,7 @@ cv::cudacodec::detail::FFmpegVideoSource::FFmpegVideoSource(const String& fname)
format_.codec = static_cast<Codec>(codec);
format_.chromaFormat = static_cast<ChromaFormat>(chroma_format);
format_.nBitDepthMinus8 = -1;
format_.width = width;
format_.height = height;
}
......
......@@ -57,22 +57,53 @@ void cv::cudacodec::detail::VideoDecoder::create(const FormatInfo& videoFormat)
cudaVideoCreate_PreferCUVID;
// Validate video format. These are the currently supported formats via NVCUVID
CV_Assert(cudaVideoCodec_MPEG1 == _codec ||
cudaVideoCodec_MPEG2 == _codec ||
cudaVideoCodec_MPEG4 == _codec ||
cudaVideoCodec_VC1 == _codec ||
cudaVideoCodec_H264 == _codec ||
cudaVideoCodec_JPEG == _codec ||
cudaVideoCodec_YUV420== _codec ||
cudaVideoCodec_YV12 == _codec ||
cudaVideoCodec_NV12 == _codec ||
cudaVideoCodec_YUYV == _codec ||
cudaVideoCodec_UYVY == _codec );
CV_Assert(cudaVideoChromaFormat_Monochrome == _chromaFormat ||
cudaVideoChromaFormat_420 == _chromaFormat ||
cudaVideoChromaFormat_422 == _chromaFormat ||
cudaVideoChromaFormat_444 == _chromaFormat);
bool codecSupported = cudaVideoCodec_MPEG1 == _codec ||
cudaVideoCodec_MPEG2 == _codec ||
cudaVideoCodec_MPEG4 == _codec ||
cudaVideoCodec_VC1 == _codec ||
cudaVideoCodec_H264 == _codec ||
cudaVideoCodec_JPEG == _codec ||
cudaVideoCodec_H264_SVC == _codec ||
cudaVideoCodec_H264_MVC == _codec ||
cudaVideoCodec_YV12 == _codec ||
cudaVideoCodec_NV12 == _codec ||
cudaVideoCodec_YUYV == _codec ||
cudaVideoCodec_UYVY == _codec;
#if defined (HAVE_CUDA)
#if (CUDART_VERSION >= 6500)
codecSupported |= cudaVideoCodec_HEVC == _codec;
#endif
#if ((CUDART_VERSION == 7500) || (CUDART_VERSION >= 9000))
codecSupported |= cudaVideoCodec_VP8 == _codec ||
cudaVideoCodec_VP9 == _codec ||
cudaVideoCodec_YUV420 == _codec;
#endif
#endif
CV_Assert(codecSupported);
CV_Assert( cudaVideoChromaFormat_Monochrome == _chromaFormat ||
cudaVideoChromaFormat_420 == _chromaFormat ||
cudaVideoChromaFormat_422 == _chromaFormat ||
cudaVideoChromaFormat_444 == _chromaFormat);
#if (CUDART_VERSION >= 9000)
// Check video format is supported by GPU's hardware video decoder
if (videoFormat.nBitDepthMinus8 != -1) { // info not available call to create CuvidVideoSource() failed
CUVIDDECODECAPS decodeCaps = {};
decodeCaps.eCodecType = _codec;
decodeCaps.eChromaFormat = _chromaFormat;
decodeCaps.nBitDepthMinus8 = videoFormat.nBitDepthMinus8;
cuSafeCall(cuvidGetDecoderCaps(&decodeCaps));
if (!decodeCaps.bIsSupported)
CV_Error(Error::StsUnsupportedFormat, "Video source is not supported by hardware video decoder");
CV_Assert(videoFormat.width >= decodeCaps.nMinWidth &&
videoFormat.height >= decodeCaps.nMinHeight &&
videoFormat.width <= decodeCaps.nMaxWidth &&
videoFormat.height <= decodeCaps.nMaxHeight);
}
#endif
// Fill the decoder-create-info struct from the given video-format struct.
std::memset(&createInfo_, 0, sizeof(CUVIDDECODECREATEINFO));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment