Skip to main content

Simple video reading

Project description

mvid

mvid is a simple library to access videos by frame index and return NumPy arrays.

from mvid import Video

with Video("myvideo.mp4") as video:
    # get the number of frames
    print(len(video))

    # random access
    frame = video[57]
    
    # iterate over all frames in the video
    for frame in video:
        pass

It uses PyAV (with minimal to no overhead) and abstracts away seeking logic for you.

Installation

pip install mvid

It requires PyAV and NumPY.

How it works

Frame lookup is based on decoding from the nearest preceding keyframe up to the requested index. We determine that index using each frame’s timestamp together with the stream’s frame rate. This approach works well for videos with consistent timing metadata, but not all files follow those assumptions. Some containers use variable frame rates or contain incomplete or inconsistent timestamps. In those cases there is no reliable way to infer a stable frame index without first scanning every frame and assigning indices explicitly. Rather than performing that preprocessing step, we intentionally crash when encountering timing metadata that cannot be interpreted unambiguously.

Performance

Generally speaking, sequential access is as fast as possible thanks to PyAV. Check benchmark.py and compare with ffmpeg -i <my_video> -f null -. The benchmarking script will also try random access and various thread parameters so you can see what performance to expect.

There is overhead from conversion to NumPY arrays. We also provide a more "raw" AVVideo class that performs all the bookkeeping without NumPY conversion.

Related projects

TorchCodec is a more heavy-duty library that returns PyTorch tensors. It also has index-based access (among other options). It requires managing your installation of ffmpeg.

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

mvid-0.1.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

mvid-0.1.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file mvid-0.1.1.tar.gz.

File metadata

  • Download URL: mvid-0.1.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for mvid-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2c1e824b73816046e57d2d4be86a0c248d36087b1587819523192df330f2c0cf
MD5 07245cb4b573f3c33e2f9123aaf2acf9
BLAKE2b-256 8ca349cd8e575fd605c2a7ef1710b5fd270a44841ab8ae5b3946dcc8127b8789

See more details on using hashes here.

File details

Details for the file mvid-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mvid-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for mvid-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d3d8e6573514664f447bdd4b9c663d6cfa8bf585817152b030a43800c25aab2d
MD5 77c472cf3185b584f9e7c23e1fab245b
BLAKE2b-256 d217936967ab8408565e794fea64b625bd44086c278fe77a12ef1efcd76ac95c

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