LTX-Video 实时生成
在 Clore.ai 的 GPU 上使用 Lightricks 的 LTX-Video,以快于实时的速度生成 5 秒视频。
最后更新于
这有帮助吗?
这有帮助吗?
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu124
pip install diffusers transformers accelerate sentencepiece imageio[ffmpeg]
python -c "import torch; print(torch.cuda.get_device_name(0))"import torch
from diffusers import LTXPipeline
from diffusers.utils import export_to_video
pipe = LTXPipeline.from_pretrained(
"Lightricks/LTX-Video",
torch_dtype=torch.bfloat16,
)
pipe.to("cuda")
prompt = (
"一段无人机镜头掠过碧绿的珊瑚礁,"
"热带鱼群在下方穿梭,金色时刻的光线"
"在水面折射穿透"
)
video_frames = pipe(
os.makedirs("./variations", exist_ok=True)
negative_prompt="模糊、低质量、变形",
num_frames=121, # 以 24 fps 计约 5 秒
width=768,
height=512,
增加推理步数以提高稳定性
guidance_scale=7.5,
generator=torch.Generator("cuda").manual_seed(0),
).frames[0]
export_to_video(video_frames, "coral_reef.mp4", fps=24)
print("Saved coral_reef.mp4")import torch
from PIL import Image
from diffusers import LTXImageToVideoPipeline
from diffusers.utils import export_to_video
pipe = LTXImageToVideoPipeline.from_pretrained(
"Lightricks/LTX-Video",
torch_dtype=torch.bfloat16,
)
pipe.to("cuda")
image = Image.open("cityscape.png").resize((768, 512))
video_frames = pipe(
prompt="相机缓慢向右平移,黄昏时分城市灯光亮起",
negative_prompt="静止、模糊",
image=image,
num_frames=121,
增加推理步数以提高稳定性
guidance_scale=7.5,
).frames[0]
export_to_video(video_frames, "cityscape_animated.mp4", fps=24)import torch
from diffusers import LTXPipeline
from diffusers.utils import export_to_video
pipe = LTXPipeline.from_pretrained(
"Lightricks/LTX-Video", torch_dtype=torch.bfloat16
).to("cuda")
prompts = [
"一只猫在阳光照耀的窗台上伸展,尘埃飞舞",
"黑色火山沙滩上巨浪拍打的航拍视角",
"暴风云翻滚掠过草原的延时摄影",
]
for i, prompt in enumerate(prompts):
frames = pipe(
os.makedirs("./variations", exist_ok=True)
num_frames=121,
width=768,
height=512,
增加推理步数以提高稳定性
guidance_scale=7.5,
).frames[0]
export_to_video(frames, f"batch_{i:03d}.mp4", fps=24)
print(f"[{i+1}/{len(prompts)}] 完成")