/vidgear

Powerful Multi-Threaded OpenCV and FFmpeg based Turbo Video Processing Python Library with unique State-of-the-Art Features.

Primary LanguagePythonMIT LicenseMIT

vidgear Logo

 

PyPi version Last Commit License

VidGear is a Python library for Turbo Multi-Threaded Video Processing

  • VidGear is a high-level All-in-One Video Processing framework build on top of OpenCV, PiCamera and FFmpeg. It's simple to use and easy to extend.

  • It contains following Powerful Gears (Multi-Threaded Video Processing classes) to handle/control different device-specific video streams and writer:

    Gear Function
    CamGear Targets any IP-Camera/USB-Camera/Network-Stream/YouTube-Video
    PiGear Targets any Raspberry Pi Camera Modules
    VideoGear Common Gear to access any of the video capture gear
    WriteGear enables Lossless Video Writer with flexible Video Compression capabilities
  • It comes with various in-built features like Flexible Control over Video Source properties like resolution, framerate, colorspace, etc. manipulation and supports easy direct Network stream pipelining (support for GStreamer, YouTube and other network streams like http(s), rtp, rstp, mms, etc.).

  • This library is also very well compatible with the Raspberry-Pi Camera modules (RPiCam) and provides us the ability to exploit its various features like brightness, saturation, sensor_mode, etc. easily.

  • Furthermore, VidGear utilizes FFmpeg's powerful encoders to encode and reduce the output to a smaller size, without sacrificing the video quality. It provide us full-control over FFmpeg output parameters.

 

Key Features

What makes VidGear stand out from all other Video Processing python tools?

  • Multi-Threaded high-speed Frame capturing (High FPS)
  • Flexible & Direct control over Video Source properties
  • Lossless Video Encoding and Writing
  • Flexible Output Video Encoder, Compression & Quality Control
  • Direct YouTube Video pipelining using its URL address
  • Easy Video Source ColorSpace Conversion
  • Automated prerequisites installation
  • Built-in robust Error and Frame Synchronization handling
  • Multi-Devices Compatibility (including RpiCamera)
  • Support for Live Network Video Streams (including Gstreamer Raw Pipeline)

 

Documentation and Usage

You can checkout VidGear WIKI-SECTION for in-depth documentation with examples for each VidGear Class

Basic example:

The bare minimum basic example of WriteGear(Compression Mode) with VideoGear class for a common Live WebCamera stream is as follows :

from vidgear.gears import VideoGear
from vidgear.gears import WriteGear
import cv2

stream = VideoGear(source=0).start() #Open live webcam video stream on first index(i.e. 0) device

writer = WriteGear(output_filename = 'Output.mp4') #Define writer with output filename 'Output.mp4'

# 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
	

	# do something with frame here

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

	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
writer.close()
# safely close writer

 

Prerequisites

Note: Vidgear automatically handles all required prerequisites(except FFmpeg) installation according to your system requirements

Critical:

  • OpenCV(with contrib): VidGear must require OpenCV with contrib (3.0+) python library to be installed on your machine which is critical for its core algorithm functioning. You can build it from from scratch (Raspberry Pi) or Vidgear automatically installs OpenCV with contrib python library for you based on your system from PyPi.

  • FFmpeg: VidGear requires FFmpeg installation for Compression capabilities. Follow this WIKI Page for latest FFmpeg installation. ⚠️

Additional:

  • PiCamera: If you are using Raspberry Pi Camera Modules such as OmniVision OV5647 Camera Module and Sony IMX219 Camera Module. It requires additional Picamera library installation on your Raspberry Pi machine prior to its installation (Latest versions recommended).

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

  • pafy: For direct YouTube Video Pipelining into OpenCV, Vidgear requires Pafy python library.

 

Installation

 

Contribution and Development

You are welcome to contribute with suggestions, feature requests and pull requests.

Clone this repository(development): You can clone this repository for latest releases (maybe experimental) for development purposes and thereby can install as follows:

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

 

Supported Python versions

  • Python 2.7 is the only supported version in 2.x series. Python 2.7 support will be dropped in the end of 2019.

  • Python 3.x releases follow OpenCV releases.

Author

License

Copyright © 2019 AbhiTronix

This project is under the MIT License. See the LICENSE file for the full license text.