Skip to main content

Powerful python Video Processing library built with Multi-Threaded Gears(a.k.a APIs) each with a unique set of trailblazing features.

Project description

VidGear Logo

VidGear Banner

Releases   |   Gears   |   Wiki Documentation   |   Installation   |   License

PyPi version Build Status Build Status Say Thank you Twitter

Buy Me A Coffee

 

VidGear is a powerful python Video Processing library built with multi-threaded Gears(a.k.a APIs) each with a unique set of trailblazing features. These APIs provides a easy-to-use, highly extensible, and multi-threaded wrapper around many underlying state-of-the-art python libraries such as OpenCV ➶, FFmpeg ➶, picamera ➶, pafy ➶, pyzmq ➶ and python-mss ➶

 

The following functional block diagram clearly depicts the functioning of VidGear library:

@Vidgear Functional Block Diagram

 

Table of Contents

TL;DR

New Release : VidGear 0.1.5

Installation Options

Gears: What are these?

For Developers/Contributors

Documentation

Project Motivation

Additional Info

 

TL;DR

VidGear is an ultrafast➶, compact, flexible and easy-to-adapt complete Video Processing Python Library.

Built with simplicity in mind, VidGear lets programmers and software developers to easily integrate and perform complex Video Processing tasks in their existing or new applications, without going through various underlying python library's documentation and using just a few lines of code. Beneficial for both, if you're new to Programming with Python language or a pro at it.

For more advanced information see the Wiki Documentation ➶.

 

New Release SneekPeak : VidGear 0.1.5

  • Released new ScreenGear API, supports Live ScreenCasting.
  • Released new NetGear API, aids real-time frame transfer through messaging(ZmQ) over the network.
  • Released new Stabilizer Class, for minimum latency Video Stabilization with OpenCV.
  • Updated VideoGear API to be used as an internal wrapper around Stabilizer Class.
  • Implemented exclusive Threaded Queue Mode for blazingly fast, synchronized and error-free multi-threading APIs.
  • Added Option to use VidGear API's standalone.
  • Several Performance enhancements and Bugs exterminated.
  • Revamped Docs and many more...

 

Installation

Prerequisites

To use VidGear in your python application, you must check the following dependencies before you install VidGear :

  • Must support these Python legacies and pip already installed.

  • OpenCV: VidGear must require OpenCV(3.0+) python enabled binaries to be installed on your machine for its core functions. For its installation, you can follow these online tutorials for linux and raspberry pi, otherwise, install it via pip:

      pip install opencv-python
    
  • FFmpeg: VidGear must require FFmpeg for its powerful video compression and encoding capabilities. :star2: Follow this FFmpeg wiki page for its installation. :star2:

  • picamera: Required for using Raspberry Pi Camera Modules(such as OmniVision OV5647 Camera Module) on your Raspberry Pi machine. You can easily install it via pip:

      pip install picamera
    

    Also, make sure to enable Raspberry Pi hardware-specific settings prior to using this library.

  • mss: Required for Screen Casting. Install it via pip:

      pip install mss
    
  • pyzmq: Required for transferring video frames through ZeroMQ messaging system over the network. Install it via pip:

      pip install pyzmq
    
  • pafy: For direct YouTube Video streaming, Vidgear needs pafy and latest youtube-dl(as pafy's backend) python libraries installed. Install it via pip:

      pip install pafy
      pip install -U youtube-dl
    

 

Option 1: PyPI Install

Best option for quickly getting VidGear installed.

  pip install vidgear

 

Option 2: Release Archive Download

Best option if you want a compressed archive.

VidGear releases are available for download as packages in the latest release

 

Option 3: Clone the Repository

Best option for automatically installing required dependencies(except FFmpeg), or for latest patches(maybe experimental), or contributing to development.

You can clone this repository's testing branch for development and thereby can install as follows:

 git clone https://github.com/abhiTronix/vidgear.git
 cd vidgear
 git checkout testing
 pip install .

 

Gears:

VidGear is built with multi-threaded Gears each with some unique function/mechanism. Each Gear is designed exclusively to handle/control different device-specific video streams, network streams, and media encoders. These APIs provides an easy-to-use, highly extensible, and a multi-threaded wrapper around many underlying various python libraries to exploit their features and functions directly while providing robust error-handling.

These Gears can be classified as follows:

A. VideoCapture Gears:

  • CamGear: Targets various IP-USB-Cameras/Network-Streams/YouTube-Video-URL.
  • PiGear: Targets various Raspberry Pi Camera Modules.
  • ScreenGear: Enables ultra-fast Screen Casting.
  • VideoGear: A common API with Video Stabilizer wrapper.

B. VideoWriter Gear:

  • WriteGear: Handles easy Lossless Video Encoding and Compression.

C. Network Gear:

  • NetGear: Targets synchronous video frames transferring between interconnecting systems over the network.

 

CamGear

CamGear supports a diverse range of video streams which can handle/control video stream almost any IP/USB Cameras, multimedia video file format (upto 4k tested), network stream URL such as http(s), rtp, rstp, mms, etc. In addition to this, it also supports live Gstreamer's RAW pipelines and YouTube video/livestreams URLs. CamGear provides a flexible, high-level multi-threaded wrapper around OpenCV's VideoCapture class with access almost all of its available parameters and also employs pafy's APIs for live YouTube streaming. Furthermore, CamGear relies exclusively on Threaded Queue mode for ultra-fast, error-free and synchronized frame handling.

Following simplified functional block diagram depicts CamGear API's generalized working:

CamGear Functional Block Diagram

CamGear API Guide:

>>> Usage Guide

 

VideoGear

VideoGear API provides a special internal wrapper around VidGear's exclusive Video Stabilizer class. Furthermore, VideoGear API can provide internal access to both CamGear and PiGear APIs separated by a special flag. Thereby, this API holds the exclusive power for any incoming VideoStream from any source, whether it is live or not, to stabilize it directly with minimum latency and memory requirements.

Below is a snapshot of a VideoGear Stabilizer in action:

VideoGear Stabilizer in action!
Original Video Courtesy@SIGGRAPH2013

Code to generate above VideoGear API Stabilized Video(See more detailed usage examples here):

# import libraries
from vidgear.gears import VideoGear
import numpy as np
import cv2

stream_stab = VideoGear(source='test.mp4', stabilize = True).start() # To open any valid video stream with `stabilize` flag set to True.
stream_org = VideoGear(source='test.mp4').start() # open same stream without stabilization for comparison

# infinite loop
while True:

  frame_stab = stream_stab.read()
  # read stabilized frames

  # check if frame is None
  if frame_stab is None:
    #if True break the infinite loop
    break

  #read original frame
  frame_org = stream_org.read()

  #concatenate both frames
  output_frame = np.concatenate((frame_org, frame_stab), axis=1)

  #put text
  cv2.putText(output_frame, "Before", (10, output_frame.shape[0] - 10),cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0,255,0), 2)
  cv2.putText(output_frame, "After", (output_frame.shape[1]//2+10, frame.shape[0] - 10),cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0,255,0), 2)

  cv2.imshow("Stabilized Frame", output_frame)
  # Show output window

  key = cv2.waitKey(1) & 0xFF
  # check for 'q' key-press
  if key == ord("q"):
    #if 'q' key-pressed break out
    break

cv2.destroyAllWindows()
# close output window
stream_org.stop()
stream_stab.stop()
# safely close video streams.

VideoGear API Guide:

>>> Usage Guide

 

PiGear

PiGear is similar to CamGear but made to support various Raspberry Pi Camera Modules (such as OmniVision OV5647 Camera Module and Sony IMX219 Camera Module). To interface with these modules correctly, PiGear provides a flexible multi-threaded wrapper around complete picamera python library, and provides us the ability to exploit its various features like brightness, saturation, sensor_mode, etc. effortlessly.

Following simplified functional block diagram depicts PiGear API:

PiGear Functional Block Diagram

PiGear API Guide:

>>> Usage Guide

 

ScreenGear

With ScreenGear, we can easily define an area on the computer screen or an open window to record the live screen frames in real-time at the expense of insignificant latency. To achieve this, ScreenGear provides a high-level multi-threaded wrapper around mss python library API and also supports the flexible direct parameter manipulation.

Below is a snapshot of a ScreenGear API in action:

ScreenGear in action!

Code to generate the above result:

# import libraries
from vidgear.gears import ScreenGear
import cv2

stream = ScreenGear().start()

# infinite loop
while True:

  frame = stream.read()
  # read frames

  # check if frame is None
  if frame is None:
    #if True break the infinite loop
    break

  cv2.imshow("Output Frame", frame)
  # Show output window

  key = cv2.waitKey(1) & 0xFF
  # check for 'q' key-press
  if key == ord("q"):
    #if 'q' key-pressed break out
    break

cv2.destroyAllWindows()
# close output window

stream.stop()
# safely close video stream.

ScreenGear API Guide:

>>> Usage Guide

 

WriteGear

WriteGear is undoubtedly the most powerful Video Processing Gear of them all. It solely handles various powerful FFmpeg tools that allow us to do almost anything you can imagine with multimedia files. With WriteGear API, you can process real-time video frames into a lossless format and specification suitable for our playback in just a few lines of codes. These specifications include setting bitrate, codec, framerate, resolution, subtitles, compression, etc. Furthermore, we can multiplex extracted audio at the output with compression and all that in real-time(see this example). In addition to this, WriteGear also provides flexible access to OpenCV's VideoWriter API which provides some basic tools for video frames encoding but without compression.

WriteGear primarily operates in the following two modes:

  • Compression Mode: In this mode, WriteGear utilizes FFmpeg's inbuilt encoders to encode lossless multimedia files. It provides us the ability to exploit almost any available parameters available within FFmpeg, with so much ease and flexibility and while doing that it robustly handles all errors/warnings quietly. You can find more about this mode here.

  • Non-Compression Mode: In this mode, WriteGear utilizes basic OpenCV's inbuilt VideoWriter API. Similar to compression mode, WriteGear also supports all parameters manipulation available within OpenCV's VideoWriter API. But this mode lacks the ability to manipulate encoding parameters and other important features like video compression, audio encoding, etc. You can learn about this mode here.

Following functional block diagram depicts WriteGear API's generalized working:

WriteGear Functional Block Diagram

WriteGear API Guide:

>>> Usage Guide

 

NetGear

NetGear is exclusively designed to transfer video frames synchronously between interconnecting systems over the network in real-time. This is achieved by implementing a high-level wrapper around PyZmQ python library that contains python bindings for ZeroMQ - a high-performance asynchronous distributed messaging library that aim to be used in distributed or concurrent applications. It provides a message queue, but unlike message-oriented middleware, a ZeroMQ system can run without a dedicated message broker. Furthermore, NetGear currently supports two ZeroMQ messaging patterns: i.e zmq.PAIR and zmq.REQ and zmq.REP.

NetGear API has two modes of operations:

  • Send Mode:(a.k.a Server configuration) which employs send() function to send frames to the client(s). You can use this function to send messages to client(s) too.
  • Receive Mode:(a.k.a Client configuration) which employs recv() function to receive frames sent by server. Client send back confirmation when frame is received successfully.

Following functional block diagram depicts NetGear API:

NetGear Functional Block Diagram

NetGear API Guide:

>>> Usage Guide

 

Documentation

The full documentation for all VidGear classes and functions can be found in the link below:

 

Testing

  • Prerequisites: Testing VidGear require some additional dependencies & data which can be downloaded manually as follows:

    • Clone & Install Testing Branch

    • Download few additional python libraries:

       pip install six
       pip install pytest
      
    • Download Test Dataset: To perform tests, additional test dataset is required, which can be downloaded by running bash script as follows:

       chmod +x scripts/prepare_dataset.sh
       ./scripts/prepare_dataset.sh               #for windows, use `sh scripts/pre_install.sh`
      
  • Run Tests: Then various VidGear tests can be run with pytest(in VidGear's root folder) as below:

     pytest -sv                                   #-sv for verbose output.
    

 

Contributing

See contributing.md

 

Project Motivation

See Wiki: Project Motivation

 

Supported Python legacies

  • Python 2.7 legacies: VidGear v0.1.5 is officially the last Python 2.7 legacies supporting version. Kindly migrate your source code to Python 3 as soon as possible.

  • Python 3.x legacies: follows the numpy releases.

 

Changelog

See changelog.md

 

License

Copyright © abhiTronix 2019

This project is licensed under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vidgear-0.1.5.tar.gz (41.7 kB view details)

Uploaded Source

Built Distribution

vidgear-0.1.5-py2.py3-none-any.whl (45.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file vidgear-0.1.5.tar.gz.

File metadata

  • Download URL: vidgear-0.1.5.tar.gz
  • Upload date:
  • Size: 41.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.6.8

File hashes

Hashes for vidgear-0.1.5.tar.gz
Algorithm Hash digest
SHA256 464114b7a0babf90b04b743865483e59f8c4c78d8bb6c430bf9ead138a11b761
MD5 89d5bf961fa98d2f9eaa4fb3b38e05c0
BLAKE2b-256 05f467bd641a75442ffbc0167b4d81dffb6e858c5809955a23bd92cf63c987e1

See more details on using hashes here.

File details

Details for the file vidgear-0.1.5-py2.py3-none-any.whl.

File metadata

  • Download URL: vidgear-0.1.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 45.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.6.8

File hashes

Hashes for vidgear-0.1.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 59822f5756ef08305fe1a86151a46e4e19a7865e6eb266c2902f46a40e40b185
MD5 e2e6abeeb360f089ee075b1a9fb59ca4
BLAKE2b-256 b4b0fd845d973cd15f38e1b479009bf0a005677a0375722cb0de3130bcf34c6c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page