Skip to main content

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)
        )

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fffio-0.7.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fffio-0.7.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file fffio-0.7.0.tar.gz.

File metadata

  • Download URL: fffio-0.7.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for fffio-0.7.0.tar.gz
Algorithm Hash digest
SHA256 622aa861ad61012e2b80990d88b3c1ffa6b81f75d9b9506d38a72d54bf264a5e
MD5 85d8aaea0b3923deaeeb68d09565be44
BLAKE2b-256 d18edf0968952262bd7c7ab6a49d023de909bc46ca5da68862161d9685fc173d

See more details on using hashes here.

File details

Details for the file fffio-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: fffio-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for fffio-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4189001811df4bc5b97b29abf80e6ccec3d267ffad291ab18fbec743873749a2
MD5 de0d3a62c6e5ce5c676e54645fa3b813
BLAKE2b-256 10006c97226796e91c747e56b8505c865f3cfb04dc93505120ca07406b5cc189

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page