Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Zai org CogVideo Export To Video

From Leeroopedia


Template:Implementation

Overview

Concrete tool for saving generated video frames as an MP4 file provided by the diffusers utility library. This is the final step in the text-to-video inference workflow, converting in-memory PIL Image frames into a playable video file.

Source

inference/cli_demo.py:L195

Signature

export_to_video(
    video_frames: List[PIL.Image.Image],
    output_video_path: str = "./output.mp4",
    fps: int = 16
) -> str

Key Parameters

Parameter Type Default Description
video_frames List[PIL.Image.Image] (required) List of PIL Image frames from pipeline output (output.frames[0])
output_video_path str "./output.mp4" File path for the output MP4 video file
fps int 16 Frames per second for video playback. Use 16 for Diffusers pipeline, 8 for SAT pipeline.

Inputs

  • List of PIL Image frames -- The video frames generated by the CogVideoX pipeline, accessed via output.frames[0]. Each frame is a PIL.Image.Image object.

Outputs

  • .mp4 video file -- An H.264-encoded MP4 video file saved to disk at the specified output path. Returns the output path as a string.

Usage Example

import torch
from diffusers import CogVideoXPipeline, CogVideoXDPMScheduler
from diffusers.utils import export_to_video

# Assume pipeline is loaded, configured, and memory-optimized
pipe = CogVideoXPipeline.from_pretrained(
    "THUDM/CogVideoX1.5-5B",
    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()

# Generate video
output = pipe(
    prompt="A detailed wooden toy ship gliding over a calm ocean.",
    height=768,
    width=1360,
    num_frames=81,
    num_inference_steps=50,
    guidance_scale=6.0,
    use_dynamic_cfg=True,
    generator=torch.Generator().manual_seed(42),
)

# Export to video file
export_to_video(
    video_frames=output.frames[0],
    output_video_path="./output.mp4",
    fps=16
)

Import

from diffusers.utils import export_to_video

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment