public class VideoWriter extends Object
Modifier and Type | Field and Description |
---|---|
protected long |
nativeObj |
Modifier | Constructor and Description |
---|---|
|
VideoWriter()
Default constructors
The constructors/functions initialize video writers.
|
protected |
VideoWriter(long addr) |
|
VideoWriter(String filename,
int fourcc,
double fps,
Size frameSize) |
|
VideoWriter(String filename,
int fourcc,
double fps,
Size frameSize,
boolean isColor) |
|
VideoWriter(String filename,
int apiPreference,
int fourcc,
double fps,
Size frameSize)
The
apiPreference parameter allows to specify API backends to use. |
|
VideoWriter(String filename,
int apiPreference,
int fourcc,
double fps,
Size frameSize,
boolean isColor)
The
apiPreference parameter allows to specify API backends to use. |
Modifier and Type | Method and Description |
---|---|
static VideoWriter |
__fromPtr__(long addr) |
protected void |
finalize() |
static int |
fourcc(char c1,
char c2,
char c3,
char c4)
Concatenates 4 chars to a fourcc code
|
double |
get(int propId)
Returns the specified VideoWriter property
|
String |
getBackendName()
Returns used backend API name
Note: Stream should be opened.
|
long |
getNativeObjAddr() |
boolean |
isOpened()
Returns true if video writer has been successfully initialized.
|
boolean |
open(String filename,
int fourcc,
double fps,
Size frameSize)
Initializes or reinitializes video writer.
|
boolean |
open(String filename,
int fourcc,
double fps,
Size frameSize,
boolean isColor)
Initializes or reinitializes video writer.
|
boolean |
open(String filename,
int apiPreference,
int fourcc,
double fps,
Size frameSize) |
boolean |
open(String filename,
int apiPreference,
int fourcc,
double fps,
Size frameSize,
boolean isColor) |
void |
release()
Closes the video writer.
|
boolean |
set(int propId,
double value)
Sets a property in the VideoWriter.
|
void |
write(Mat image)
Writes the next video frame
|
protected VideoWriter(long addr)
public VideoWriter(String filename, int apiPreference, int fourcc, double fps, Size frameSize, boolean isColor)
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.filename
- automatically generatedapiPreference
- automatically generatedfourcc
- automatically generatedfps
- automatically generatedframeSize
- automatically generatedisColor
- automatically generatedpublic VideoWriter(String filename, int apiPreference, int fourcc, double fps, Size frameSize)
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.filename
- automatically generatedapiPreference
- automatically generatedfourcc
- automatically generatedfps
- automatically generatedframeSize
- automatically generatedpublic VideoWriter(String filename, int fourcc, double fps, Size frameSize, boolean isColor)
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](http://www.fourcc.org/codecs.php) page. FFMPEG backend with MP4 container natively uses
other values as fourcc code: see [ObjectType](http://www.mp4ra.org/codecs.html),
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:
fourcc=-1
pops up the codec selection dialog from the system.
img_%02d.jpg
) and fourcc=0
OR fps=0
. Use uncompressed image format (eg. img_%02d.BMP
) to save raw frames.
codec=0; fps=0;
you can create an uncompressed (raw) video file.
public VideoWriter(String filename, int fourcc, double fps, Size frameSize)
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](http://www.fourcc.org/codecs.php) page. FFMPEG backend with MP4 container natively uses
other values as fourcc code: see [ObjectType](http://www.mp4ra.org/codecs.html),
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.
will work with grayscale frames (the flag is currently supported on Windows only).
Tips:
fourcc=-1
pops up the codec selection dialog from the system.
img_%02d.jpg
) and fourcc=0
OR fps=0
. Use uncompressed image format (eg. img_%02d.BMP
) to save raw frames.
codec=0; fps=0;
you can create an uncompressed (raw) video file.
public VideoWriter()
public long getNativeObjAddr()
public static VideoWriter __fromPtr__(long addr)
public String getBackendName()
public boolean isOpened()
public boolean open(String filename, int apiPreference, int fourcc, double fps, Size frameSize, boolean isColor)
public boolean open(String filename, int apiPreference, int fourcc, double fps, Size frameSize)
public boolean open(String filename, int fourcc, double fps, Size frameSize, boolean isColor)
filename
- automatically generatedfourcc
- automatically generatedfps
- automatically generatedframeSize
- automatically generatedisColor
- automatically generatedtrue
if video writer has been successfully initialized
The method first calls VideoWriter::release to close the already opened file.public boolean open(String filename, int fourcc, double fps, Size frameSize)
filename
- automatically generatedfourcc
- automatically generatedfps
- automatically generatedframeSize
- automatically generatedtrue
if video writer has been successfully initialized
The method first calls VideoWriter::release to close the already opened file.public boolean set(int propId, double value)
propId
- Property identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY)
or one of REF: videoio_flags_othersvalue
- Value of the property.true
if the property is supported by the backend used by the VideoWriter instance.public double get(int propId)
propId
- Property identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY)
or one of REF: videoio_flags_otherspublic static int fourcc(char c1, char c2, char c3, char c4)
c1
- automatically generatedc2
- automatically generatedc3
- automatically generatedc4
- automatically generatedpublic void release()
public void write(Mat image)
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.Copyright © 2020. All rights reserved.