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.7.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyvideoreader-0.5.7.tar.gz
Algorithm Hash digest
SHA256 f5fafb7760468863f08d2ee1c613a46bec5f2b0ca64af681eb313c66bb08cb47
MD5 b6cadba3ed84891067c83872527f864a
BLAKE2b-256 477ff92c33e37dad8594f4d05da2ce167b529709605df448bf2f75d1a7316dd7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyvideoreader-0.5.7-py3-none-any.whl
Algorithm Hash digest
SHA256 22111a5371d12d5a12529e04a5b840f1d1592bb8385227b1a0b1e86d4a4788a7
MD5 b31e7fd6ec0a9f3afb89fe5d805816da
BLAKE2b-256 3c790ddc6c5d5a3b83c685a5cff9b53b9977007cc2604d7285e1e943f1638574

See more details on using hashes here.

Supported by

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