VideoWriter
import { VideoWriter } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
Native object: release it with using or delete(). Factories can return null; check before calling methods.
example: samples/cpp/tutorial_code/videoio/video-write/video-write.cpp
Check tutorial_video_write "the corresponding tutorial" for more details
example: samples/cpp/videowriter.cpp
An example using VideoCapture and VideoWriter class
Video writer class.
The class provides C++ API for writing video files or image sequences.
Constructors and members
static new
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.
new(filename: EmbindString, apiPreference: number, fourcc: number, fps: number, frameSize: Size, isColor: boolean): VideoWriter;4 available overloads
new(): VideoWriter;new(filename: EmbindString, fourcc: number, fps: number, frameSize: Size): VideoWriter;new(filename: EmbindString, fourcc: number, fps: number, frameSize: Size, isColor: boolean): VideoWriter;new(filename: EmbindString, apiPreference: number, fourcc: number, fps: number, frameSize: Size, isColor: boolean): VideoWriter;filenameName of the output video file.
fourcc4-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.
fpsFramerate of the created video stream.
frameSizeSize of the video frames.
isColorIf it is not zero, the encoder will expect and encode color frames, otherwise it will work with grayscale frames.
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.
- With some backends
apiPreferenceapi preference argument (number).
The VideoWriter result.
Upstream declaration ↗Upstream declaration 2 ↗Upstream declaration 3 ↗
static from2
Create an owned VideoWriter instance with the supplied configuration.
example: samples/cpp/tutorial_code/videoio/video-write/video-write.cpp
Check tutorial_video_write "the corresponding tutorial" for more details
example: samples/cpp/videowriter.cpp
An example using VideoCapture and VideoWriter class
Video writer class.
from2(_0: EmbindString, _1: number, _2: number, _3: number, _4: Size): VideoWriter | null;_00 argument (EmbindString).
_11 argument (number).
_22 argument (number).
_33 argument (number).
_44 argument (Size).
The VideoWriter | null result.
static from3
Create an owned VideoWriter instance with the supplied configuration.
example: samples/cpp/tutorial_code/videoio/video-write/video-write.cpp
Check tutorial_video_write "the corresponding tutorial" for more details
example: samples/cpp/videowriter.cpp
An example using VideoCapture and VideoWriter class
Video writer class.
from3(_0: EmbindString, _1: number, _2: number, _3: Size, _4: IntVector): VideoWriter | null;_00 argument (EmbindString).
_11 argument (number).
_22 argument (number).
_33 argument (Size).
_44 argument (IntVector).
The VideoWriter | null result.
static from4
Create an owned VideoWriter instance with the supplied configuration.
example: samples/cpp/tutorial_code/videoio/video-write/video-write.cpp
Check tutorial_video_write "the corresponding tutorial" for more details
example: samples/cpp/videowriter.cpp
An example using VideoCapture and VideoWriter class
Video writer class.
from4(_0: EmbindString, _1: number, _2: number, _3: number, _4: Size, _5: IntVector): VideoWriter | null;_00 argument (EmbindString).
_11 argument (number).
_22 argument (number).
_33 argument (number).
_44 argument (Size).
_55 argument (IntVector).
The VideoWriter | null result.
static fourcc
Concatenates 4 chars to a fourcc code
fourcc(c1: number, c2: number, c3: number, c4: number): number;c1c1 argument (number).
c2c2 argument (number).
c3c3 argument (number).
c4c4 argument (number).
a fourcc code
This static method constructs the fourcc code of the codec to be used in the constructor VideoWriter::VideoWriter or VideoWriter::open.
clone
Create another handle to the same native object. This retains the object without copying its pixels or algorithm state; dispose both handles separately.
clone(): this;The this result.
open
Initializes or reinitializes video writer.
The method opens video writer. Parameters are the same as in the constructor
VideoWriter::VideoWriter.
open(filename: EmbindString, fourcc: number, fps: number, frameSize: Size, isColor: boolean): boolean;2 available overloads
open(filename: EmbindString, fourcc: number, fps: number, frameSize: Size): boolean;open(filename: EmbindString, fourcc: number, fps: number, frameSize: Size, isColor: boolean): boolean;filenamefilename argument (EmbindString).
fourccfourcc argument (number).
fpsfps argument (number).
frameSizeframe size argument (Size).
isColoris color argument (boolean).
true if video writer has been successfully initialized
The method first calls VideoWriter::release to close the already opened file.
open1
Initializes or reinitializes video writer.
The method opens video writer. Parameters are the same as in the constructor
VideoWriter::VideoWriter.
open1(filename: EmbindString, apiPreference: number, fourcc: number, fps: number, frameSize: Size, isColor: boolean): boolean;2 available overloads
open1(filename: EmbindString, apiPreference: number, fourcc: number, fps: number, frameSize: Size): boolean;open1(filename: EmbindString, apiPreference: number, fourcc: number, fps: number, frameSize: Size, isColor: boolean): boolean;filenamefilename argument (EmbindString).
apiPreferenceapi preference argument (number).
fourccfourcc argument (number).
fpsfps argument (number).
frameSizeframe size argument (Size).
isColoris color argument (boolean).
true if video writer has been successfully initialized
The method first calls VideoWriter::release to close the already opened file.
open2
Initializes or reinitializes video writer.
The method opens video writer. Parameters are the same as in the constructor
VideoWriter::VideoWriter.
open2(filename: EmbindString, fourcc: number, fps: number, frameSize: Size, params: IntVector): boolean;filenamefilename argument (EmbindString).
fourccfourcc argument (number).
fpsfps argument (number).
frameSizeframe size argument (Size).
paramsparams argument (IntVector).
true if video writer has been successfully initialized
The method first calls VideoWriter::release to close the already opened file.
open3
Initializes or reinitializes video writer.
The method opens video writer. Parameters are the same as in the constructor
VideoWriter::VideoWriter.
open3(filename: EmbindString, apiPreference: number, fourcc: number, fps: number, frameSize: Size, params: IntVector): boolean;filenamefilename argument (EmbindString).
apiPreferenceapi preference argument (number).
fourccfourcc argument (number).
fpsfps argument (number).
frameSizeframe size argument (Size).
paramsparams argument (IntVector).
true if video writer has been successfully initialized
The method first calls VideoWriter::release to close the already opened file.
isOpened
Returns true if video writer has been successfully initialized.
isOpened(): boolean;The boolean result.
release
Closes the video writer.
The method is automatically called by subsequent VideoWriter::open and by the VideoWriter
destructor.
release(): void;write
Writes the next video frame
write(image: Mat): boolean;imageThe 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.
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.
set
Sets a property in the VideoWriter.
set(propId: number, value: number): boolean;propIdProperty identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY) or one of
videoio_flags_othersvalueValue of the property.
true if the property is supported by the backend used by the VideoWriter instance.
get
Returns the specified VideoWriter property
get(propId: number): number;propIdProperty identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY) or one of
videoio_flags_others
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
Returns used backend API name
Note: Stream should be opened.
getBackendName(): string;The string result.
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.