Skip to main content

A robust reader for avi videos.

Project description

AVI-R Package

PyPI version Downloads Publish to PyPI (formerly DIVA IO)

Author: Lijun Yu

Email: lijun@lj-y.com

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.

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

avi-r-1.3.9.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

avi_r-1.3.9-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file avi-r-1.3.9.tar.gz.

File metadata

  • Download URL: avi-r-1.3.9.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for avi-r-1.3.9.tar.gz
Algorithm Hash digest
SHA256 abde61b2467671130739b0fd4c8b645b96550fed0cea789faa713fa4889487ad
MD5 47573c134efcd8858d5140a08fb6eeee
BLAKE2b-256 91a4bd49c5edc60902765b1212aba0ba57c65f7eac6368bf3408c7ddb5b9426f

See more details on using hashes here.

File details

Details for the file avi_r-1.3.9-py3-none-any.whl.

File metadata

  • Download URL: avi_r-1.3.9-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for avi_r-1.3.9-py3-none-any.whl
Algorithm Hash digest
SHA256 ecf3ca95602847a23d447e8ac5e3921ebe3c4e6e4e1c9c8bc3a1bdc040f8f292
MD5 67aee75958246d639174e7170d7a542a
BLAKE2b-256 70991219eecdab23cbac6bf5f554d900e4762623bf551e2fd40ded2f93dd1195

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