Skip to content

WebGear_RTC API Usage Examples:⚓


Installation with Asyncio Support⚓

WebGear_RTC API is the part of asyncio package of VidGear, thereby you need to install VidGear with asyncio support as follows:

pip install vidgear[asyncio]


Must Required with WebGear_RTC API. You can easily install it via pip:

Microsoft Visual C++ 14.0 is required.

Installing aiortc on windows requires Microsoft Build Tools for Visual C++ libraries installed. You can easily fix this error by installing any ONE of these choices:

While the error is calling for VC++ 14.0 - but newer versions of Visual C++ libraries works as well.

Afterwards, Select: Workloads → Desktop development with C++, then for Individual Components, select only:

  • Windows 10 SDK
  • C++ x64/x86 build tools

Finally, proceed installing aiortc via pip.

  pip install aiortc

ASGI Server⚓

You'll also need to install an ASGI Server to run following WebGear_RTC usage examples, and by default WebGear_RTC ships the state-of-the-art uvicorn Server. But you can also use other ASGI server such as daphne, or hypercorn with it.


Bare-Minimum Usage⚓

Let's implement a Bare-Minimum usage example:

Running Programmatically⚓

You can access and run WebGear_RTC VideoStreamer Server programmatically in your python script in just a few lines of code, as follows:

For accessing WebGear_RTC on different Client Devices on the network, use "" as host value instead of "localhost" on Host Machine. More information can be found here ➶

We are using frame_size_reduction attribute for frame size reduction (in percentage) to be streamed with its options dictionary parameter to cope with performance-throttling in this example.

# import required libraries
import uvicorn
from vidgear.gears.asyncio import WebGear_RTC

# various performance tweaks
options = {
    "frame_size_reduction": 25,

# initialize WebGear_RTC app
web = WebGear_RTC(source="foo.mp4", logging=True, **options)

# run this app on Uvicorn server at address http://localhost:8000/, host="localhost", port=8000)

# close app safely

which can be accessed on any browser on your machine at http://localhost:8000/.

Running from Terminal⚓

You can also access and run WebGear_RTC Server directly from the terminal commandline. The following command will run a WebGear_RTC VideoStreamer server at http://localhost:8000/:

Make sure your PYTHON_PATH is set to python 3.7+ versions only.

If you're using --options/-op flag, then kindly wrap your dictionary value in single '' quotes.

python3 -m vidgear.gears.asyncio --mode webrtc --source test.avi --logging True --options '{"frame_size_reduction": 50, "frame_jpeg_quality": 80, "frame_jpeg_optimize": True, "frame_jpeg_progressive": False}'

which can also be accessed on any browser on the network at http://localhost:8000/.

Advanced Usage from Terminal

You can run python3 -m vidgear.gears.asyncio -h help command to see all the advanced settings, as follows:

usage: python -m vidgear.gears.asyncio [-h] [-m MODE] [-s SOURCE] [-ep ENABLEPICAMERA] [-S STABILIZE]
            [-cn CAMERA_NUM] [-yt stream_mode] [-b BACKEND] [-cs COLORSPACE]
            [-r RESOLUTION] [-f FRAMERATE] [-td TIME_DELAY]
            [-ip IPADDRESS] [-pt PORT] [-l LOGGING] [-op OPTIONS]

Runs WebGear/WebGear_RTC Video Server through terminal.

optional arguments:
  -h, --help            show this help message and exit
  -m {mjpeg,webrtc}, --mode {mjpeg,webrtc}
                        Whether to use "MJPEG" or "WebRTC" mode for streaming.
  -s SOURCE, --source SOURCE
                        Path to input source for CamGear API.
                        Sets the flag to access PiGear(if True) or otherwise
                        CamGear API respectively.
                        Enables/disables real-time video stabilization.
  -cn CAMERA_NUM, --camera_num CAMERA_NUM
                        Sets the camera module index that will be used by
                        PiGear API.
  -yt STREAM_MODE, --stream_mode STREAM_MODE
                        Enables YouTube Mode in CamGear API.
  -b BACKEND, --backend BACKEND
                        Sets the backend of the video source in CamGear API.
  -cs COLORSPACE, --colorspace COLORSPACE
                        Sets the colorspace of the output video stream.
  -r RESOLUTION, --resolution RESOLUTION
                        Sets the resolution (width,height) for camera module
                        in PiGear API.
  -f FRAMERATE, --framerate FRAMERATE
                        Sets the framerate for camera module in PiGear API.
  -td TIME_DELAY, --time_delay TIME_DELAY
                        Sets the time delay(in seconds) before start reading
                        the frames.
  -ip IPADDRESS, --ipaddress IPADDRESS
                        Uvicorn binds the socket to this ipaddress.
  -pt PORT, --port PORT
                        Uvicorn binds the socket to this port.
  -l LOGGING, --logging LOGGING
                        Enables/disables error logging, essential for
  -op OPTIONS, --options OPTIONS
                        Sets the parameters supported by APIs(whichever being
                        accessed) to the input videostream, But make sure to
                        wrap your dict value in single or double quotes.


Last update: February 7, 2022