Skip to main content

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

Project description

Pythonic video reader

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

Installation

In a terminal window run:

conda install pyvideoreader -c ncb

or

pip install pyvideoreader

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 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]:
    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


Download files

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

Source Distribution

pyvideoreader-0.5.6.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyvideoreader-0.5.6-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file pyvideoreader-0.5.6.tar.gz.

File metadata

  • Download URL: pyvideoreader-0.5.6.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.1

File hashes

Hashes for pyvideoreader-0.5.6.tar.gz
Algorithm Hash digest
SHA256 3a23f95dcda5047b5e38dceedbbeda0bec0f4be74674accfdb597a442d7641ff
MD5 aaf6c862a1e71dc4c0e8a996adb586a3
BLAKE2b-256 83f140577d05800416d0a2d412f2bce86fa560a67b1b37676a3f22dab25e5f3f

See more details on using hashes here.

File details

Details for the file pyvideoreader-0.5.6-py3-none-any.whl.

File metadata

  • Download URL: pyvideoreader-0.5.6-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.1

File hashes

Hashes for pyvideoreader-0.5.6-py3-none-any.whl
Algorithm Hash digest
SHA256 47797b2f96a4b700f56e868387004066a81f84fcc35087394decb8ed6bc526ff
MD5 3c3e9c6acac2550fb4923d2fed434373
BLAKE2b-256 4aad0414b45b90ca4c122344b4b6274f1c64438678303e39c5a52e6d4252f5f7

See more details on using hashes here.

Supported by

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