Video writer class.
More...
#include <opencv2/videoio.hpp>
|
| VideoWriter () |
| Default constructors.
|
|
| VideoWriter (const String &filename, int apiPreference, int fourcc, double fps, const Size &frameSize, const std::vector< int > ¶ms) |
|
| VideoWriter (const String &filename, int apiPreference, int fourcc, double fps, Size frameSize, bool isColor=true) |
|
| VideoWriter (const String &filename, int fourcc, double fps, const Size &frameSize, const std::vector< int > ¶ms) |
|
| VideoWriter (const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true) |
|
virtual | ~VideoWriter () |
| Default destructor.
|
|
virtual double | get (int propId) const |
| Returns the specified VideoWriter property.
|
|
String | getBackendName () const |
| Returns used backend API name.
|
|
virtual bool | isOpened () const |
| Returns true if video writer has been successfully initialized.
|
|
bool | open (const String &filename, int apiPreference, int fourcc, double fps, const Size &frameSize, const std::vector< int > ¶ms) |
|
bool | open (const String &filename, int apiPreference, int fourcc, double fps, Size frameSize, bool isColor=true) |
|
bool | open (const String &filename, int fourcc, double fps, const Size &frameSize, const std::vector< int > ¶ms) |
|
virtual bool | open (const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true) |
| Initializes or reinitializes video writer.
|
|
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 int | fourcc (char c1, char c2, char c3, char c4) |
| Concatenates 4 chars to a fourcc code.
|
|
Video writer class.
The class provides C++ API for writing video files or image sequences.
- Examples
- samples/cpp/tutorial_code/videoio/video-write/video-write.cpp, samples/cpp/videowriter.cpp, and samples/hog_tapi.cpp.
◆ VideoWriter() [1/5]
cv::VideoWriter::VideoWriter |
( |
| ) |
|
Python: |
---|
| cv.VideoWriter( | | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, fourcc, fps, frameSize[, isColor] | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, apiPreference, fourcc, fps, frameSize[, isColor] | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, fourcc, fps, frameSize, params | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, apiPreference, fourcc, fps, frameSize, params | ) -> | <VideoWriter object> |
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/5]
cv::VideoWriter::VideoWriter |
( |
const String & | filename, |
|
|
int | fourcc, |
|
|
double | fps, |
|
|
Size | frameSize, |
|
|
bool | isColor = true ) |
Python: |
---|
| cv.VideoWriter( | | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, fourcc, fps, frameSize[, isColor] | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, apiPreference, fourcc, fps, frameSize[, isColor] | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, fourcc, fps, frameSize, params | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, apiPreference, fourcc, fps, frameSize, params | ) -> | <VideoWriter object> |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters
-
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 MSDN page or with this page of the fourcc site for a more complete list). 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. |
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.
- If FFMPEG is used, we allow frames of odd width or height, but in this case we truncate the rightmost column/the bottom row. Probably, this should be handled more elegantly, but some internal functions inside FFMPEG swscale require even width/height.
◆ VideoWriter() [3/5]
cv::VideoWriter::VideoWriter |
( |
const String & | filename, |
|
|
int | apiPreference, |
|
|
int | fourcc, |
|
|
double | fps, |
|
|
Size | frameSize, |
|
|
bool | isColor = true ) |
Python: |
---|
| cv.VideoWriter( | | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, fourcc, fps, frameSize[, isColor] | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, apiPreference, fourcc, fps, frameSize[, isColor] | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, fourcc, fps, frameSize, params | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, apiPreference, fourcc, fps, frameSize, params | ) -> | <VideoWriter object> |
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() [4/5]
cv::VideoWriter::VideoWriter |
( |
const String & | filename, |
|
|
int | fourcc, |
|
|
double | fps, |
|
|
const Size & | frameSize, |
|
|
const std::vector< int > & | params ) |
Python: |
---|
| cv.VideoWriter( | | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, fourcc, fps, frameSize[, isColor] | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, apiPreference, fourcc, fps, frameSize[, isColor] | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, fourcc, fps, frameSize, params | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, apiPreference, fourcc, fps, frameSize, params | ) -> | <VideoWriter object> |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. The params
parameter allows to specify extra encoder parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) see cv::VideoWriterProperties
◆ VideoWriter() [5/5]
cv::VideoWriter::VideoWriter |
( |
const String & | filename, |
|
|
int | apiPreference, |
|
|
int | fourcc, |
|
|
double | fps, |
|
|
const Size & | frameSize, |
|
|
const std::vector< int > & | params ) |
Python: |
---|
| cv.VideoWriter( | | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, fourcc, fps, frameSize[, isColor] | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, apiPreference, fourcc, fps, frameSize[, isColor] | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, fourcc, fps, frameSize, params | ) -> | <VideoWriter object> |
| cv.VideoWriter( | filename, apiPreference, fourcc, fps, frameSize, params | ) -> | <VideoWriter object> |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ ~VideoWriter()
virtual cv::VideoWriter::~VideoWriter |
( |
| ) |
|
|
virtual |
◆ create()
static Ptr< IVideoWriter > cv::VideoWriter::create |
( |
const String & | filename, |
|
|
int | fourcc, |
|
|
double | fps, |
|
|
Size | frameSize, |
|
|
bool | isColor = true ) |
|
staticprotected |
◆ fourcc()
static int cv::VideoWriter::fourcc |
( |
char | c1, |
|
|
char | c2, |
|
|
char | c3, |
|
|
char | c4 ) |
|
static |
Python: |
---|
| cv.VideoWriter.fourcc( | c1, c2, c3, c4 | ) -> | retval |
| cv.VideoWriter_fourcc( | c1, c2, c3, c4 | ) -> | retval |
◆ get()
virtual double cv::VideoWriter::get |
( |
int | propId | ) |
const |
|
virtual |
Python: |
---|
| cv.VideoWriter.get( | propId | ) -> | retval |
Returns the specified VideoWriter property.
- Parameters
-
- Returns
- Value for the specified property. Value 0 is returned when querying a property that is not supported by the backend used by the VideoWriter instance.
◆ getBackendName()
String cv::VideoWriter::getBackendName |
( |
| ) |
const |
Python: |
---|
| cv.VideoWriter.getBackendName( | | ) -> | retval |
Returns used backend API name.
- Note
- Stream should be opened.
◆ isOpened()
virtual bool cv::VideoWriter::isOpened |
( |
| ) |
const |
|
virtual |
Python: |
---|
| cv.VideoWriter.isOpened( | | ) -> | retval |
◆ open() [1/4]
bool cv::VideoWriter::open |
( |
const String & | filename, |
|
|
int | apiPreference, |
|
|
int | fourcc, |
|
|
double | fps, |
|
|
const Size & | frameSize, |
|
|
const std::vector< int > & | params ) |
Python: |
---|
| cv.VideoWriter.open( | filename, fourcc, fps, frameSize[, isColor] | ) -> | retval |
| cv.VideoWriter.open( | filename, apiPreference, fourcc, fps, frameSize[, isColor] | ) -> | retval |
| cv.VideoWriter.open( | filename, fourcc, fps, frameSize, params | ) -> | retval |
| cv.VideoWriter.open( | filename, apiPreference, fourcc, fps, frameSize, params | ) -> | retval |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ open() [2/4]
bool cv::VideoWriter::open |
( |
const String & | filename, |
|
|
int | apiPreference, |
|
|
int | fourcc, |
|
|
double | fps, |
|
|
Size | frameSize, |
|
|
bool | isColor = true ) |
Python: |
---|
| cv.VideoWriter.open( | filename, fourcc, fps, frameSize[, isColor] | ) -> | retval |
| cv.VideoWriter.open( | filename, apiPreference, fourcc, fps, frameSize[, isColor] | ) -> | retval |
| cv.VideoWriter.open( | filename, fourcc, fps, frameSize, params | ) -> | retval |
| cv.VideoWriter.open( | filename, apiPreference, fourcc, fps, frameSize, params | ) -> | retval |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ open() [3/4]
bool cv::VideoWriter::open |
( |
const String & | filename, |
|
|
int | fourcc, |
|
|
double | fps, |
|
|
const Size & | frameSize, |
|
|
const std::vector< int > & | params ) |
Python: |
---|
| cv.VideoWriter.open( | filename, fourcc, fps, frameSize[, isColor] | ) -> | retval |
| cv.VideoWriter.open( | filename, apiPreference, fourcc, fps, frameSize[, isColor] | ) -> | retval |
| cv.VideoWriter.open( | filename, fourcc, fps, frameSize, params | ) -> | retval |
| cv.VideoWriter.open( | filename, apiPreference, fourcc, fps, frameSize, params | ) -> | retval |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ open() [4/4]
virtual bool cv::VideoWriter::open |
( |
const String & | filename, |
|
|
int | fourcc, |
|
|
double | fps, |
|
|
Size | frameSize, |
|
|
bool | isColor = true ) |
|
virtual |
Python: |
---|
| cv.VideoWriter.open( | filename, fourcc, fps, frameSize[, isColor] | ) -> | retval |
| cv.VideoWriter.open( | filename, apiPreference, fourcc, fps, frameSize[, isColor] | ) -> | retval |
| cv.VideoWriter.open( | filename, fourcc, fps, frameSize, params | ) -> | retval |
| cv.VideoWriter.open( | filename, apiPreference, fourcc, fps, frameSize, params | ) -> | retval |
◆ operator<<() [1/2]
virtual VideoWriter & cv::VideoWriter::operator<< |
( |
const Mat & | image | ) |
|
|
virtual |
Stream operator to write the next video frame.
- See also
- write
◆ operator<<() [2/2]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- See also
- write
◆ release()
virtual void cv::VideoWriter::release |
( |
| ) |
|
|
virtual |
Python: |
---|
| cv.VideoWriter.release( | | ) -> | None |
◆ set()
virtual bool cv::VideoWriter::set |
( |
int | propId, |
|
|
double | value ) |
|
virtual |
Python: |
---|
| cv.VideoWriter.set( | propId, value | ) -> | retval |
Sets a property in the VideoWriter.
- Parameters
-
- Returns
true
if the property is supported by the backend used by the VideoWriter instance.
◆ write()
virtual void cv::VideoWriter::write |
( |
InputArray | image | ) |
|
|
virtual |
Python: |
---|
| cv.VideoWriter.write( | image | ) -> | None |
Writes the next video frame.
- Parameters
-
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.
◆ iwriter
Ptr<IVideoWriter> cv::VideoWriter::iwriter |
|
protected |
◆ writer
The documentation for this class was generated from the following file: