Skip to main content

Pythonic wrapper around opencv's VideoCapture().

Project description

Pythonic video reader

Wrapper around opencv's cv2.VideoCapture to simplify reading video files in python.


In a terminal window run:

conda install pyvideoreader -c ncb


pip install pyvideoreader


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]

Or use a context manger 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]:

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 =  # read next frame

Project details

Download files

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

Files for pyvideoreader, version 0.5.3
Filename, size File type Python version Upload date Hashes
Filename, size pyvideoreader-0.5.3.tar.gz (9.6 kB) File type Source Python version None Upload date Hashes View
Filename, size pyvideoreader-0.5.3-py3-none-any.whl (7.2 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page