fffio (FFmpeg Frame Input/Output)
This is a Python package for easily reading and writing video files.
Install
To install from PyPI:
pip install fffio
To install from GitHub:
pip install git+https://github.com/yamakox/fffio.git
How to read frames from a video
Simply iterate through calls to the FrameReader's frames method.
from fffio import FrameReader
import cv2
with FrameReader('sample.mp4') as reader:
for i, frame in enumerate(reader.frames(), 1):
# frame is a numpy.ndarray(shape=(height, width, 3), dtype=np.uint8).
_ = cv2.imwrite(
f'sample{i:05d}.jpg',
cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
)
Note: If the video file is generated using FrameWriter, ensure that the colorspace value in FrameReader matches the value in FrameWriter.
| class | colorspace parameter |
|---|---|
| FrameReader | The default value is False. |
| FrameWriter | The default value is True. |
How to write frames to a video
Simply iterate through calls to FrameWriter's write or write_frame method.
from fffio import FrameWriter
import cv2
from pathlib import Path
size=(1920, 1080)
with FrameWriter('sample.mp4', size=size) as writer:
for file in sorted(Path('.').glob('*.jpg')):
frame = cv2.cvtColor(cv2.imread(str(file)), cv2.COLOR_BGR2RGB)
frame = cv2.resize(frame, size, interpolation=cv2.INTER_LANCZOS4)
writer.write(frame)
Note: When colorspace parameter is True (default), FrameWriter converts colorspace (bt601-6-625 -> bt709) during conversion from RGB to YUV. For more information, please see Colorspace support in FFmpeg.
Examples
The script examples in the examples folder can be run using uv.
uv sync
cd examples
uv run frame_writer_sample.py
uv run frame_reader_sample.py
Build
Please see Build.md.
Metadata
Release files for fffio 0.7.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 | |
|---|---|---|---|
| fffio-0.7.0.tar.gz | 5.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fffio-0.7.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.0 kB
Release files / fffio-0.7.0.tar.gz
| Download URL | fffio-0.7.0.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
622aa861ad61012e2b80990d88b3c1ffa6b81f75d9b9506d38a72d54bf264a5e
|
|
BLAKE2b-256 checksum How to use checksums |
d18edf0968952262bd7c7ab6a49d023de909bc46ca5da68862161d9685fc173d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Release files / fffio-0.7.0-py3-none-any.whl
| Download URL | fffio-0.7.0-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4189001811df4bc5b97b29abf80e6ccec3d267ffad291ab18fbec743873749a2
|
|
BLAKE2b-256 checksum How to use checksums |
10006c97226796e91c747e56b8505c865f3cfb04dc93505120ca07406b5cc189
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|