1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
11
// For Open Source Computer Vision Library
13
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
16
// Third party copyrights are property of their respective owners.
18
// Redistribution and use in source and binary forms, with or without modification,
19
// are permitted provided that the following conditions are met:
21
// * Redistribution's of source code must retain the above copyright notice,
22
// this list of conditions and the following disclaimer.
24
// * Redistribution's in binary form must reproduce the above copyright notice,
25
// this list of conditions and the following disclaimer in the documentation
26
// and/or other materials provided with the distribution.
28
// * The name of the copyright holders may not be used to endorse or promote products
29
// derived from this software without specific prior written permission.
31
// This software is provided by the copyright holders and contributors "as is" and
32
// any express or implied warranties, including, but not limited to, the implied
33
// warranties of merchantability and fitness for a particular purpose are disclaimed.
34
// In no event shall the Intel Corporation or contributors be liable for any direct,
35
// indirect, incidental, special, exemplary, or consequential damages
36
// (including, but not limited to, procurement of substitute goods or services;
37
// loss of use, data, or profits; or business interruption) however caused
38
// and on any theory of liability, whether in contract, strict liability,
39
// or tort (including negligence or otherwise) arising in any way out of
40
// the use of this software, even if advised of the possibility of such damage.
44
#ifndef __OPENCV_CUDACODEC_HPP__
45
#define __OPENCV_CUDACODEC_HPP__
48
# error cudacodec.hpp header must be compiled as C++
51
#include "opencv2/core/cuda.hpp"
56
@defgroup cudacodec Video Encoding/Decoding
60
namespace cv { namespace cudacodec {
62
//! @addtogroup cudacodec
65
////////////////////////////////// Video Encoding //////////////////////////////////
67
// Works only under Windows.
68
// Supports olny H264 video codec and AVI files.
81
/** @brief Different parameters for CUDA video encoder.
83
struct CV_EXPORTS EncoderParams
85
int P_Interval; //!< NVVE_P_INTERVAL,
86
int IDR_Period; //!< NVVE_IDR_PERIOD,
87
int DynamicGOP; //!< NVVE_DYNAMIC_GOP,
88
int RCType; //!< NVVE_RC_TYPE,
89
int AvgBitrate; //!< NVVE_AVG_BITRATE,
90
int PeakBitrate; //!< NVVE_PEAK_BITRATE,
91
int QP_Level_Intra; //!< NVVE_QP_LEVEL_INTRA,
92
int QP_Level_InterP; //!< NVVE_QP_LEVEL_INTER_P,
93
int QP_Level_InterB; //!< NVVE_QP_LEVEL_INTER_B,
94
int DeblockMode; //!< NVVE_DEBLOCK_MODE,
95
int ProfileLevel; //!< NVVE_PROFILE_LEVEL,
96
int ForceIntra; //!< NVVE_FORCE_INTRA,
97
int ForceIDR; //!< NVVE_FORCE_IDR,
98
int ClearStat; //!< NVVE_CLEAR_STAT,
99
int DIMode; //!< NVVE_SET_DEINTERLACE,
100
int Presets; //!< NVVE_PRESETS,
101
int DisableCabac; //!< NVVE_DISABLE_CABAC,
102
int NaluFramingType; //!< NVVE_CONFIGURE_NALU_FRAMING_TYPE
103
int DisableSPSPPS; //!< NVVE_DISABLE_SPS_PPS
106
/** @brief Constructors.
108
@param configFile Config file name.
110
Creates default parameters or reads parameters from config file.
112
explicit EncoderParams(const String& configFile);
114
/** @brief Reads parameters from config file.
116
@param configFile Config file name.
118
void load(const String& configFile);
119
/** @brief Saves parameters to config file.
121
@param configFile Config file name.
123
void save(const String& configFile) const;
126
/** @brief Callbacks for CUDA video encoder.
128
class CV_EXPORTS EncoderCallBack
138
virtual ~EncoderCallBack() {}
140
/** @brief Callback function to signal the start of bitstream that is to be encoded.
142
Callback must allocate buffer for CUDA encoder and return pointer to it and it's size.
144
virtual uchar* acquireBitStream(int* bufferSize) = 0;
146
/** @brief Callback function to signal that the encoded bitstream is ready to be written to file.
148
virtual void releaseBitStream(unsigned char* data, int size) = 0;
150
/** @brief Callback function to signal that the encoding operation on the frame has started.
153
@param picType Specify frame type (I-Frame, P-Frame or B-Frame).
155
virtual void onBeginFrame(int frameNumber, PicType picType) = 0;
157
/** @brief Callback function signals that the encoding operation on the frame has finished.
160
@param picType Specify frame type (I-Frame, P-Frame or B-Frame).
162
virtual void onEndFrame(int frameNumber, PicType picType) = 0;
165
/** @brief Video writer interface.
167
The implementation uses H264 video codec.
169
@note Currently only Windows platform is supported.
172
- An example on how to use the videoWriter class can be found at
173
opencv_source_code/samples/gpu/video_writer.cpp
175
class CV_EXPORTS VideoWriter
178
virtual ~VideoWriter() {}
180
/** @brief Writes the next video frame.
182
@param frame The written frame.
183
@param lastFrame Indicates that it is end of stream. The parameter can be ignored.
185
The method write the specified image to video file. The image must have the same size and the same
186
surface format as has been specified when opening the video writer.
188
virtual void write(InputArray frame, bool lastFrame = false) = 0;
190
virtual EncoderParams getEncoderParams() const = 0;
193
/** @brief Creates video writer.
195
@param fileName Name of the output video file. Only AVI file format is supported.
196
@param frameSize Size of the input video frames.
197
@param fps Framerate of the created video stream.
198
@param format Surface format of input frames ( SF_UYVY , SF_YUY2 , SF_YV12 , SF_NV12 ,
199
SF_IYUV , SF_BGR or SF_GRAY). BGR or gray frames will be converted to YV12 format before
200
encoding, frames with other formats will be used as is.
202
The constructors initialize video writer. FFMPEG is used to write videos. User can implement own
203
multiplexing with cudacodec::EncoderCallBack .
205
CV_EXPORTS Ptr<VideoWriter> createVideoWriter(const String& fileName, Size frameSize, double fps, SurfaceFormat format = SF_BGR);
207
@param fileName Name of the output video file. Only AVI file format is supported.
208
@param frameSize Size of the input video frames.
209
@param fps Framerate of the created video stream.
210
@param params Encoder parameters. See cudacodec::EncoderParams .
211
@param format Surface format of input frames ( SF_UYVY , SF_YUY2 , SF_YV12 , SF_NV12 ,
212
SF_IYUV , SF_BGR or SF_GRAY). BGR or gray frames will be converted to YV12 format before
213
encoding, frames with other formats will be used as is.
215
CV_EXPORTS Ptr<VideoWriter> createVideoWriter(const String& fileName, Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
218
@param encoderCallback Callbacks for video encoder. See cudacodec::EncoderCallBack . Use it if you
219
want to work with raw video stream.
220
@param frameSize Size of the input video frames.
221
@param fps Framerate of the created video stream.
222
@param format Surface format of input frames ( SF_UYVY , SF_YUY2 , SF_YV12 , SF_NV12 ,
223
SF_IYUV , SF_BGR or SF_GRAY). BGR or gray frames will be converted to YV12 format before
224
encoding, frames with other formats will be used as is.
226
CV_EXPORTS Ptr<VideoWriter> createVideoWriter(const Ptr<EncoderCallBack>& encoderCallback, Size frameSize, double fps, SurfaceFormat format = SF_BGR);
228
@param encoderCallback Callbacks for video encoder. See cudacodec::EncoderCallBack . Use it if you
229
want to work with raw video stream.
230
@param frameSize Size of the input video frames.
231
@param fps Framerate of the created video stream.
232
@param params Encoder parameters. See cudacodec::EncoderParams .
233
@param format Surface format of input frames ( SF_UYVY , SF_YUY2 , SF_YV12 , SF_NV12 ,
234
SF_IYUV , SF_BGR or SF_GRAY). BGR or gray frames will be converted to YV12 format before
235
encoding, frames with other formats will be used as is.
237
CV_EXPORTS Ptr<VideoWriter> createVideoWriter(const Ptr<EncoderCallBack>& encoderCallback, Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
239
////////////////////////////////// Video Decoding //////////////////////////////////////////
241
/** @brief Video codecs supported by cudacodec::VideoReader .
254
Uncompressed_YUV420 = (('I'<<24)|('Y'<<16)|('U'<<8)|('V')), //!< Y,U,V (4:2:0)
255
Uncompressed_YV12 = (('Y'<<24)|('V'<<16)|('1'<<8)|('2')), //!< Y,V,U (4:2:0)
256
Uncompressed_NV12 = (('N'<<24)|('V'<<16)|('1'<<8)|('2')), //!< Y,UV (4:2:0)
257
Uncompressed_YUYV = (('Y'<<24)|('U'<<16)|('Y'<<8)|('V')), //!< YUYV/YUY2 (4:2:2)
258
Uncompressed_UYVY = (('U'<<24)|('Y'<<16)|('V'<<8)|('Y')) //!< UYVY (4:2:2)
261
/** @brief Chroma formats supported by cudacodec::VideoReader .
271
/** @brief Struct providing information about video file format. :
276
ChromaFormat chromaFormat;
281
/** @brief Video reader interface.
284
- An example on how to use the videoReader class can be found at
285
opencv_source_code/samples/gpu/video_reader.cpp
287
class CV_EXPORTS VideoReader
290
virtual ~VideoReader() {}
292
/** @brief Grabs, decodes and returns the next video frame.
294
If no frames has been grabbed (there are no more frames in video file), the methods return false .
295
The method throws Exception if error occurs.
297
virtual bool nextFrame(OutputArray frame) = 0;
299
/** @brief Returns information about video file format.
301
virtual FormatInfo format() const = 0;
304
/** @brief Interface for video demultiplexing. :
306
User can implement own demultiplexing by implementing this interface.
308
class CV_EXPORTS RawVideoSource
311
virtual ~RawVideoSource() {}
313
/** @brief Returns next packet with RAW video frame.
315
@param data Pointer to frame data.
316
@param size Size in bytes of current frame.
317
@param endOfFile Indicates that it is end of stream.
319
virtual bool getNextPacket(unsigned char** data, int* size, bool* endOfFile) = 0;
321
/** @brief Returns information about video file format.
323
virtual FormatInfo format() const = 0;
326
/** @brief Creates video reader.
328
@param filename Name of the input video file.
330
FFMPEG is used to read videos. User can implement own demultiplexing with cudacodec::RawVideoSource
332
CV_EXPORTS Ptr<VideoReader> createVideoReader(const String& filename);
334
@param source RAW video source implemented by user.
336
CV_EXPORTS Ptr<VideoReader> createVideoReader(const Ptr<RawVideoSource>& source);
340
}} // namespace cv { namespace cudacodec {
342
#endif /* __OPENCV_CUDACODEC_HPP__ */