vrw: A Simple Library for Video Reading and Writing
vrw is a lightweight Python library for reading and writing video files with slicing support. It provides a simple interface for handling video frames using NumPy arrays and supports multiple backends like OpenCV and PyAV.
Installation
To install vrw, use the following command:
pip install vrw
Usage
Reading Videos
The VideoReader class allows you to read video files and access frames with slicing and indexing.
from vrw import VideoReader
# Open a video file
vr = VideoReader("video.mp4")
# Access video properties
print(vr.shape) # (N, H, W, C): N frames, H height, W width, C channels
print(vr.fps) # Frames per second
print(vr.dtype) # Data type of the frames
# Access frames using slicing
print(vr[:, 0].shape) # (N, W, C): All frames, first row
print(vr[::2, :, -1].shape) # (N // 2, H, C): Every second frame, last column
print(vr[..., 0].shape) # (N, H, W): All frames, first channel
print(vr[[1, 3, 3, 7], :42].shape) # (4, 42, W, C): Specific frames, first 42 rows
# Reading grayscale frames
vr_gray = VideoReader("video.mp4", to_gray=True)
print(vr_gray.shape) # (N, H, W): Grayscale frames
Note that advanced indexing involving the 0th axis has not been implemented yet.
Writing Videos
The VideoWriter class allows you to write video files frame by frame.
Writing RGB Frames
from vrw import VideoWriter
import numpy as np
# Write RGB frames to a video file
with VideoWriter("video.mp4", fps=30) as vw:
for i in range(256):
im = np.full((256, 256, 3), i, dtype=np.uint8)
im[..., 0], im[..., 1] = np.mgrid[:256, :256]
vw.write(im)
Writing Grayscale Frames
# Write grayscale frames to a video file
with VideoWriter("video.mp4", fps=30) as vw:
for i in range(256):
vw.write(np.full((256, 256), i, dtype=np.uint8))
Using the PyAV Backend
The PyAV backend allows you to use advanced codecs (e.g., libx264) for video writing. Ensure that FFmpeg is installed and built with the required codecs.
# Use the PyAV backend with a specific codec
with VideoWriter("video.mp4", fps=30, backend="pyav", codec="libx264") as vw:
for i in range(256):
im = np.full((256, 256, 3), i, dtype=np.uint8)
im[..., 0], im[..., 1] = np.mgrid[:256, :256]
vw.write(im)
Backends
vrw supports the following backends
- OpenCV: Default backend for reading and writing videos.
- PyAV: Alternative backend for advanced codec support (requires FFmpeg built with the necessary codecs).
To specify a backend, use the backend parameter (e.g., backend="cv2" or backend="pyav") when creating a VideoReader or VideoWriter instance.
Metadata
Release files for vrw 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 | Provenance | Actions |
|---|---|---|---|---|
| vrw-0.2.0.tar.gz | 339.4 kB | Without provenance | Details for vrw-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vrw-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for vrw-0.2.0-py3-none-any.whl |
Total release size: 351.2 kB
Release files / vrw-0.2.0.tar.gz
| Download URL | vrw-0.2.0.tar.gz |
|---|---|
| Size | 339.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
21f5c1913c1a3c4c6f3456e4ebc29106a9a4b0d2291ec979a2ee03e14794ebcb
|
|
BLAKE2b-256 checksum How to use checksums |
4c2b745f8b1aedebd5467dd3512b877609e8bf49138c64b521a6d843d6356a5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / vrw-0.2.0-py3-none-any.whl
| Download URL | vrw-0.2.0-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
df06d1907b85f3d7e1900d2021cdd7b293aaf6488253f014a0c57fec7ededfc0
|
|
BLAKE2b-256 checksum How to use checksums |
295955dddfff500eb93660daa75ddc88cca7d2dfaddba955198b3d125276b761
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for vrw 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.