> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-zh/shi-pin-sheng-cheng/ltx-video.md).

# LTX-Video 实时生成

在 Clore.ai GPU 上使用 Lightricks 的 LTX-Video 以快于实时的速度生成 5 秒视频。

Lightricks 的 LTX-Video 是目前最快的开源视频生成模型。在 RTX 4090 上，它大约 4 秒就能生成一段 5 秒、768×512 的视频片段——比实时播放还快。该模型通过原生 `diffusers` 通过以下方式集成： `LTXPipeline` 以及 `LTXImageToVideoPipeline`.

在……上租用 GPU [Clore.ai](https://clore.ai/) 让你立即获得 LTX-Video 所需的硬件，无需前期投入，并按小时计费。

## 主要特性

* **比实时更快** —— 在 RTX 4090 上，5 秒视频约 4 秒即可生成。
* **文生视频** —— 根据自然语言描述生成片段。
* **图像转视频** —— 用运动和相机控制让静态参考图像动起来。
* **轻量级架构** —— 20 亿参数的视频 DiT，带有紧凑的潜空间。
* **原生 diffusers** — `LTXPipeline` 以及 `LTXImageToVideoPipeline` 在 `diffusers >= 0.32`.
* **开源权重** —— Apache-2.0 许可证；完全允许商业使用。
* **时序 VAE** —— 在空间和时间上实现 1:192 的压缩比；解码高效。

## 需求

| 组件        | 最低    | 推荐    |
| --------- | ----- | ----- |
| GPU 显存    | 16 GB | 24 GB |
| 系统内存      | 16 GB | 32 GB |
| 磁盘        | 15 GB | 30 GB |
| Python    | 3.10+ | 3.11  |
| CUDA      | 12.8+ | 12.8+ |
| diffusers | 0.32+ | 最新    |

**Clore.ai GPU 推荐：** 一台 **RTX 4090** （24 GB，$0.14–0.42/小时）最适合追求最高吞吐量。一个 **RTX 3090** （24 GB，$0.07–0.21/小时）仍然比许多竞争模型更快，而成本只是其一小部分。

## 快速开始

```bash
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu128
pip install diffusers transformers accelerate sentencepiece imageio[ffmpeg]

python -c "import torch; print(torch.cuda.get_device_name(0))"
```

## 使用示例

### 文生视频

```python
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(
    prompt=prompt,
    negative_prompt="模糊、低质量、失真",
    num_frames=121,               # 约 24 fps 下 5 秒
    width=768,
    height=512,
    num_inference_steps=30,
    guidance_scale=7.5,
    generator=torch.Generator("cuda").manual_seed(0),
).frames[0]

export_to_video(video_frames, "coral_reef.mp4", fps=24)
print("已保存 coral_reef.mp4")
```

### 图像转视频

```python
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,
    num_inference_steps=30,
    guidance_scale=7.5,
).frames[0]

export_to_video(video_frames, "cityscape_animated.mp4", fps=24)
```

### 批量生成脚本

```python
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(
        prompt=prompt,
        num_frames=121,
        width=768,
        height=512,
        num_inference_steps=30,
        guidance_scale=7.5,
    ).frames[0]
    export_to_video(frames, f"batch_{i:03d}.mp4", fps=24)
    print(f"[{i+1}/{len(prompts)}] 完成")
```

## 给 Clore.ai 用户的建议

1. **速度基准测试** —— 在 RTX 4090 上，LTX-Video 可在约 4 秒内生成 121 帧；可将此作为运行租赁实例是否正常的检查标准。
2. **bf16 精度** —— 检查点以 bf16 训练；不要切换为 fp16，否则可能导致质量下降。
3. **缓存权重** ——将 `HF_HOME=/workspace/hf_cache` 放在持久卷上。模型约 6 GB；每次容器启动都重新下载会浪费时间。
4. **提示词工程** —— LTX-Video 对电影化语言反应良好："无人机镜头"、"慢动作"、"黄金时刻"、"跟拍镜头"。请具体说明相机运动。
5. **通宵批量运行** —— LTX-Video 足够快，在 4090 上每小时可生成数百个片段。把提示词从文件中排队，让它持续运行即可。
6. **SSH + tmux** —— 生成任务务必在一个 `tmux` 会话中运行，这样连接中断也不会打断耗时较长的批处理任务。
7. **监控 VRAM** — `watch -n1 nvidia-smi` 在第二个终端中，以确保没有使用到交换分区。

## 故障排查

| 问题                     | 修复                                                                |
| ---------------------- | ----------------------------------------------------------------- |
| `OutOfMemoryError`     | 减少 `num_frames` 为 81 或 `宽度`/`高度` 调整为 512×320                      |
| 在 diffusers 中找不到模型     | 升级： `pip install -U diffusers` —— LTXPipeline 需要 diffusers ≥ 0.32 |
| 黑屏或静态输出                | 请确保你传入了 `negative_prompt`；将 `guidance_scale` 提高到 8–9              |
| `ImportError: imageio` | `pip install imageio[ffmpeg]` —— 导出 MP4 需要 ffmpeg 后端              |
| 首次推理较慢                 | 首次运行会编译 CUDA 内核并下载权重；后续运行会很快                                      |
| 色带伪影                   | 使用 `torch.bfloat16` （不是 float16）；bfloat16 的动态范围更大                 |
| 容器在任务中途重启              | 设置 `HF_HOME` 到持久存储；未完成的 HF 下载会自动续传                                |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-zh/shi-pin-sheng-cheng/ltx-video.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
