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 fourcc,
double fps,
Size frameSize,
MatOfInt params)
The
params parameter allows to specify extra encoder parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... |
|
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. |
|
VideoWriter(String filename,
int apiPreference,
int fourcc,
double fps,
Size frameSize,
MatOfInt params) |
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 fourcc,
double fps,
Size frameSize,
MatOfInt params) |
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) |
boolean |
open(String filename,
int apiPreference,
int fourcc,
double fps,
Size frameSize,
MatOfInt params) |
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()
public 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
[MSDN](https://docs.microsoft.com/en-us/windows/win32/medfound/video-fourccs) page
or with this [page](https://fourcc.org/codecs.php)
of the fourcc site for a more complete list). FFMPEG backend with MP4 container natively uses
other values as fourcc code: see [ObjectType](http://mp4ra.org/#/codecs),
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:
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
[MSDN](https://docs.microsoft.com/en-us/windows/win32/medfound/video-fourccs) page
or with this [page](https://fourcc.org/codecs.php)
of the fourcc site for a more complete list). FFMPEG backend with MP4 container natively uses
other values as fourcc code: see [ObjectType](http://mp4ra.org/#/codecs),
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.
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 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, MatOfInt params)
params
parameter allows to specify extra encoder parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .)
see cv::VideoWriterPropertiesfilename
- automatically generatedfourcc
- automatically generatedfps
- automatically generatedframeSize
- automatically generatedparams
- automatically generatedpublic long getNativeObjAddr()
public static VideoWriter __fromPtr__(long addr)
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 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 apiPreference, int fourcc, double fps, Size frameSize, MatOfInt params)
public boolean isOpened()
public 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.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 String getBackendName()
Copyright © 2024. All rights reserved.