Git Product home page Git Product logo

videoreader's Introduction

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

videoreader's People

Contributors

postpop avatar nickdelgrosso avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.