videoio: save/load image sequence as H.264 video
A small Python module for saving and loading RGB and uint16 (depth) frames as H.264 encoded video
Prerequisites
ffmpeg>=2.1with libx264 enabled- If you are using conda, you can install the correct version with
conda remove ffmpegandconda install ffmpeg x264 -c conda-forge
- If you are using conda, you can install the correct version with
ffprobe(usually comes with ffmpeg)
Quickstart
Save/load RGB frames:
import numpy as np
from videoio import videosave, videoread
frames = np.random.random((20, 200, 400, 3)) # [framesNr, height, width, RGB]
# Save to video
videosave("out.mp4", frames)
# Load from video
frames = videoread("out.mp4")
Read frames sequentially:
from videoio import VideoReader
for frame in VideoReader("in.mp4"):
do_something_with(frame)
Write frames sequentially:
from videoio import VideoWriter
writer = VideoWriter("out.mp4", resolution=(400, 200)) # [width, height]
for i in range(100):
frame = get_frame()
writer.write(frame)
writer.close()
or
with VideoWriter("out.mp4", resolution=(400, 200)) as writer:
for i in range(100):
frame = get_frame()
writer.write(frame)
Lossless write/read of uint16 3D arrays (useful for saving depth frames stored in mm, for example Kinect data):
import numpy as np
from videoio import uint16save, uint16read
# Generate 20 random depth frames
depth_frames = (np.random.random((20, 200, 400)) * 65535).astype(np.uint16)
# Save
uint16save("out_depth.mp4", depth_frames)
# Load
depth_frames = uint16read("out_depth.mp4")
Save RGB frames in lossless mode with different compression preset and different FPS:
videosave("out.mp4", frames, lossless=True, preset="veryfast", fps=10.5)
Read RGB frames and scale them to target resolution simultaneously:
frames = videoread("in.mp4", output_resolution=(100, 250))
Read video/uint16-array starting from certain frame:
(Works if the input video was created by videoio, other cases are not guaranteed)
frames = videoread("in.mp4", start_frame=100)
for frame in VideoReader("in.mp4", start_frame=100):
do_something_with(frame)
Installation
From pip:
pip install videoio
From source:
git clone https://github.com/vguzov/videoio.git
python setup.py install
Metadata
Release files for videoio 0.3.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 | |
|---|---|---|---|
| videoio-0.3.0.tar.gz | 12.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| videoio-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.8 kB
Release files / videoio-0.3.0.tar.gz
| Download URL | videoio-0.3.0.tar.gz |
|---|---|
| Size | 12.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ff006088c9dc5bdd7ea73a7317177d0c3e67033114f68711a43d0b66bfc0e492
|
|
BLAKE2b-256 checksum How to use checksums |
078b3e53eca0ef2bfe1772a153fcf3c15cef556e98ee3e2c422985d07d44d499
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.14
|
Release files / videoio-0.3.0-py3-none-any.whl
| Download URL | videoio-0.3.0-py3-none-any.whl |
|---|---|
| Size | 13.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5ff628fbdddb67931d36ca7557205c632fba09cd96494294e936122b4fd29201
|
|
BLAKE2b-256 checksum How to use checksums |
2da5ea290cc888a6114868081491981bec03a6261a5e22fdabdcb89ed5a97da2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.14
|