Python package of FFmpeg Frame Input/Output
Project description
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)
)
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)
FrameWriter performs color correction 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.
cd examples
uv run frame_writer_sample.py
uv run frame_reader_sample.py
Build
Please see Build.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fffio-0.6.1.tar.gz.
File metadata
- Download URL: fffio-0.6.1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
888186ad4e3af317da1659ed016835968c3be5e8c40dcf7138c077c01917bfe4
|
|
| MD5 |
756126fbeaf0d9ce50cea108ebe35c4e
|
|
| BLAKE2b-256 |
26471e3060abc3dee63cb6da6cb4602c9b380eb36256e117177d9bb907dc6465
|
File details
Details for the file fffio-0.6.1-py3-none-any.whl.
File metadata
- Download URL: fffio-0.6.1-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f4bf1ec1c0820c3d888ae651c155259bd8f9b3babc54ef119e2b23ad6bda80c
|
|
| MD5 |
29a66e7c2bfefb5f9a1e073cbb5ec417
|
|
| BLAKE2b-256 |
90d9680f3ed77bed77ca5bf478dc93e69f285d1c6afad6df1b7679db350dd00f
|