Class cv::VideoWriter#
Video writer class. View details
#include <opencv2/videoio.hpp>Collaboration diagram for cv::VideoWriter:
Detailed Description#
Video writer class.
The class provides C++ API for writing video files or image sequences.
Constructor & Destructor Documentation#
VideoWriter()#
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()#
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()#
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()#
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()#
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. Tips:
With some backends
fourcc=-1pops up the codec selection dialog from the system.To save image sequence use a proper filename (eg.
img_%02d.jpg) andfourcc=0ORfps=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.
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.
~VideoWriter()#
cv::VideoWriter::~VideoWriter()
Default destructor.
The method first calls VideoWriter::release to close the already opened file.
Member Function Documentation#
get()#
double cv::VideoWriter::get(int propId)
Python:
cv.VideoWriter.get(propId) -> retval
Returns the specified VideoWriter property.
Parameters
propId— Property identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY) or one of Additional flags for video I/O API backends
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()
Python:
cv.VideoWriter.getBackendName() -> retval
Returns used backend API name.
Note
Stream should be opened.
isOpened()#
bool cv::VideoWriter::isOpened()
Python:
cv.VideoWriter.isOpened() -> retval
Returns true if video writer has been successfully initialized.
open()#
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()#
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()#
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()#
bool cv::VideoWriter::open(
const String & filename,
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
Initializes or reinitializes video writer.
The method opens video writer. Parameters are the same as in the constructor VideoWriter::VideoWriter. The method first calls VideoWriter::release to close the already opened file.
Returns
true if video writer has been successfully initialized
operator<<()#
VideoWriter & cv::VideoWriter::operator<<(const Mat & image)
Stream operator to write the next video frame.
See also
operator<<()#
VideoWriter & cv::VideoWriter::operator<<(const UMat & image)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
See also
release()#
void cv::VideoWriter::release()
Python:
cv.VideoWriter.release()
Closes the video writer.
The method is automatically called by subsequent VideoWriter::open and by the VideoWriter destructor.
set()#
bool cv::VideoWriter::set(
int propId,
double value )
Python:
cv.VideoWriter.set(propId, value) -> retval
Sets a property in the VideoWriter.
Parameters
propId— Property identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY) or one of Additional flags for video I/O API backendsvalue— Value of the property.
Returns
true if the property is supported by the backend used by the VideoWriter instance.
write()#
bool cv::VideoWriter::write(InputArray image)
Python:
cv.VideoWriter.write(image) -> retval
Writes the next video frame.
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.
Parameters
image— The written frame. In general, color images are expected in BGR format.
Returns
true if the frame was written successfully by the underlying backend, false otherwise (for example, on network errors when streaming, encoder failures, or unsupported input frames). Backends that do not surface per-frame status from their native API report true on best-effort success.
fourcc()#
static int cv::VideoWriter::fourcc(
char c1,
char c2,
char c3,
char c4 )
Python:
cv.VideoWriter.fourcc(c1, c2, c3, c4) -> retval
cv.VideoWriter_fourcc(c1, c2, c3, c4) -> retval
Concatenates 4 chars to a fourcc code.
This static method constructs the fourcc code of the codec to be used in the constructor VideoWriter::VideoWriter or VideoWriter::open.
Returns
a fourcc code
create()#
static Ptr< IVideoWriter > cv::VideoWriter::create(
const String & filename,
int fourcc,
double fps,
Size frameSize,
bool isColor = true )
Member Data Documentation#
iwriter#
Ptr< IVideoWriter > cv::VideoWriter::iwriter
Source file#
The documentation for this class was generated from the following file:
opencv2/videoio.hpp