Skip to main content

Simple video reading and writing

Project description

mvid

mvid is a simple library to treat video as a sequence (e.g. as a list) of 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 is built on top of PyAV (with minimal to no overhead) and abstracts away seeking and timing logic.

Requirements

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.0.tar.gz (4.4 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.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mvid-0.1.0.tar.gz
  • Upload date:
  • Size: 4.4 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.0.tar.gz
Algorithm Hash digest
SHA256 8b6aca6fddf5ef9027395e4a0cb2f4c820a1c7b7660a3a34409b26ce27915e76
MD5 c94eba0fc984b4aa2b3c8f1aa86e3b84
BLAKE2b-256 752eca6ac7e2afe36928249d5c10ddd334f86b49450303b706aa59589e689a97

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mvid-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cd0d5727791a4499767ca82064f3d88bbb33a8817b05db2dc45afae3a9ca9336
MD5 5449fc6bedb08968435b86a1b32f8988
BLAKE2b-256 0e04b644e2c2d31ef4e92e07c5e7f724291ff061bcd8b9b9a0c795d90dbbdf89

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