Skip to content

Commit ca68951

Browse files
committed
Support for HEVC in cudacodec::VideoReader opencv#6054
1 parent 7601c21 commit ca68951

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

modules/cudacodec/src/video_decoder.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ void cv::cudacodec::detail::VideoDecoder::create(const FormatInfo& videoFormat)
6363
cudaVideoCodec_VC1 == _codec ||
6464
cudaVideoCodec_H264 == _codec ||
6565
cudaVideoCodec_JPEG == _codec ||
66+
cudaVideoCodec_H264_SVC == _codec ||
67+
cudaVideoCodec_H264_MVC == _codec ||
68+
cudaVideoCodec_HEVC == _codec ||
69+
cudaVideoCodec_VP8 == _codec ||
70+
cudaVideoCodec_VP9 == _codec ||
6671
cudaVideoCodec_YUV420== _codec ||
6772
cudaVideoCodec_YV12 == _codec ||
6873
cudaVideoCodec_NV12 == _codec ||
@@ -84,7 +89,7 @@ void cv::cudacodec::detail::VideoDecoder::create(const FormatInfo& videoFormat)
8489
createInfo_.ulNumDecodeSurfaces = FrameQueue::MaximumSize;
8590

8691
// Limit decode memory to 24MB (16M pixels at 4:2:0 = 24M bytes)
87-
while (createInfo_.ulNumDecodeSurfaces * videoFormat.width * videoFormat.height > 16 * 1024 * 1024)
92+
while (createInfo_.ulNumDecodeSurfaces * videoFormat.width * videoFormat.height > 16 * 4096 * 4096)
8893
createInfo_.ulNumDecodeSurfaces--;
8994

9095
createInfo_.ChromaFormat = _chromaFormat;
@@ -114,3 +119,4 @@ void cv::cudacodec::detail::VideoDecoder::release()
114119
}
115120

116121
#endif // HAVE_NVCUVID
122+

modules/videoio/src/cap_ffmpeg_impl.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc,
15581558
and qmin since they will be set to reasonable defaults by the libx264
15591559
preset system. Also, use a crf encode with the default quality rating,
15601560
this seems easier than finding an appropriate default bitrate. */
1561-
if (c->codec_id == AV_CODEC_ID_H264) {
1561+
if (c->codec_id == AV_CODEC_ID_H264 || c->codec_id == AV_CODEC_ID_HEVC) {
15621562
c->gop_size = -1;
15631563
c->qmin = -1;
15641564
c->bit_rate = 0;
@@ -1707,7 +1707,7 @@ bool CvVideoWriter_FFMPEG::writeFrame( const unsigned char* data, int step, int
17071707
const int CV_STEP_ALIGNMENT = 32;
17081708
const size_t CV_SIMD_SIZE = 32;
17091709
const size_t CV_PAGE_MASK = ~(4096 - 1);
1710-
const unsigned char* dataend = data + ((size_t)height * step);
1710+
const uchar* dataend = data + ((size_t)height * step);
17111711
if (step % CV_STEP_ALIGNMENT != 0 ||
17121712
(((size_t)dataend - CV_SIMD_SIZE) & CV_PAGE_MASK) != (((size_t)dataend + CV_SIMD_SIZE) & CV_PAGE_MASK))
17131713
{
@@ -2555,6 +2555,9 @@ enum
25552555
VideoCodec_JPEG,
25562556
VideoCodec_H264_SVC,
25572557
VideoCodec_H264_MVC,
2558+
VideoCodec_HEVC,
2559+
VideoCodec_VP8,
2560+
VideoCodec_VP9,
25582561

25592562
// Uncompressed YUV
25602563
VideoCodec_YUV420 = (('I'<<24)|('Y'<<16)|('U'<<8)|('V')), // Y,U,V (4:2:0)
@@ -2665,13 +2668,18 @@ bool InputMediaStream_FFMPEG::open(const char* fileName, int* codec, int* chroma
26652668
*codec = ::VideoCodec_H264;
26662669
break;
26672670

2671+
case CV_CODEC(CODEC_ID_HEVC):
2672+
*codec = ::VideoCodec_HEVC;
2673+
break;
2674+
26682675
default:
26692676
return false;
26702677
};
26712678

26722679
switch (enc->pix_fmt)
26732680
{
26742681
case AV_PIX_FMT_YUV420P:
2682+
case AV_PIX_FMT_YUVJ420P:
26752683
*chroma_format = ::VideoChromaFormat_YUV420;
26762684
break;
26772685

modules/videoio/src/ffmpeg_codecs.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ typedef struct AVCodecTag {
7878
} AVCodecTag;
7979

8080
#if (LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(54, 51, 100))
81+
#define AV_CODEC_ID_HEVC CODEC_ID_HEVC
8182
#define AV_CODEC_ID_H264 CODEC_ID_H264
8283
#define AV_CODEC_ID_H263 CODEC_ID_H263
8384
#define AV_CODEC_ID_H263P CODEC_ID_H263P
@@ -143,6 +144,11 @@ typedef struct AVCodecTag {
143144
#endif
144145

145146
const AVCodecTag codec_bmp_tags[] = {
147+
{ AV_CODEC_ID_HEVC, MKTAG('H', 'E', 'V', 'C') },
148+
{ AV_CODEC_ID_HEVC, MKTAG('h', 'e', 'v', 'c') },
149+
{ AV_CODEC_ID_HEVC, MKTAG('H', '2', '6', '5') },
150+
{ AV_CODEC_ID_HEVC, MKTAG('h', '2', '6', '5') },
151+
146152
{ AV_CODEC_ID_H264, MKTAG('H', '2', '6', '4') },
147153
{ AV_CODEC_ID_H264, MKTAG('h', '2', '6', '4') },
148154
{ AV_CODEC_ID_H264, MKTAG('X', '2', '6', '4') },

0 commit comments

Comments
 (0)