cv::VideoWriter Class Reference
视频 I/O

Video writer class. 更多...

#include <opencv2/videoio.hpp>

Public Member Functions

VideoWriter ()
Default constructors. 更多...
VideoWriter (const 字符串 &filename, int fourcc , double fps, Size frameSize, bool isColor=true)
VideoWriter (const 字符串 &filename, int apiPreference, int fourcc , double fps, Size frameSize, bool isColor=true)
virtual ~VideoWriter ()
Default destructor. 更多...
virtual double get (int propId) const
Returns the specified VideoWriter 特性。 更多...
字符串 getBackendName () const
Returns used backend API name. 更多...
virtual bool isOpened () const
Returns true if video writer has been successfully initialized. 更多...
virtual bool open (const 字符串 &filename, int fourcc , double fps, Size frameSize, bool isColor=true)
Initializes or reinitializes video writer. 更多...
bool open (const 字符串 &filename, int apiPreference, int fourcc , double fps, Size frameSize, bool isColor=true)
virtual VideoWriter & operator<< (const Mat &image)
Stream operator to write the next video frame. 更多...
virtual VideoWriter & operator<< (const UMat &image)
virtual void release ()
Closes the video writer. 更多...
virtual bool set (int propId, double value)
Sets a property in the VideoWriter . 更多...
virtual void write ( InputArray image)
Writes the next video frame. 更多...

Static Public Member Functions

static int fourcc (char c1, char c2, char c3, char c4)
Concatenates 4 chars to a fourcc code. 更多...

Static Protected Member Functions

static Ptr < IVideoWriter > create (const 字符串 &filename, int fourcc , double fps, Size frameSize, bool isColor=true)

Protected Attributes

Ptr < IVideoWriter > iwriter
Ptr < CvVideoWriter > writer

详细描述

Video writer class.

The class provides C++ API for writing video files or image sequences.

范例:
samples/cpp/tutorial_code/videoio/video-write/video-write.cpp , samples/cpp/videowriter_basic.cpp ,和 samples/tapi/hog.cpp .

Constructor & Destructor Documentation

VideoWriter() [1/3]

cv::VideoWriter::VideoWriter ( )
Python:
<VideoWriter object> = cv.VideoWriter( )
<VideoWriter object> = cv.VideoWriter( filename, fourcc, fps, frameSize[, isColor] )
<VideoWriter object> = cv.VideoWriter( filename, apiPreference, fourcc, fps, frameSize[, isColor] )

Default constructors.

The constructors/functions initialize video writers.

  • On Linux FFMPEG is used to write videos;
  • On Windows FFMPEG or MSWF or DSHOW is used;
  • On MacOSX AVFoundation is used.

VideoWriter() [2/3]

cv::VideoWriter::VideoWriter ( const 字符串 & filename ,
int fourcc ,
double fps ,
Size frameSize ,
bool isColor = true
)
Python:
<VideoWriter object> = cv.VideoWriter( )
<VideoWriter object> = cv.VideoWriter( filename, fourcc, fps, frameSize[, isColor] )
<VideoWriter object> = cv.VideoWriter( filename, apiPreference, fourcc, fps, frameSize[, isColor] )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

参数
filename Name of the output video file.
fourcc 4-character code of codec used to compress the frames. For example, VideoWriter::fourcc ('P','I','M','1') is a MPEG-1 codec, VideoWriter::fourcc ('M','J','P','G') is a motion-jpeg codec etc. List of codes can be obtained at Video Codecs by FOURCC page. FFMPEG backend with MP4 container natively uses other values as fourcc code: see ObjectType , so you may receive a warning message from OpenCV about fourcc code conversion.
fps Framerate of the created video stream.
frameSize Size of the video frames.
isColor If it is not zero, the encoder will expect and encode color frames, otherwise it will work with grayscale frames (the flag is currently supported on Windows only).

Tips:

  • With some backends fourcc=-1 pops up the codec selection dialog from the system.
  • To save image sequence use a proper filename (eg. img_%02d.jpg ) and fourcc=0 OR fps=0 . Use uncompressed image format (eg. img_%02d.BMP ) to save raw frames.
  • Most codecs are lossy. If you want lossless video file you need to use a lossless codecs (eg. FFMPEG FFV1, Huffman HFYU, Lagarith LAGS, etc...)
  • If FFMPEG is enabled, using codec=0; fps=0; you can create an uncompressed (raw) video file.

VideoWriter() [3/3]

cv::VideoWriter::VideoWriter ( const 字符串 & filename ,
int apiPreference ,
int fourcc ,
double fps ,
Size frameSize ,
bool isColor = true
)
Python:
<VideoWriter object> = cv.VideoWriter( )
<VideoWriter object> = cv.VideoWriter( filename, fourcc, fps, frameSize[, isColor] )
<VideoWriter object> = cv.VideoWriter( filename, apiPreference, fourcc, fps, frameSize[, isColor] )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. The apiPreference parameter allows to specify API backends to use. Can be used to enforce a specific reader implementation if multiple are available: e.g. cv::CAP_FFMPEG or cv::CAP_GSTREAMER .

~VideoWriter()

virtual cv::VideoWriter::~VideoWriter ( )
virtual

Default destructor.

The method first calls VideoWriter::release to close the already opened file.

成员函数文档编制

create()

static Ptr <IVideoWriter> cv::VideoWriter::create ( const 字符串 & filename ,
int fourcc ,
double fps ,
Size frameSize ,
bool isColor = true
)
static protected

fourcc()

static int cv::VideoWriter::fourcc ( char c1 ,
char c2 ,
char c3 ,
char c4
)
static
Python:
retval = cv.VideoWriter_fourcc( c1, c2, c3, c4 )

Concatenates 4 chars to a fourcc code.

返回
a fourcc code

This static method constructs the fourcc code of the codec to be used in the constructor VideoWriter::VideoWriter or VideoWriter::open .

范例:
samples/cpp/videowriter_basic.cpp .

get()

virtual double cv::VideoWriter::get ( int propId ) const
virtual
Python:
retval = cv.VideoWriter.get( propId )

Returns the specified VideoWriter 特性。

参数
propId Property identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY ) or one of Additional flags for video I/O API backends
返回
Value for the specified property. Value 0 is returned when querying a property that is not supported by the backend used by the VideoWriter 实例。

getBackendName()

字符串 cv::VideoWriter::getBackendName ( ) const
Python:
retval = cv.VideoWriter.getBackendName( )

Returns used backend API name.

注意
Stream should be opened.

isOpened()

virtual bool cv::VideoWriter::isOpened ( ) const
virtual
Python:
retval = cv.VideoWriter.isOpened( )

Returns true if video writer has been successfully initialized.

范例:
samples/cpp/videowriter_basic.cpp ,和 samples/tapi/hog.cpp .

open() [1/2]

virtual bool cv::VideoWriter::open ( const 字符串 & filename ,
int fourcc ,
double fps ,
Size frameSize ,
bool isColor = true
)
virtual
Python:
retval = cv.VideoWriter.open( filename, fourcc, fps, frameSize[, isColor] )
retval = cv.VideoWriter.open( filename, apiPreference, fourcc, fps, frameSize[, isColor] )

Initializes or reinitializes video writer.

The method opens video writer. Parameters are the same as in the constructor VideoWriter::VideoWriter .

返回
true if video writer has been successfully initialized

The method first calls VideoWriter::release to close the already opened file.

范例:
samples/cpp/tutorial_code/videoio/video-write/video-write.cpp , samples/cpp/videowriter_basic.cpp ,和 samples/tapi/hog.cpp .

open() [2/2]

bool cv::VideoWriter::open ( const 字符串 & filename ,
int apiPreference ,
int fourcc ,
double fps ,
Size frameSize ,
bool isColor = true
)
Python:
retval = cv.VideoWriter.open( filename, fourcc, fps, frameSize[, isColor] )
retval = cv.VideoWriter.open( filename, apiPreference, fourcc, fps, frameSize[, isColor] )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

operator<<() [1/2]

virtual VideoWriter & cv::VideoWriter::operator<< ( const Mat & image )
virtual

Stream operator to write the next video frame.

另请参阅
write

operator<<() [2/2]

virtual VideoWriter & cv::VideoWriter::operator<< ( const UMat & image )
virtual

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

另请参阅
write

release()

virtual void cv::VideoWriter::release ( )
virtual
Python:
None = cv.VideoWriter.release( )

Closes the video writer.

The method is automatically called by subsequent VideoWriter::open and by the VideoWriter 析构函数。

set()

virtual bool cv::VideoWriter::set ( int propId ,
double value
)
virtual
Python:
retval = cv.VideoWriter.set( propId, value )

Sets a property in the VideoWriter .

参数
propId Property identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY ) or one of Additional flags for video I/O API backends
value Value of the property.
返回
true if the property is supported by the backend used by the VideoWriter 实例。

write()

virtual void cv::VideoWriter::write ( InputArray image )
virtual
Python:
None = cv.VideoWriter.write( image )

Writes the next video frame.

参数
image The written frame. In general, color images are expected in BGR format.

The function/method writes the specified image to video file. It must have the same size as has been specified when opening the video writer.

范例:
samples/cpp/videowriter_basic.cpp .

Member Data Documentation

iwriter

Ptr <IVideoWriter> cv::VideoWriter::iwriter
protected

writer

Ptr < CvVideoWriter > cv::VideoWriter::writer
protected

The documentation for this class was generated from the following file: