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 likehttp(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.
- 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)
You can checkout VidGear WIKI-SECTION for in-depth documentation with examples for each VidGear Class
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
Note: Vidgear automatically handles all required prerequisites(except FFmpeg) installation according to your system requirements
-
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 installsOpenCV 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.
⚠️
- 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.
-
From PyPI(Stable Only):
VidGear
can be easily installed as follows(available on Python Package Index (PyPI)):$ pip install vidgear
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 .
-
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.
- Abhishek Thakur @abhiTronix
Copyright © 2019 AbhiTronix
This project is under the MIT License. See the LICENSE file for the full license text.