Skip to content

WriteGear API Parameters: Non-Compression Mode⚓

output⚓

This parameter sets the valid output Video filename/path for the output video.

WriteGear API will throw RuntimeError if output provided is empty or invalid.

Data-Type: String

Default Value: Its default value is 0.

Usage:

Make sure to provide valid filename with valid file-extension based on the encoder in use (default is .mp4).

Its valid input can be one of the following:

  • Path to directory: Valid path of the directory to save the output video file. In this case, WriteGear API will automatically assign a unique filename (with a default extension i.e..mp4) as follows:

    writer = WriteGear(output = '/home/foo/foo1', compression_mode=False) # Define writer 
    
  • Filename (with/without path): Valid filename(with valid extension) of the output video file. In case filename is provided without path, then current working directory will be used.

    writer = WriteGear(output = 'output.mp4', compression_mode=False) # Define writer 
    
  • GStreamer Pipeline:

    WriteGear API also supports GStreamer Pipeline as input to its output parameter in Non-Compression Mode, when GStreamer Pipeline Mode is enabled. It can be used as follows:

    Requirement for GStreamer Pipelining

    GStreamer Pipelining in WriteGear requires your OpenCV to be built with GStreamer support. Checkout this FAQ for compiling OpenCV with GStreamer support.

    New in v0.2.5

    This feature was added in v0.2.5.

    # enable GStreamer Pipeline Mode for writer
    output_params = {"-gst_pipeline_mode": True}
    # Define writer
    writer = WriteGear(
    output="appsrc ! videoconvert ! avenc_mpeg4 bitrate=100000 ! mp4mux ! filesink location=foo.mp4", compression_mode=False) 
    

 

compression_mode⚓

This parameter selects the WriteGear's Primary Mode of Operation, i.e. if this parameter is enabled (.i.e compression_mode = True) WriteGear will use FFmpeg to encode output video, and if disabled (.i.e compression_mode = False), the OpenCV's VideoWriter API will be used for encoding files/streams.

Data-Type: Boolean

Default Value: Its default value is True.

Usage:

WriteGear(output = 'output.mp4', compression_mode=False)

 

custom_ffmpeg⚓

Not supported in Non-Compression Mode!

 

output_params⚓

This parameter allows us to exploit almost all OpenCV's VideoWriter API supported parameters effortlessly and flexibly for video-encoding in Non-Compression Mode, by formatting desired FFmpeg Parameters as this parameter's attributes. All supported parameters and FOURCC codecs for compression mode discussed below:

Remember, Non-Compression mode lacks the ability to control output quality and other important features like lossless video compression, audio encoding, etc., which are available with WriteGear's Compression Mode only.

Data-Type: Dictionary

Default Value: Its default value is {}.

Supported Attributes⚓

Non-Compression Mode only gives access to a limited number of Parameters through its output_params parameter's attributes, which are as follows:

A. OpenCV Parameters⚓

WriteGear provides access to all available OpenCV's VideoWriter API parameters in Non-Compression Mode.

Parameters Description
-fourcc 4-character code of codec used to encode frames
-fps controls the framerate of output video(Default value: 25)
-backend (optional) In case of multiple backends, this parameter allows us to specify VideoWriter API's backends to use. Its valid values are CAP_FFMPEG or CAP_GSTREAMER(if enabled)
-color (optional) If it is not zero(0), the encoder will expect and encode color frames, otherwise it will work with grayscale frames (the flag is currently supported on Windows only)

-height and -width parameter are no longer supported and are automatically derived from the input frames.

B. Exclusive Parameters⚓

In addition to OpenCV Parameters, WriteGear API also provides few exclusive attribute, which are as follows:

  • -gst_pipeline_mode: a boolean attribute to enable GStreamer Pipeline Mode to supports GStreamer Pipeline as input to its output parameter in Non-Compression Mode.

    Enabling -gst_pipeline_mode will enforce -backend parameter value to "CAP_GSTREAMER"

    New in v0.2.5

    -gst_pipeline_mode attribute was added in v0.2.5.

    Its usage example can be found here ➶.

Usage:

To assign desired parameters in Non-Compression Mode, you can format it as dictionary attribute and pass through this(output_params) parameter as follows:

# format parameter as dictionary attribute
output_params = {"-fps":30} 
# and then, assign it
WriteGear(output = 'output.mp4', **output_params)

Its usage example can be found here ➶.

Supported FOURCC Codecs⚓

FOURCC is a 4-character code of the codec used to encode video in Non-Compression Mode(OpenCV's VideoWriter API) without compression.

List of all supported FOURCC codecs can found here ➶

Usage:

To select desired FOURCC codec in Non-Compression Mode, you can format it as dictionary attribute and pass through this(output_params) parameter. For example, using MJPG as codec, we can:

# format codec as dictionary attribute
output_params = {"-fourcc":"MJPG"} 
# and then, assign it
WriteGear(output = 'output.mp4', **output_params)

Its usage example can be found here ➶.

 

logging⚓

This parameter enables logging (if True), essential for debugging.

Data-Type: Boolean

Default Value: Its default value is False.

Usage:

WriteGear(output = 'output.mp4', logging=True)

 


Last update: August 24, 2022