Pythonic wrapper around opencv's VideoCapture().
Project description
videoreader - a pythonic way to read videos
Wrapper around opencv's cv2.VideoCapture
to simplify working with video files.
Installation
In a terminal window run:
conda install opencv
pip install git+http://github.com/postpop/videoreader
Usage
Open a video file and read frame 100:
from videoreader import VideoReader
vr = VideoReader(video_file_name)
print(vr) # prints video_file_name, number of frames, frame rate and frame size
frame = vr[100]
vr.close()
Or use a with
statement which takes care of opening and closing the video:
with VideoReader(video_file_name) as vr: # load the video
frame = vr[100]
Supports slice-syntax: vr[start:end:step]
. To iterate over all frames you need to use vr[:]
. To read every 100th frame, starting at frame 500 and ending at frame 10000 do this:
for frame in vr[500:10000:100]:
do_something_with(frame)
Lists, tuples or ranges can also be passed as indices, e.g. vr[(42, 314, 999)]
.
Note that indexing returns a generator - each frame in the indices is read on demand which saves memory. If you need all frames at once you can convert it to a list list(vr[start:end:frame])
.
For compatibility, videoreader
can also be used like the underlying cv2.VideoCapture
:
ret, frame = vr.read() # read next frame
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyvideoreader-0.4.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1402a0926980a329def82e646eb5863c42996c88968e317b3b60bc62aca99560 |
|
MD5 | d791640a2277cfab480dd437a04c9a72 |
|
BLAKE2b-256 | bf86f0ce564a4f668ed4ec4d3f3066754d511ef4450b8a18531744e183580e28 |