mvid
mvid is a simple library to access videos by frame index and return NumPy arrays.
import mvid
with mvid.Video("myvideo.mp4") as video:
# get the number of frames
print(len(video))
# random access
frame = video[57] # frame is a NumPy array
print(frame.shape) # (H, W, 3)
# 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.
We also give a simple Recorder to write from NumPy arrays
import numpy as np
import mvid
with mvid.Recorder("output.mp4", fps=50) as rec:
# record 1 second of gray
for _ in range(50):
rec(128 * np.ones(1080, 1920, 3))
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.
Metadata
Release files for mvid 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mvid-0.2.0.tar.gz | 6.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mvid-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.8 kB
Release files / mvid-0.2.0.tar.gz
| Download URL | mvid-0.2.0.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9859d12e67d1565e646e9ee66dab8869f2d2aab048fea895569ff7ccb0ce3ba3
|
|
BLAKE2b-256 checksum How to use checksums |
6a8fa7b95d6364fc97019c09948b7bc6827ee1a3d47b934b1f3d390c390e45e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.1
|
Release files / mvid-0.2.0-py3-none-any.whl
| Download URL | mvid-0.2.0-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
803ddfb58c9217994ab9b345ce537326219f852b0bab57b7f3bf7fa084a4bbde
|
|
BLAKE2b-256 checksum How to use checksums |
4e31de77cc1b9508114152454fd4a94b72b32fec3ee743afd50f6b5e77550fc8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.1
|