VideoGear API Usage Examples:¶
After going through following Usage Examples, Checkout more of its advanced configurations here âž¶
Bare-Minimum Usage with CamGear backend¶
VideoGear by default provides direct internal access to CamGear API. Explicitly select it with api=Backend.CAMGEAR.
Following is the bare-minimum code you need to access CamGear API with VideoGear:
Bare-Minimum Usage with FFGear backend¶
Select FFGear backend with api=Backend.FFGEAR to access FFGear API for hardware-accelerated FFmpeg-powered decoding.
Following is the bare-minimum code you need to access FFGear API with VideoGear:
FFGear Backend requires the deffcode library
FFGear API MUST have the deffcode library installed, along with a valid FFmpeg executable. Any failure in detection will raise ImportError/RuntimeError immediately.
Install via pip:
For FFmpeg installation, see FFmpeg Installation âž¶
FFGear API Backend does not support colorspace or time_delay parameters. Use its options dict for advanced FFmpeg configuration.
Bare-Minimum Usage with PiGear backend¶
Select PiGear backend with api=Backend.PIGEAR to access PiGear API.
Following is the bare-minimum code you need to access PiGear API with VideoGear:
Under the hood, PiGear API (version 0.3.3 onwards) prioritizes the new picamera2 API backend.
However, PiGear API seamlessly switches to the legacy picamera backend, if the picamera2 library is unavailable or not installed.
It is advised to enable logging(logging=True) to see which backend is being used.
The picamera library is built on the legacy camera stack that is NOT (and never has been) supported on 64-bit OS builds.
You could also enforce the legacy picamera API backend in PiGear by using the enforce_legacy_picamera user-defined optional parameter boolean attribute.
Make sure to complete Raspberry Pi Camera Hardware-specific settings prior using this API, otherwise nothing will work.
Using VideoGear with Video Stabilizer backend¶
VideoGear API provides a special internal wrapper around VidGear's Exclusive Video Stabilizer class and provides easy way of activating stabilization for various video-streams (real-time or not) with its stabilize boolean parameter during initialization.
The usage example is as follows:
For a more detailed information on Video-Stabilizer Class, Read here âž¶
The stabilizer might be slower for High-Quality/Resolution videos-frames.
New in v0.3.6
The Kalman backend (StabilizerMode.KALMAN) was added in v0.3.6.
Kalman backend stabilizes every frame immediately, with no SMOOTHING_RADIUS frames of startup delay or lag. Ideal for live streams.
Advanced VideoGear usage with CamGear Backend¶
VideoGear provides internal access to CamGear, PiGear, and FFGear APIs, and thereby all additional parameters of each backend are also easily accessible within VideoGear API.
The usage example of VideoGear API with Variable Camera Properties is as follows:
This example demonstrates how to use the VideoGear API in a similar manner to the CamGear's example for controlling variable source properties. Any CamGear usage example can be implemented using the VideoGear API in a similar way.
All the supported Source Tweak Parameters can be found here âž¶
Advanced VideoGear usage with PiGear Backend¶
VideoGear provides internal access to both CamGear and PiGear APIs, and thereby all additional parameters of PiGear API or CamGear API are also easily accessible within VideoGear API.
The usage example of VideoGear API with Variable Camera Properties is as follows:
This example demonstrates how to use the VideoGear API in a similar manner to the PiGear's example for using variable camera properties. Any PiGear usage example can be implemented using the VideoGear API in a similar way.
Backend PiGear API now fully supports the newer picamera2 python library under the hood for Raspberry Pi camera modules. Follow this guide âž¶ for its installation.
Make sure to complete Raspberry Pi Camera Hardware-specific settings prior using this backend, otherwise nothing will work.
Under the hood, Backend PiGear API (version 0.3.3 onwards) prioritizes the new picamera2 API backend.
However, the API seamlessly switches to the legacy picamera backend, if the picamera2 library is unavailable or not installed.
It is advised to enable logging(logging=True) to see which backend is being used.
The picamera library is built on the legacy camera stack that is NOT (and never has been) supported on 64-bit OS builds.
You could also enforce the legacy picamera API backend in PiGear by using the enforce_legacy_picamera user-defined optional parameter boolean attribute.
Advanced VideoGear usage with FFGear Backend¶
FFGear Backend requires the deffcode library
FFGear API MUST have the deffcode library installed, along with a valid FFmpeg executable. Any failure in detection will raise ImportError/RuntimeError immediately.
Install via pip:
For FFmpeg installation, see FFmpeg Installation âž¶
The usage example below demonstrates hardware-accelerated decoding and stabilization together using the FFGear backend:
This example demonstrates how to use the VideoGear API in a similar manner to the FFGear's NVIDIA CUVID Decoding example. Any FFGear usage example can be implemented using the VideoGear API in a similar way.
For hardware-accelerated decoding options (CUDA/CUVID etc.) and advanced FFmpeg filter pipelines, see FFGear Hardware-Accelerated Decoding âž¶
Advanced VideoGear usage with Stabilizer Backend¶
New in v0.3.5
The STABILIZER_MODE option and the StabilizerMode enum were added in v0.3.5. Omitting STABILIZER_MODE keeps the previous behavior — VideoGear defaults to StabilizerMode.ASW.
When stabilization is enabled, VideoGear forwards Stabilizer parameters via the options dictionary:
For zero-latency real-time stabilization, switch to the Kalman backend with PROCESS_NOISE/MEASUREMENT_NOISE tuning instead of SMOOTHING_RADIUS:
Non-StabilizerMode values passed via STABILIZER_MODE silently fall back to StabilizerMode.ASW.
Using VideoGear with Colorspace Manipulation¶
VideoGear API also supports Colorspace Manipulation but NOT Direct like other VideoCapture Gears.
Important: color_space global variable is NOT Supported in VideoGear API
color_spaceglobal variable is NOT Supported in VideoGear API, calling it will result inAttribueError. More details can be found here âž¶- Any incorrect or None-type value on
colorspaceparameter will be skipped automatically.
FFGear API Backend does not support colorspace parameter. See this âž¶ for source pixel-format conversions.
In following example code, we will convert source colorspace to HSV on initialization:
Bonus Examples¶
Checkout more advanced VideoGear examples with unusual configuration here âž¶