Skip to content

CamGear API Parameters

source

CamGear API will throw RuntimeError if source provided is invalid.

This parameter defines the source for the input stream.

Data-Type: Based on input.

Default Value: Its default value is 0.

Its valid input can be one of the following:

  • Index (integer): Valid index of the connected video device, for e.g 0, or 1, or 2 etc. as follows:

    CamGear(source=0)
    
  • Filepath (string): Valid path of the video file, for e.g "/home/foo.mp4" as follows:

    CamGear(source='/home/foo.mp4')
    
  • Streaming Services URL Address (string): Valid Video URL as input when Stream Mode is enabled(i.e. stream_mode=True):

    CamGear internally implements yt_dlp backend class for pipelining live video-frames and metadata from various streaming services. For example Twitch URL can be used as follows:

    Supported Streaming Websites

    The complete list of all supported Streaming Websites URLs can be found here ➶

    CamGear(source='https://www.twitch.tv/shroud', stream_mode=True)
    
  • Network Address (string): Valid (http(s), rtp, rtsp, rtmp, mms, etc.) incoming network stream address such as 'rtsp://192.168.31.163:554/' as input:

    CamGear(source='rtsp://192.168.31.163:554/')
    
  • GStreamer Pipeline:

    CamGear API also supports GStreamer Pipeline.

    Requirements for GStreamer Pipelining

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

    Thereby, You can easily check GStreamer support by running print(cv2.getBuildInformation()) python command and see if output contains something similar as follows:

    Video I/O:
    ...
         GStreamer:                   YES (ver 1.8.3)
    ...
    

    Be sure convert video output into BGR colorspace before pipelining as follows:

    CamGear(source='udpsrc port=5000 ! application/x-rtp,media=video,payload=96,clock-rate=90000,encoding-name=H264, ! rtph264depay ! decodebin ! videoconvert ! video/x-raw, format=BGR ! appsink')
    

 

stream_mode

This parameter controls the Stream Mode, .i.e if enabled(stream_mode=True), the CamGear API will interpret the given source input as YouTube URL address.

Due to a FFmpeg bug that causes video to freeze frequently in OpenCV, It is advised to always use GStreamer backend for any livestream videos. Checkout this FAQ for compiling OpenCV with GStreamer support.

Data-Type: Boolean

Default Value: Its default value is False.

Usage:

Supported Streaming Websites

The complete list of all supported Streaming Websites URLs can be found here ➶

CamGear(source='https://youtu.be/bvetuLwJIkA', stream_mode=True)

Its complete usage example is given here ➶.

 

colorspace

This parameter selects the colorspace of the input stream.

Data-Type: String

Default Value: Its default value is None.

Usage:

All supported colorspace values are given here ➶

CamGear(source=0, colorspace="COLOR_BGR2HSV")

Its complete usage example is given here ➶

 

backend

This parameter manually selects the backend for OpenCV's VideoCapture class (only if specified).

Data-Type: Integer

Default Value: Its default value is 0

Usage:

All supported backends are listed here ➶

Its value can be for e.g. backend = cv2.CAP_DSHOW for selecting Direct Show as backend:

CamGear(source=0, backend = cv2.CAP_DSHOW)

 

options

This parameter provides the ability to alter various Source Tweak Parameters available within OpenCV's VideoCapture API properties.

Data-Type: Dictionary

Default Value: Its default value is {}

Usage:

All supported parameters are listed here ➶

The desired parameters can be passed to CamGear API by formatting them as this parameter's attributes, as follows:

# formatting parameters as dictionary attributes
options = {"CAP_PROP_FRAME_WIDTH":320, "CAP_PROP_FRAME_HEIGHT":240, "CAP_PROP_FPS":60}
# assigning it
CamGear(source=0, **options)

 

logging

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

Data-Type: Boolean

Default Value: Its default value is False.

Usage:

CamGear(source=0, logging=True)

 

time_delay

This parameter set the time delay (in seconds) before the CamGear API start reading the frames. This delay is only required if the source required some warm-up delay before starting up.

Data-Type: Integer

Default Value: Its default value is 0.

Usage:

CamGear(source=0, time_delay=1) # set 1 seconds time delay