GithubHelp home page GithubHelp logo

ankitshah009 / avi-r Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cmu-inf-diva/avi-r

0.0 2.0 0.0 112 KB

AVI-R Package (formerly DIVA IO): A robust reader for AVI video files

Home Page: https://pypi.org/project/avi-r/

License: GNU General Public License v3.0

Python 97.92% Shell 2.08%

avi-r's Introduction

AVI-R Package

PyPI version Downloads Publish to PyPI (formerly DIVA IO)

Author: Lijun Yu

Email: [email protected]

A robust reader for AVI video files. Originally designed for the MEVA dataset to replace OpenCV's cv2.VideoCapture in the DIVA project.

Installation

pip install avi-r

Usage

A robust video loader that deals with missing frames in AVI files. In AVI-R, missing frames are automatically filled with the previous available frame, or the next available frame for the beginning of a video. This ensures you are getting the correct frame ids and valid frame contents all the time.

In comparison, OpenCV's cv2.VideoCapture would skip missing frames without warning, leading to wrong frame ids. Pims would return empty frames also without warning. And decord would crash.

Iterator Interface

from avi_r import AVIReader
video = AVIReader(video_path) # or AVIReader(video_name, parent_dir)
for frame in video:
    # frame is a avi_r.frame.Frame object
    image = frame.numpy()
    # image is an uint8 array in a shape of (height, width, channel[BGR])
    # ... Do something with the image
video.close() # Release internal buffers

Replace cv2.VideoCapture

To replace the cv2.VideoCapture objects in legacy codes, simply change from

import cv2
cap = cv2.VideoCapture(video_path)

to

from avi_r import AVIReader
cap = AVIReader(video_path)

AVIReader.read follows the schema of cv2.VideoCapture.read but automatically inserts the missing frames while reading the video. AVIReader.release also follows cv2.VideoCapture.release.

Random Access

Random access of a frame requires decoding from the nearest key frame (approximately every 60 frames for MEVA). Averagely, this introduces a constant overhead of 0.1 seconds. However, when the nearest key frame is missing, AVIReader will try to search a valid one till the beginning.

start_frame_id = 1500
length = 100
video.seek(start_frame_id)
for frame in video.get_iter(length):
    image = frame.numpy()
    # ... Do something with the image
video.close()

Video Properties

video.num_frames # cap.get(cv2.CAP_PROP_FRAME_COUNT)
video.frame_rate # cap.get(cv2.CAP_PROP_FPS)
video.height # cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
video.width # cap.get(cv2.CAP_PROP_FRAME_WIDTH)

Other Interfaces

For other usages, please see the comments in reader.py.

Speed

See speed.md.

Version History

See version.md.

avi-r's People

Contributors

lijun-yu avatar

Watchers

James Cloos avatar  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.