Implementation:Zai org CogVideo I2V Export To Video
Metadata
| Field | Value |
|---|---|
| Page Type | Implementation (Wrapper Doc) |
| Knowledge Sources | Repo (CogVideo), Paper (CogVideoX) |
| Domains | Video_Generation, Diffusion_Models, Image_Conditioning |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
Concrete tool for saving I2V-generated video frames as an MP4 file provided by the diffusers utility library.
Description
export_to_video is a utility function from the diffusers library that takes a list of PIL Image frames and encodes them into an H.264-compressed MP4 video file. The function handles frame-by-frame encoding, codec selection, and container formatting automatically.
This function is used identically for both T2V and I2V workflows. It is documented here as part of the I2V pipeline for workflow traceability.
Usage
Import export_to_video from diffusers.utils and call it with the list of PIL Image frames obtained from the I2V pipeline output, along with the desired output file path and frame rate.
Code Reference
Source Location
inference/cli_demo.py, line 195.
Signature
export_to_video(
video_frames, # List[PIL.Image.Image]: frames from pipeline output
output_video_path, # str: path to save the output MP4 file (default "./output.mp4")
fps=fps, # int: frames per second (default 16)
)
# Returns: str (output file path)
Import
from diffusers.utils import export_to_video
I/O Contract
Inputs
| Parameter | Type | Required | Description |
|---|---|---|---|
video_frames |
List[PIL.Image.Image] | Yes | List of PIL Image frames from the I2V pipeline output. Accessed via output.frames[0].
|
output_video_path |
str | No | File path for the output MP4 video. Defaults to "./output.mp4".
|
fps |
int | No | Frame rate for the output video. Defaults to 16. Determines playback speed. |
Outputs
| Output | Type | Description |
|---|---|---|
| Video file | .mp4 file on disk | An H.264-encoded MP4 video file saved at the specified output_video_path.
|
| Return value | str | The output file path string. |
Usage Examples
Basic I2V Video Export
from diffusers.utils import export_to_video
# Assuming video_frames is obtained from the I2V pipeline:
# video_frames = pipe(prompt=..., image=..., ...).frames[0]
export_to_video(video_frames, "./i2v_output.mp4", fps=16)
Complete I2V Workflow with Export
import torch
from diffusers import CogVideoXImageToVideoPipeline, CogVideoXDPMScheduler
from diffusers.utils import export_to_video, load_image
# Load and configure pipeline
pipe = CogVideoXImageToVideoPipeline.from_pretrained(
"THUDM/CogVideoX-5b-I2V", torch_dtype=torch.bfloat16
)
pipe.scheduler = CogVideoXDPMScheduler.from_config(
pipe.scheduler.config, timestep_spacing="trailing"
)
pipe.enable_sequential_cpu_offload()
pipe.vae.enable_slicing()
pipe.vae.enable_tiling()
# Load conditioning image
image = load_image("/path/to/reference.png")
# Generate video
video_frames = pipe(
prompt="A dog running through a field of flowers",
image=image,
height=480,
width=720,
num_frames=81,
num_inference_steps=50,
guidance_scale=6.0,
use_dynamic_cfg=True,
generator=torch.Generator().manual_seed(42),
).frames[0]
# Export to MP4
export_to_video(video_frames, "./dog_running.mp4", fps=16)
Export with Custom Frame Rate
from diffusers.utils import export_to_video
# Slower playback at 8 fps (81 frames = ~10 seconds)
export_to_video(video_frames, "./slow_motion.mp4", fps=8)
# Faster playback at 24 fps (81 frames = ~3.4 seconds)
export_to_video(video_frames, "./fast_motion.mp4", fps=24)