opencv/modules/cudacodec/doc/videoenc.rst

193 lines
6.7 KiB
ReStructuredText
Raw Normal View History

Video Encoding
==============
.. highlight:: cpp
2013-08-20 19:05:49 +08:00
cudacodec::VideoWriter
----------------------
Video writer interface.
2013-08-20 19:05:49 +08:00
.. ocv:class:: cudacodec::VideoWriter
The implementation uses H264 video codec.
.. note:: Currently only Windows platform is supported.
.. note::
Merge remote-tracking branch 'origin/2.4' Conflicts: 3rdparty/ffmpeg/ffmpeg_version.cmake cmake/OpenCVFindLibsGrfmt.cmake cmake/templates/cvconfig.h.cmake modules/bioinspired/doc/retina/index.rst modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst modules/calib3d/src/precomp.hpp modules/contrib/src/inputoutput.cpp modules/contrib/src/precomp.hpp modules/core/include/opencv2/core/internal.hpp modules/core/include/opencv2/core/types_c.h modules/core/src/drawing.cpp modules/core/src/precomp.hpp modules/core/src/system.cpp modules/features2d/doc/common_interfaces_of_descriptor_matchers.rst modules/features2d/doc/common_interfaces_of_feature_detectors.rst modules/features2d/include/opencv2/features2d/features2d.hpp modules/features2d/src/precomp.hpp modules/flann/src/precomp.hpp modules/gpu/doc/camera_calibration_and_3d_reconstruction.rst modules/gpu/doc/image_filtering.rst modules/gpu/doc/image_processing.rst modules/gpu/doc/video.rst modules/gpu/perf/perf_imgproc.cpp modules/gpu/perf4au/main.cpp modules/gpu/src/imgproc.cpp modules/gpu/src/precomp.hpp modules/gpu/test/test_imgproc.cpp modules/highgui/CMakeLists.txt modules/highgui/test/test_precomp.hpp modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst modules/imgproc/src/precomp.hpp modules/java/generator/src/cpp/Mat.cpp modules/legacy/src/precomp.hpp modules/ml/doc/k_nearest_neighbors.rst modules/ml/src/precomp.hpp modules/nonfree/doc/feature_detection.rst modules/nonfree/src/precomp.hpp modules/objdetect/include/opencv2/objdetect/objdetect.hpp modules/objdetect/src/cascadedetect.cpp modules/objdetect/src/hog.cpp modules/objdetect/src/precomp.hpp modules/objdetect/test/test_latentsvmdetector.cpp modules/ocl/src/hog.cpp modules/ocl/src/opencl/objdetect_hog.cl modules/ocl/src/precomp.hpp modules/photo/src/precomp.hpp modules/stitching/src/precomp.hpp modules/superres/perf/perf_precomp.hpp modules/superres/src/optical_flow.cpp modules/superres/src/precomp.hpp modules/superres/test/test_precomp.hpp modules/ts/include/opencv2/ts.hpp modules/video/src/precomp.hpp modules/videostab/src/precomp.hpp modules/world/src/precomp.hpp
2013-08-06 17:56:49 +08:00
* An example on how to use the videoWriter class can be found at opencv_source_code/samples/gpu/video_writer.cpp
2013-08-20 19:05:49 +08:00
cudacodec::VideoWriter::write
-----------------------------
Writes the next video frame.
2013-08-20 19:05:49 +08:00
.. ocv:function:: void cudacodec::VideoWriter::write(InputArray frame, bool lastFrame = false) = 0
:param frame: The written frame.
:param lastFrame: Indicates that it is end of stream. The parameter can be ignored.
The method write the specified image to video file. The image must have the same size and the same surface format as has been specified when opening the video writer.
2013-08-20 19:05:49 +08:00
cudacodec::createVideoWriter
----------------------------
Creates video writer.
2013-08-20 19:05:49 +08:00
.. ocv:function:: Ptr<cudacodec::VideoWriter> cudacodec::createVideoWriter(const String& fileName, Size frameSize, double fps, SurfaceFormat format = SF_BGR)
.. ocv:function:: Ptr<cudacodec::VideoWriter> cudacodec::createVideoWriter(const String& fileName, Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR)
.. ocv:function:: Ptr<cudacodec::VideoWriter> cudacodec::createVideoWriter(const Ptr<EncoderCallBack>& encoderCallback, Size frameSize, double fps, SurfaceFormat format = SF_BGR)
.. ocv:function:: Ptr<cudacodec::VideoWriter> cudacodec::createVideoWriter(const Ptr<EncoderCallBack>& encoderCallback, Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR)
:param fileName: Name of the output video file. Only AVI file format is supported.
:param frameSize: Size of the input video frames.
:param fps: Framerate of the created video stream.
2013-08-20 19:05:49 +08:00
:param params: Encoder parameters. See :ocv:struct:`cudacodec::EncoderParams` .
:param format: Surface format of input frames ( ``SF_UYVY`` , ``SF_YUY2`` , ``SF_YV12`` , ``SF_NV12`` , ``SF_IYUV`` , ``SF_BGR`` or ``SF_GRAY``). BGR or gray frames will be converted to YV12 format before encoding, frames with other formats will be used as is.
2013-08-20 19:05:49 +08:00
:param encoderCallback: Callbacks for video encoder. See :ocv:class:`cudacodec::EncoderCallBack` . Use it if you want to work with raw video stream.
2013-08-20 19:05:49 +08:00
The constructors initialize video writer. FFMPEG is used to write videos. User can implement own multiplexing with :ocv:class:`cudacodec::EncoderCallBack` .
2013-08-20 19:05:49 +08:00
cudacodec::EncoderParams
------------------------
.. ocv:struct:: cudacodec::EncoderParams
Different parameters for CUDA video encoder. ::
struct EncoderParams
{
int P_Interval; // NVVE_P_INTERVAL,
int IDR_Period; // NVVE_IDR_PERIOD,
int DynamicGOP; // NVVE_DYNAMIC_GOP,
int RCType; // NVVE_RC_TYPE,
int AvgBitrate; // NVVE_AVG_BITRATE,
int PeakBitrate; // NVVE_PEAK_BITRATE,
int QP_Level_Intra; // NVVE_QP_LEVEL_INTRA,
int QP_Level_InterP; // NVVE_QP_LEVEL_INTER_P,
int QP_Level_InterB; // NVVE_QP_LEVEL_INTER_B,
int DeblockMode; // NVVE_DEBLOCK_MODE,
int ProfileLevel; // NVVE_PROFILE_LEVEL,
int ForceIntra; // NVVE_FORCE_INTRA,
int ForceIDR; // NVVE_FORCE_IDR,
int ClearStat; // NVVE_CLEAR_STAT,
int DIMode; // NVVE_SET_DEINTERLACE,
int Presets; // NVVE_PRESETS,
int DisableCabac; // NVVE_DISABLE_CABAC,
int NaluFramingType; // NVVE_CONFIGURE_NALU_FRAMING_TYPE
int DisableSPSPPS; // NVVE_DISABLE_SPS_PPS
EncoderParams();
explicit EncoderParams(const String& configFile);
void load(const String& configFile);
void save(const String& configFile) const;
};
2013-08-20 19:05:49 +08:00
cudacodec::EncoderParams::EncoderParams
---------------------------------------
Constructors.
2013-08-20 19:05:49 +08:00
.. ocv:function:: cudacodec::EncoderParams::EncoderParams()
.. ocv:function:: cudacodec::EncoderParams::EncoderParams(const String& configFile)
:param configFile: Config file name.
Creates default parameters or reads parameters from config file.
2013-08-20 19:05:49 +08:00
cudacodec::EncoderParams::load
------------------------------
Reads parameters from config file.
2013-08-20 19:05:49 +08:00
.. ocv:function:: void cudacodec::EncoderParams::load(const String& configFile)
:param configFile: Config file name.
2013-08-20 19:05:49 +08:00
cudacodec::EncoderParams::save
------------------------------
Saves parameters to config file.
2013-08-20 19:05:49 +08:00
.. ocv:function:: void cudacodec::EncoderParams::save(const String& configFile) const
:param configFile: Config file name.
2013-08-20 19:05:49 +08:00
cudacodec::EncoderCallBack
--------------------------
.. ocv:class:: cudacodec::EncoderCallBack
Callbacks for CUDA video encoder. ::
class EncoderCallBack
{
public:
enum PicType
{
IFRAME = 1,
PFRAME = 2,
BFRAME = 3
};
virtual ~EncoderCallBack() {}
virtual unsigned char* acquireBitStream(int* bufferSize) = 0;
virtual void releaseBitStream(unsigned char* data, int size) = 0;
virtual void onBeginFrame(int frameNumber, PicType picType) = 0;
virtual void onEndFrame(int frameNumber, PicType picType) = 0;
};
2013-08-20 19:05:49 +08:00
cudacodec::EncoderCallBack::acquireBitStream
--------------------------------------------
Callback function to signal the start of bitstream that is to be encoded.
2013-08-20 19:05:49 +08:00
.. ocv:function:: virtual uchar* cudacodec::EncoderCallBack::acquireBitStream(int* bufferSize) = 0
Callback must allocate buffer for CUDA encoder and return pointer to it and it's size.
2013-08-20 19:05:49 +08:00
cudacodec::EncoderCallBack::releaseBitStream
--------------------------------------------
Callback function to signal that the encoded bitstream is ready to be written to file.
2013-08-20 19:05:49 +08:00
.. ocv:function:: virtual void cudacodec::EncoderCallBack::releaseBitStream(unsigned char* data, int size) = 0
2013-08-20 19:05:49 +08:00
cudacodec::EncoderCallBack::onBeginFrame
----------------------------------------
Callback function to signal that the encoding operation on the frame has started.
2013-08-20 19:05:49 +08:00
.. ocv:function:: virtual void cudacodec::EncoderCallBack::onBeginFrame(int frameNumber, PicType picType) = 0
:param picType: Specify frame type (I-Frame, P-Frame or B-Frame).
2013-08-20 19:05:49 +08:00
cudacodec::EncoderCallBack::onEndFrame
--------------------------------------
Callback function signals that the encoding operation on the frame has finished.
2013-08-20 19:05:49 +08:00
.. ocv:function:: virtual void cudacodec::EncoderCallBack::onEndFrame(int frameNumber, PicType picType) = 0
:param picType: Specify frame type (I-Frame, P-Frame or B-Frame).