VidGear Documentation

repository·master·Indexed 25 days ago

https://github.com/abhitronix/vidgear

A high-performance, cross-platform Python framework for real-time video processing. It provides multi-threaded and asyncio-optimized APIs called 'Gears' for video capture (CamGear, FFGear, PiGear, ScreenGear, VideoGear), writing (WriteGear), streaming (StreamGear, WebGear, WebGear_RTC), and network transfer (NetGear, NetGear_Async), leveraging libraries such as OpenCV, FFmpeg, ZeroMQ, and yt_dlp.

Tokens
141.9K
Snippets
290
Records
540
Agent score
82%

What's inside VidGear

  1. Overview of NetGear API

    master

    NetGear is designed for synchronous and asynchronous real-time video frame transfers between systems over a network. It acts as a high-level wrapper around the PyZmQ library (Python bindings for ZeroMQ), allowing for high-performance distributed messaging without a dedicated broker.

    Key features include:

    • ZeroMQ Messaging Patterns: Supports zmq.PAIR, zmq.REQ/zmq.REP, and zmq.PUB/zmq.SUB patterns.
    • Protocols: Supports tcp and ipc protocols.
    • Lazy Pirate Pattern: Implements automatic reconnection for zmq.PAIR and zmq.REQ/zmq.REP patterns. Instead of blocking, the API polls the socket, attempts to reconnect if a timeout occurs, and eventually abandons the connection after several failed attempts.
    • JPEG Frame Compression: Enabled by default (using fast DCT and 90% compression quality) to boost performance during network transfers.
  2. Overview of WebGear_RTC API

    master

    WebGear_RTC is a video-streaming API designed for modern browsers and native clients. Unlike the standard WebGear API which uses Motion JPEG, WebGear_RTC utilizes WebRTC technology for high-performance, real-time streaming.

    Key features include:

    • Built on the aiortc library for asynchronous WebRTC/ORTC support.
    • Handles multiple consumers seamlessly.
    • Native support for ICE, STUN, and TURN servers to establish direct media connections.
    • Integrates with the Starlette ASGI application ecosystem (middleware, routing, templates, etc.).
    • Provides internal wrappers for VideoGear, CamGear, PiGear, and FFGear APIs.
  3. Overview of CamGear API

    master

    CamGear is a high-level, multi-threaded wrapper around OpenCV's VideoCapture API designed for flexible video stream handling. It uses Threaded Queue mode to ensure error-free and synchronized frame handling.

    Supported Sources:

    • IP/USB Cameras: Almost any camera type.
    • Multimedia Files: Various video file formats (tested up to 4K).
    • Network Streams: URLs using http(s), rtp, rtsp, rtmp, mms, etc.
    • Gstreamer: Supports Gstreamer's RAW pipelines.
    • Streaming Sites: Seamlessly handles sites like YouTube and Twitch via an internal yt_dlp backend.

    Best Practices:

    • Enable Logging: It is advised to set logging = True during your first run to help identify runtime errors.
    • OpenCV Users: If you are transitioning from OpenCV, refer to the switching guide for compatibility details.
  4. Overview of StreamGear API

    master

    StreamGear is a wrapper around FFmpeg designed to simplify the transcoding workflow for generating ultra-low latency, high-quality, dynamic, and adaptive streaming formats like MPEG-DASH and Apple HLS.

    It allows developers to transcode source video/audio files or real-time video frames into sequences of smaller chunks/segments. These segments can be served via an HTTP server and accessed through standard HTTP GET requests. StreamGear automatically generates the necessary manifest files (e.g., .mpd for DASH or .m3u8 for HLS) containing segment timing, URLs, and media characteristics.

    Note: For traditional protocols like RTMP or RTSP/RTP, use the WriteGear API instead.

  5. Overview of VideoGear API

    master

    VideoGear is a unified video-capture API designed to allow switching between multiple video-capture backends with minimal code changes. It provides a wrapper around the Video Stabilizer class and offers a common interface for different capture technologies.

    Key Features:

    • Unified Access: Switch between CamGear, PiGear, and FFGear using a single parameter.
    • Video Stabilization: Simplifies stabilization for both live streams and video files.
    • Backend Switching: Easily swap backends by changing the api parameter.

    Tip: It is highly recommended to enable logging (logging = True) during your initial implementation to help identify runtime errors.

  6. Overview of NetGear_Async API

    master

    NetGear_Async is a high-performance asynchronous video streaming API built on zmq.asyncio and powered by the uvloop event loop. It is designed for high-speed, lag-free video streaming over a network with minimal resource consumption (approximately one-third the memory of the standard NetGear API).

    Key features include:

    • High Throughput: Capable of transferring thousands of frames in seconds with minimal system load.
    • Bidirectional Data Transmission: Supports sending data between the receiver (client) and sender (server) while transferring video frames.
    • Source Versatility: Includes internal wrappers for VideoGear, providing access to CamGear, PiGear, and FFGear to stream frames from various sources.
    • Custom Sources: Allows defining custom servers to transform frames before network transmission.
  7. Overview of FFGear API

    master

    FFGear is a multi-threaded, high-performance wrapper around the deffcode FFdecoder API. It executes FFmpeg pipelines inside a subprocess pipe to generate real-time, low-overhead decoded video frames in Python.

    Key features include:

    • Hardware-Accelerated Decoding: GPU-powered decoding via CUDA/CUVID and other backends.
    • Flexible Pixel Formats: Support for any FFmpeg pixel format (e.g., bgr24, yuv420p, gray) with OpenCV compatibility patches.
    • Per-Frame Metadata Extraction: Asynchronous extraction via the showinfo filter.
    • Live Complex Filtergraphs: Support for simple and complex FFmpeg filter pipelines.
    • Multi-Input Sources: Simultaneous inputs via -map or -filter_complex.
    • Wide Source Support: USB/virtual/IP cameras, multimedia files, image sequences, desktop capture, and network streams (HTTP(s), RTSP/RTP, etc.).
    • Streaming Support: Integration with yt-dlp for streaming services like YouTube and Twitch.
    • Threaded Queue Mode: Configurable via QUEUE_SIZE, THREADED_QUEUE_MODE, and THREAD_TIMEOUT for asynchronous frame delivery.
  8. Overview of PiGear API

    master

    PiGear is a specialized API optimized for Raspberry Pi Boards, providing comprehensive support for camera modules (e.g., OmniVision OV5647, Sony IMX219) and limited compatibility for USB cameras. It acts as a robust, multi-threaded wrapper around the picamera2 library, leveraging the libcamera API for high performance.

    Key features include:

    • Seamless Backend Switching: Automatically switches to the legacy picamera library if picamera2 is unavailable.
    • Hardware Safety: Implements a Threaded Internal Timer that monitors for frozen threads or hardware failures (like a disconnected camera cable) to ensure the API exits safely without causing kernel panics.
    • Parameter Support: Supports picamera2 parameters such as sensor, controls, transform, and format with internal type and sanity checks.
    • Multi-camera Support: Supports multiple camera modules, including those on Raspberry Pi Compute Module IO boards and USB cameras (via picamera2).

    Important: Ensure Raspberry Pi Camera hardware-specific settings are completed before use.

  9. Overview of VidGear

    master
    VidGear is a high-performance, cross-platform Python framework designed for real-time video processing. It provides a multi-threaded and asyncio optimized API layer on top of specialized libraries like OpenCV, FFmpeg, ZeroMQ, and yt_dlp. It is designed to read, write, process, and stream video files, frames, and streams from various devices with robust error handling and real-time performance.
  10. Introduction to VidGear

    master
    VidGear is a cross-platform, high-performance video-processing framework for building complex real-time media applications in Python. It provides a multi-threaded and asyncio-based API framework that wraps specialized libraries such as OpenCV, FFmpeg, ZeroMQ, picamera2, starlette, yt_dlp, and others. It is designed to simplify complex video processing tasks with minimal code while providing robust error-handling and real-time performance.
  11. Overview of WebGear API

    master

    WebGear is an ASGI Video-Broadcaster API designed for transmitting Motion-JPEG frames from a single source to multiple recipients via a web browser. It is built on top of Starlette and provides an asynchronous wrapper that integrates with the Starlette ecosystem (middleware, routing, static files, Jinja2 templating, etc.).

    WebGear uses an intraframe-only compression scheme (encoding frames as JPEG-DIB) and streams them over HTTP using Starlette's StreamingResponse and a Uvicorn ASGI server. It can act as a broadcaster for video sources provided by CamGear, PiGear, or FFGear via the VideoGear interface.

  12. Overview of ScreenGear API

    master

    ScreenGear is a high-performance tool designed for rapid screencasting. It allows for real-time frame grabbing from a monitor, supporting both full-screen and specific area definitions with minimal latency. It can capture frames from multiple monitors and supports multiple backends by providing a multi-threaded wrapper around dxcam, pyscreenshot, and python-mss libraries.

    Tip: When running for the first time, it is advised to enable logging (logging = True) to help identify any runtime errors.