pngs_to_video#
- pngs_to_video(inputs, output_path, fps=24, resize_to=None)[source]#
Convert a sequence of PNG images into an MP4 video using
imageiowith the PyAV plugin.This function reads a list or folder of PNG images, ensures that each frame is RGB (uint8), contiguous in memory, and has even pixel dimensions, then encodes them into an H.264 MP4 video file. Optionally, images can be resized before encoding. It provides a fully pure-Python workflow using
imageioandPillow.- Parameters:
inputs (str or list of str) –
- Either:
a directory path containing PNG files,
a glob pattern (e.g.,
"./frames/*.png"), oran explicit list of file paths.
output_path (str) – Path to the output video file (e.g.,
"./output.mp4").fps (int, optional) – Frames per second of the output video. Default is 24.
resize_to (tuple of int, optional) – Target video frame size
(width, height)in pixels. IfNone, uses the size of the first image. Default isNone.
- Returns:
The video is written directly to
output_path.- Return type:
None
Notes
The output codec is H.264 (requires
pyavplugin inimageio).Any unreadable or malformed image will raise a
RuntimeError.
Examples
>>> pngs_to_video("./frames/*.png", "movie.mp4", fps=30) >>> pngs_to_video(["frame1.png", "frame2.png", "frame3.png"], "out.mp4", resize_to=(1280, 720))