> 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/animatediff.md).

# AnimateDiff

AnimateDiff 是一个即插即用模块， **可为你现有的 Stable Diffusion 模型赋予动画效果** 无需任何额外训练。凭借超过 10,000 个 GitHub 星标，它已成为将静态图像的 SD 检查点转化为平滑、时间一致的视频生成器的首选框架。在 Clore.ai 的 GPU 实例上运行它，并使用 ComfyUI 作为前端，以获得最大的灵活性。

***

## 什么是 AnimateDiff？

AnimateDiff 会将一个 **运动模块** 插入到冻结的 Stable Diffusion U-Net 中。该运动模块只需在视频数据上训练一次，就可以与任何微调过的 SD 1.5 检查点——DreamBooth 模型、LoRA、ControlNet 适配器——组合使用，而无需重新训练。其结果是短动画片段（通常为 16–32 帧，8 fps），并能保留基础模型的风格。

**主要亮点：**

* 开箱即用，兼容任何 SD 1.5 检查点
* 兼容 ControlNet、IP-Adapter、LoRA 及其他扩展
* ComfyUI 节点生态系统提供完整的流程控制
* 提供 SDXL 运动模块，可输出更高分辨率内容
* 社区维护的模型仓库，包含面向特定领域的运动模块

***

## 前提条件

| 要求     | 最低       | 推荐              |
| ------ | -------- | --------------- |
| GPU 显存 | 8 GB     | 16–24 GB        |
| GPU    | RTX 3080 | RTX 4090 / A100 |
| 内存     | 16 GB    | 32 GB           |
| 存储     | 20 GB    | 50+ GB          |

{% hint style="info" %}
AnimateDiff 在 512×512 分辨率、标准 16 帧序列下大约占用 8–10 GB 显存。对于 768×768 或更长序列，建议使用 16 GB 及以上。
{% endhint %}

***

## 步骤 1——在 Clore.ai 上租用 GPU

1. 前往 [clore.ai](https://clore.ai) 并登录。
2. 点击 **市场** 并按显存筛选（为获得最佳效果，≥ 16 GB）。
3. 选择一台服务器——RTX 4090 或 A6000 具有最佳性价比。
4. 在 **Docker 镜像**，输入你的自定义镜像（见下方步骤 2）。
5. 配置 **打开端口**: `22` （SSH）和 `8188` （ComfyUI Web UI）。
6. 点击 **租用** 并等待实例启动（约 1–2 分钟）。

{% hint style="info" %}
使用 **高级** 端口配置，将端口 `8188` 映射到一个公网端口。记下分配到的公网端口——你将使用它来访问 ComfyUI Web 界面。
{% endhint %}

***

## 步骤 2——Docker 镜像

没有唯一官方的 AnimateDiff Docker 镜像。推荐的做法是使用一个 **基于 ComfyUI 的镜像** 并预装 AnimateDiff 节点。

**推荐的公开镜像：**

```
yanwk/comfyui-boot:latest
```

或者自行构建：

```dockerfile
FROM pytorch/pytorch:2.11.0-cuda12.8-cudnn9-runtime

RUN apt-get update && apt-get install -y \
    git wget curl ffmpeg libgl1 libglib2.0-0 \
    openssh-server && \
    rm -rf /var/lib/apt/lists/*

# 设置 SSH
RUN mkdir /var/run/sshd && \
    echo 'root:clore123' | chpasswd && \
    sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

# 克隆 ComfyUI
RUN git clone https://github.com/comfyanonymous/ComfyUI /workspace/ComfyUI && \
    cd /workspace/ComfyUI && pip install -r requirements.txt

# 安装 ComfyUI Manager
RUN cd /workspace/ComfyUI/custom_nodes && \
    git clone https://github.com/ltdrdata/ComfyUI-Manager

# 安装 AnimateDiff-Evolved 节点
RUN cd /workspace/ComfyUI/custom_nodes && \
    git clone https://github.com/Kosinkadink/ComfyUI-AnimateDiff-Evolved && \
    pip install -r ComfyUI-AnimateDiff-Evolved/requirements.txt

# 安装用于输出的 VideoHelperSuite
RUN cd /workspace/ComfyUI/custom_nodes && \
    git clone https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite && \
    pip install -r ComfyUI-VideoHelperSuite/requirements.txt

EXPOSE 22 8188

CMD service ssh start && \\
    python /workspace/ComfyUI/main.py --listen 0.0.0.0 --port 8188 --enable-cors-header
```

***

## 步骤 3 — 通过 SSH 连接

实例运行后，通过 SSH 连接以下载模型：

```bash
ssh root@<clore-host> -p <assigned-ssh-port>
```

替换 `<clore-host>` 以及 `<assigned-ssh-port>` 替换为你在 Clore.ai 控制面板中显示的值。

***

## 步骤 4——下载模型

AnimateDiff 至少需要一个 **基础 SD 1.5 检查点** 和一个 **运动模块**.

### 下载运动模块

```bash
cd /workspace/ComfyUI/custom_nodes/ComfyUI-AnimateDiff-Evolved/models

# v3 运动模块（推荐）
wget -O v3_sd15_mm.ckpt \
  "https://huggingface.co/guoyww/animatediff/resolve/main/v3_sd15_mm.ckpt"

# v2 运动模块（兼容性更广）
wget -O mm_sd_v15_v2.ckpt \
  "https://huggingface.co/guoyww/animatediff/resolve/main/mm_sd_v15_v2.ckpt"
```

### 下载基础 SD 1.5 检查点

```bash
cd /workspace/ComfyUI/models/checkpoints

# Realistic Vision（AnimateDiff 常用）
wget -O realisticVisionV60B1_v51VAE.safetensors \
  "https://huggingface.co/SG161222/Realistic_Vision_V6.0_B1_noVAE/resolve/main/Realistic_Vision_V6.0_B1_fp16-no-ema.safetensors"
```

{% hint style="info" %}
你可以使用任何 SD 1.5 微调模型。常见选择包括 DreamShaper、Deliberate 和 Epicphotogasm。可从 CivitAI 或 Hugging Face 下载。
{% endhint %}

### （可选）下载 SDXL 运动模块

```bash
cd /workspace/ComfyUI/custom_nodes/ComfyUI-AnimateDiff-Evolved/models

wget -O temporaldiff-v1-animatediff.safetensors \
  "https://huggingface.co/CiaraRowles/TemporalDiff/resolve/main/temporaldiff-v1-animatediff.safetensors"
```

***

## 步骤 5——访问 ComfyUI

打开浏览器并访问：

```
http://<clore-host>:<public-port-8188>
```

你应该会看到 ComfyUI 节点编辑器界面。

{% hint style="info" %}
把这个 URL 加入书签。ComfyUI 会在你工作时自动保存工作流——除非导出 JSON，否则无需手动保存。
{% endhint %}

***

## 步骤 6——加载 AnimateDiff 工作流

### 基础 AnimateDiff 工作流（JSON）

在 ComfyUI 中，按 **加载** 并粘贴或导入这个工作流 JSON，或者按以下节点手动搭建：

**核心节点链：**

1. `加载检查点` → 你的 SD 1.5 检查点
2. `CLIP 文本编码（提示词）` → 正向和负向提示词
3. `AnimateDiff Loader` → 选择你的运动模块
4. `KSampler（高效）` → 采样设置
5. `VAE 解码` → 解码潜空间
6. `Video Combine` （VideoHelperSuite）→ 导出为 GIF/MP4

### 推荐采样设置

| 参数        | 数值              |
| --------- | --------------- |
| 步数        | 20–25           |
| CFG Scale | 7–8             |
| 采样器       | DPM++ 2M Karras |
| 宽度 × 高度   | 512 × 512       |
| 帧数        | 16              |
| 上下文长度     | 16              |

***

## 步骤 7——运行你的第一个动画

1. 在 `CLIP 文本编码` 节点中，输入你的提示词：

   ```
   一只威严的狮子在日落时分穿过高草丛，电影感，4k
   ```
2. 在负面提示词节点中：

   ```
   最差质量，低质量，模糊，水印，变形，nsfw
   ```
3. 在 `AnimateDiff Loader`，选择 `v3_sd15_mm.ckpt`
4. 点击 **排队提示词**

{% hint style="info" %}
在 512×512 分辨率、20 步、16 帧的情况下，生成时间大约为 **30–60 秒** 在 RTX 4090 上。更长的序列和更高的分辨率会线性增加耗时。
{% endhint %}

***

## 高级技巧

### 将 ControlNet 与 AnimateDiff 结合使用

AnimateDiff 可与 ControlNet 配合，用于受控视频生成：

```bash
# 下载 ControlNet 模型
cd /workspace/ComfyUI/models/controlnet
wget -O control_v11p_sd15_openpose.pth \
  "https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose.pth"
```

添加一个 `ControlNet Apply` 节点，放在 `Load ControlNet Model` 以及 `KSampler`之间。使用 OpenPose 骨架图作为条件输入。

### Prompt Travel（关键帧动画）

AnimateDiff-Evolved 节点支持 **prompt travel** ——在不同帧使用不同的文本提示：

```
“黎明时分的森林” → 第 0 帧
“正午时分的森林” → 第 8 帧
“日落时分的森林” → 第 16 帧
```

这可以在场景之间创建平滑过渡，而无需手动设置关键帧。

### 将 LoRA 与 AnimateDiff 结合使用

```bash
# 下载运动 LoRA
cd /workspace/ComfyUI/models/loras
wget -O v2_lora_PanLeft.ckpt \
  "https://huggingface.co/guoyww/animatediff/resolve/main/v2_lora_PanLeft.ckpt"
```

添加一个 `LoRA Loader` 节点来应用镜头运动效果：PanLeft、PanRight、ZoomIn、ZoomOut、RollingAnticlockwise。

***

## 输出格式

通过 VideoHelperSuite 的 AnimateDiff 支持：

| 格式        | 节点              | 备注        |
| --------- | --------------- | --------- |
| GIF       | `Video Combine` | 最适合分享     |
| MP4（h264） | `Video Combine` | 文件体积最小    |
| WebP      | `Video Combine` | 画质/体积表现良好 |
| PNG 帧     | `保存图像`          | 用于后期处理    |

***

## 故障排查

### 显存不足（CUDA OOM）

```
RuntimeError: CUDA out of memory
```

**解决方案：**

* 减少帧数（尝试 8 帧而不是 16 帧）
* 降低分辨率（512×512 是 SD 1.5 的最佳点）
* 启用 `--lowvram` 在 ComfyUI 启动命令中的标志
* 使用 `fp16` 精度，位于 `加载检查点` 节点

### 未找到运动模块

```
错误：未找到运动模块
```

**解决方案：** 请确认 `.ckpt` 文件位于：

```
/workspace/ComfyUI/custom_nodes/ComfyUI-AnimateDiff-Evolved/models/
```

刷新 ComfyUI 页面以重新加载可用模型。

### 闪烁 / 帧不一致

**解决方案：**

* 增大 `context_length` 以匹配总帧数
* 使用 `v3_sd15_mm.ckpt` 而不是 v2（更好的时间一致性）
* 降低 CFG scale（尝试 7 而不是 9）
* 使用低方差采样器： `DPM++ 2M Karras` 或 `Euler a`

### SSH 连接被拒绝

```bash
ssh: connect to host <ip> port <port>: Connection refused
```

**解决方案：** 等待 1–2 分钟让 SSH 守护进程启动，或通过 Clore.ai 控制面板日志检查容器是否已完全初始化。

***

## Clore.ai GPU 推荐

AnimateDiff 使用 SD 1.5 作为骨干——与现代视频模型相比，显存需求较低，因此更适合预算有限的用户。

| GPU           | 显存    | Clore.ai 价格                       | 16 帧 @ 512px | 备注                                        |
| ------------- | ----- | --------------------------------- | ------------ | ----------------------------------------- |
| RTX 3090      | 24 GB | $0.07–0.21/小时                     | 约 50 秒       | 最佳性价比——可运行多个排队批次                          |
| RTX 4090      | 24 GB | $0.14–0.42/小时                     | \~30 秒       | 速度最快的消费级 GPU                              |
| A100 40GB     | 40 GB | [裸机](https://clore.ai/bare-metal) | 约 18 秒       | 对 SD 1.5 来说有些性能过剩，但对 SDXL+AnimateDiff 很合适 |
| RTX 3080 10GB | 10 GB | $0.05–0.19/小时                     | 约 90 秒       | 预算最低——仅限 512px，较短片段                       |

{% hint style="info" %}
**RTX 3090 是 AnimateDiff 的最佳平衡点** 价格为每小时 $0.07–0.21。一个 16 帧动画大约需要 50 秒，这意味着每花 1 美元可生成 70+ 个片段。对于大批量内容创作，可在 ComfyUI 中使用批队列并通宵运行。
{% endhint %}

**SDXL AnimateDiff 用户：** SDXL 运动模块在 768px 下需要 12GB 以上显存。RTX 3090/4090 可以很好地处理。RTX 3080（10GB）对于 SDXL 工作流来说限制太大。

***

## 有用资源

* [AnimateDiff GitHub](https://github.com/guoyww/AnimateDiff)
* [ComfyUI-AnimateDiff-Evolved](https://github.com/Kosinkadink/ComfyUI-AnimateDiff-Evolved)
* [ComfyUI 官方](https://github.com/comfyanonymous/ComfyUI)
* [AnimateDiff 运动模型（HuggingFace）](https://huggingface.co/guoyww/animatediff)
* [CivitAI — SD 检查点](https://civitai.com)


---

# 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/animatediff.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.
