Table of Contents

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

fileName string

Name of the output video file.

fourcc FourCC

4-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.

fps double

Frame rate of the created video stream.

frameSize Size

Size of video frames.

prms VideoWriterPara

Parameters 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

fileName string

Name of the output video file.

fourcc FourCC

4-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.

fps double

Frame rate of the created video stream.

frameSize Size

Size of video frames.

isColor bool

If 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

fileName string

Name of the output video file.

fourcc FourCC

4-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.

fps double

Frame rate of the created video stream.

frameSize Size

Size of video frames.

prms int[]

The params parameter 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

fileName string

Name of the output video file.

apiPreference VideoCaptureAPIs

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.

fourcc FourCC

4-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.

fps double

Frame rate of the created video stream.

frameSize Size

Size of video frames.

prms VideoWriterPara

Parameters 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

fileName string

Name of the output video file.

apiPreference VideoCaptureAPIs

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.

fourcc FourCC

4-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.

fps double

Frame rate of the created video stream.

frameSize Size

Size of video frames.

isColor bool

If 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

fileName string

Name of the output video file.

apiPreference VideoCaptureAPIs

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.

fourcc FourCC

4-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.

fps double

Frame rate of the created video stream.

frameSize Size

Size of video frames.

prms int[]

The params parameter 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

string

Fps

Frames per second of the output video

public double Fps { get; }

Property Value

double

FrameSize

Get size of frame image

public Size FrameSize { get; }

Property Value

Size

IsColor

Get whether output frames is color or not

public bool IsColor { get; }

Property Value

bool

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

c1 char
c2 char
c3 char
c4 char

Returns

int

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

code string

Returns

int

Get(VideoWriterProperties)

Returns the specified VideoWriter property

public double Get(VideoWriterProperties propId)

Parameters

propId VideoWriterProperties

Property 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

string

IsOpened()

Returns true if video writer has been successfully initialized.

public bool IsOpened()

Returns

bool

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

fileName string

Name of the output video file.

fourcc FourCC

4-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.

fps double

Frame rate of the created video stream.

frameSize Size

Size of video frames.

isColor bool

If 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

bool

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

fileName string

Name of the output video file.

apiPreference VideoCaptureAPIs

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.

fourcc FourCC

4-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.

fps double

Frame rate of the created video stream.

frameSize Size

Size of video frames.

isColor bool

If 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

bool

Release()

public void Release()

Set(VideoWriterProperties, double)

Sets a property in the VideoWriter.

public bool Set(VideoWriterProperties propId, double value)

Parameters

propId VideoWriterProperties

Property identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY) or one of @ref videoio_flags_others

value double

Value of the property.

Returns

bool

true if 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

image InputArray

the written frame.