Class VideoWriter
- Namespace
- OpenCvSharp
- Assembly
- OpenCvSharp.dll
AVI Video File Writer
public class VideoWriter : DisposableCvObject, IDisposable, ICvPtrHolder
- Inheritance
-
VideoWriter
- Implements
- Inherited Members
Constructors
VideoWriter()
public VideoWriter()
VideoWriter(string, FourCC, double, Size, VideoWriterPara)
Creates video writer structure.
public VideoWriter(string fileName, FourCC fourcc, double fps, Size frameSize, VideoWriterPara prms)
Parameters
fileNamestringName of the output video file.
fourccFourCC4-character code of codec used to compress the frames. For example, "PIM1" is MPEG-1 codec, "MJPG" is motion-jpeg codec etc. Under Win32 it is possible to pass null in order to choose compression method and additional compression parameters from dialog.
fpsdoubleFrame rate of the created video stream.
frameSizeSizeSize of video frames.
prmsVideoWriterParaParameters of VideoWriter for hardware acceleration
VideoWriter(string, FourCC, double, Size, bool)
Creates video writer structure.
public VideoWriter(string fileName, FourCC fourcc, double fps, Size frameSize, bool isColor = true)
Parameters
fileNamestringName of the output video file.
fourccFourCC4-character code of codec used to compress the frames. For example, "PIM1" is MPEG-1 codec, "MJPG" is motion-jpeg codec etc. Under Win32 it is possible to pass null in order to choose compression method and additional compression parameters from dialog.
fpsdoubleFrame rate of the created video stream.
frameSizeSizeSize of video frames.
isColorboolIf it is true, the encoder will expect and encode color frames, otherwise it will work with grayscale frames (the flag is currently supported on Windows only).
VideoWriter(string, FourCC, double, Size, int[])
Creates video writer structure.
public VideoWriter(string fileName, FourCC fourcc, double fps, Size frameSize, int[] prms)
Parameters
fileNamestringName of the output video file.
fourccFourCC4-character code of codec used to compress the frames. For example, "PIM1" is MPEG-1 codec, "MJPG" is motion-jpeg codec etc. Under Win32 it is possible to pass null in order to choose compression method and additional compression parameters from dialog.
fpsdoubleFrame rate of the created video stream.
frameSizeSizeSize of video frames.
prmsint[]The
paramsparameter allows to specify extra encoder parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) see cv::VideoWriterProperties
VideoWriter(string, VideoCaptureAPIs, FourCC, double, Size, VideoWriterPara)
Creates video writer structure.
public VideoWriter(string fileName, VideoCaptureAPIs apiPreference, FourCC fourcc, double fps, Size frameSize, VideoWriterPara prms)
Parameters
fileNamestringName of the output video file.
apiPreferenceVideoCaptureAPIsallows 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.
fourccFourCC4-character code of codec used to compress the frames. For example, "PIM1" is MPEG-1 codec, "MJPG" is motion-jpeg codec etc. Under Win32 it is possible to pass null in order to choose compression method and additional compression parameters from dialog.
fpsdoubleFrame rate of the created video stream.
frameSizeSizeSize of video frames.
prmsVideoWriterParaParameters of VideoWriter for hardware acceleration
VideoWriter(string, VideoCaptureAPIs, FourCC, double, Size, bool)
Creates video writer structure.
public VideoWriter(string fileName, VideoCaptureAPIs apiPreference, FourCC fourcc, double fps, Size frameSize, bool isColor = true)
Parameters
fileNamestringName of the output video file.
apiPreferenceVideoCaptureAPIsallows 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.
fourccFourCC4-character code of codec used to compress the frames. For example, "PIM1" is MPEG-1 codec, "MJPG" is motion-jpeg codec etc. Under Win32 it is possible to pass null in order to choose compression method and additional compression parameters from dialog.
fpsdoubleFrame rate of the created video stream.
frameSizeSizeSize of video frames.
isColorboolIf it is true, the encoder will expect and encode color frames, otherwise it will work with grayscale frames (the flag is currently supported on Windows only).
VideoWriter(string, VideoCaptureAPIs, FourCC, double, Size, int[])
Creates video writer structure.
public VideoWriter(string fileName, VideoCaptureAPIs apiPreference, FourCC fourcc, double fps, Size frameSize, int[] prms)
Parameters
fileNamestringName of the output video file.
apiPreferenceVideoCaptureAPIsallows 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.
fourccFourCC4-character code of codec used to compress the frames. For example, "PIM1" is MPEG-1 codec, "MJPG" is motion-jpeg codec etc. Under Win32 it is possible to pass null in order to choose compression method and additional compression parameters from dialog.
fpsdoubleFrame rate of the created video stream.
frameSizeSizeSize of video frames.
prmsint[]The
paramsparameter allows to specify extra encoder parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) see cv::VideoWriterProperties
Properties
FileName
Get output video file name
public string? FileName { get; }
Property Value
Fps
Frames per second of the output video
public double Fps { get; }
Property Value
FrameSize
Get size of frame image
public Size FrameSize { get; }
Property Value
IsColor
Get whether output frames is color or not
public bool IsColor { get; }
Property Value
Methods
DisposeUnmanaged()
Releases unmanaged resources
protected override void DisposeUnmanaged()
FourCC(char, char, char, char)
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.
public static int FourCC(char c1, char c2, char c3, char c4)
Parameters
Returns
FourCC(string)
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.
public static int FourCC(string code)
Parameters
codestring
Returns
Get(VideoWriterProperties)
Returns the specified VideoWriter property
public double Get(VideoWriterProperties propId)
Parameters
propIdVideoWriterPropertiesProperty identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY) or one of @ref videoio_flags_others
Returns
- double
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 that stream should be opened.
public string GetBackendName()
Returns
IsOpened()
Returns true if video writer has been successfully initialized.
public bool IsOpened()
Returns
Open(string, FourCC, double, Size, bool)
Creates video writer structure.
public bool Open(string fileName, FourCC fourcc, double fps, Size frameSize, bool isColor = true)
Parameters
fileNamestringName of the output video file.
fourccFourCC4-character code of codec used to compress the frames. For example, "PIM1" is MPEG-1 codec, "MJPG" is motion-jpeg codec etc. Under Win32 it is possible to pass null in order to choose compression method and additional compression parameters from dialog.
fpsdoubleFrame rate of the created video stream.
frameSizeSizeSize of video frames.
isColorboolIf it is true, the encoder will expect and encode color frames, otherwise it will work with grayscale frames (the flag is currently supported on Windows only).
Returns
Open(string, VideoCaptureAPIs, FourCC, double, Size, bool)
Creates video writer structure.
public bool Open(string fileName, VideoCaptureAPIs apiPreference, FourCC fourcc, double fps, Size frameSize, bool isColor = true)
Parameters
fileNamestringName of the output video file.
apiPreferenceVideoCaptureAPIsallows 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.
fourccFourCC4-character code of codec used to compress the frames. For example, "PIM1" is MPEG-1 codec, "MJPG" is motion-jpeg codec etc. Under Win32 it is possible to pass null in order to choose compression method and additional compression parameters from dialog.
fpsdoubleFrame rate of the created video stream.
frameSizeSizeSize of video frames.
isColorboolIf it is true, the encoder will expect and encode color frames, otherwise it will work with grayscale frames (the flag is currently supported on Windows only).
Returns
Release()
public void Release()
Set(VideoWriterProperties, double)
Sets a property in the VideoWriter.
public bool Set(VideoWriterProperties propId, double value)
Parameters
propIdVideoWriterPropertiesProperty identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY) or one of @ref videoio_flags_others
valuedoubleValue of the property.
Returns
- bool
trueif the property is supported by the backend used by the VideoWriter instance.
Write(InputArray)
Writes/appends one frame to video file.
public void Write(InputArray image)
Parameters
imageInputArraythe written frame.