Module Opencv.Video_writer

type t
val video_writer1 : unit -> t

Usage: video_writer1 ()

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.
val video_writer2 : ?⁠is_color:bool -> string -> int -> float -> size2i -> t

Usage: video_writer2 ?is_color filename fourcc fps frame_size

  • Parameter: filename: Name of the output video file.
  • Parameter: 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://mp4ra.org/#/codecs), so you may receive a warning message from OpenCV about fourcc code conversion.
  • Parameter: fps: Framerate of the created video stream.
  • Parameter: frame_size: Size of the video frames.
  • Parameter: is_color: If it is not zero, the encoder will expect and encode color frames, otherwise it will work with grayscale frames.

Tips:

  • With some backends fourcc=-1 pops up the codec selection dialog from the system.
  • To save image sequence use a proper filename (eg. img_%02d.jpg) and fourcc=0 OR fps=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.
val video_writer3 : ?⁠is_color:bool -> string -> int -> int -> float -> size2i -> t

Usage: video_writer3 ?is_color filename api_preference fourcc fps frame_size

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

val video_writer4 : string -> int -> float -> size2i -> int list -> t

Usage: video_writer4 filename fourcc fps frame_size params

* The params parameter allows to specify extra encoder parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) * see cv::VideoWriterProperties

val video_writer5 : string -> int -> int -> float -> size2i -> int list -> t

Usage: video_writer5 filename api_preference fourcc fps frame_size params

val open1 : ?⁠is_color:bool -> t -> string -> int -> float -> size2i -> bool

Usage: open1 ?is_color __self filename fourcc fps frame_size

Initializes or reinitializes video writer.

The method opens video writer. Parameters are the same as in the constructor VideoWriter::VideoWriter.

  • Returns: true if video writer has been successfully initialized

The method first calls VideoWriter::release to close the already opened file.

val open2 : ?⁠is_color:bool -> t -> string -> int -> int -> float -> size2i -> bool

Usage: open2 ?is_color __self filename api_preference fourcc fps frame_size

val open3 : t -> string -> int -> float -> size2i -> int list -> bool

Usage: open3 __self filename fourcc fps frame_size params

val open4 : t -> string -> int -> int -> float -> size2i -> int list -> bool

Usage: open4 __self filename api_preference fourcc fps frame_size params

val is_opened : t -> bool

Usage: is_opened __self

Returns true if video writer has been successfully initialized.

val release : t -> unit

Usage: release __self

Closes the video writer.

The method is automatically called by subsequent VideoWriter::open and by the VideoWriter destructor.

val write : t -> Cvdata.t -> unit

Usage: write __self image

Writes the next video frame

  • Parameter: 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.

val set : t -> int -> float -> bool

Usage: set __self prop_id value

Sets a property in the VideoWriter.

  • Parameter: prop_id: Property identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY) or one of videoio_flags_others
  • Parameter: value: Value of the property.
  • Returns: true if the property is supported by the backend used by the VideoWriter instance.
val get : t -> int -> float

Usage: get __self prop_id

Returns the specified VideoWriter property

  • Parameter: prop_id: Property identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY) or one of videoio_flags_others
  • Returns: 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.
val fourcc : char -> char -> char -> char -> int

Usage: fourcc c1 c2 c3 c4

Concatenates 4 chars to a fourcc code

  • Returns: a fourcc code

This static method constructs the fourcc code of the codec to be used in the constructor VideoWriter::VideoWriter or VideoWriter::open.

val get_backend_name : t -> string

Usage: get_backend_name __self

Returns used backend API name

Note: Stream should be opened.