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
, or1
, or2
etc. as follows: -
Filepath (string): Valid path of the video file, for e.g
"/home/foo.mp4"
as follows: -
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 ➶
-
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: -
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:Be sure convert video output into BGR colorspace before pipelining as follows:
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 ➶
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 ➶
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:
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:
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: