# AnimateDiff

AnimateDiff 是一个即插即用的模块，能够 **为您现有的 Stable Diffusion 模型添加动画** 无需任何额外训练。它在 GitHub 上拥有超过 10,000 颗星，是将静态图像的 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、LoRAs 及其他扩展
* ComfyUI 节点生态系统提供完整的流水线控制
* 提供用于更高分辨率输出的 SDXL 运动模块
* 社区维护的模型库，包含领域特定的运动模块

***

## 先决条件

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

{% hint style="info" %}
使用标准 16 帧序列在 512×512 时，AnimateDiff 大约消耗 8–10 GB VRAM。对于 768×768 或更长序列，建议使用 16+ GB。
{% endhint %}

***

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

1. 前往 [clore.ai](https://clore.ai) 并登录。
2. 点击 **市场** 并按 VRAM 过滤（≥ 16 GB 可获得最佳效果）。
3. 选择服务器——RTX 4090 或 A6000 在性价比上最佳。
4. 在 **Docker 镜像**下，输入您的自定义镜像（见下面步骤 2）。
5. 配置 **开放端口**: `22` （SSH）和 `8188` （ComfyUI Web 界面）。
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.1.2-cuda12.1-cudnn8-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 加载器` → 选择您的运动模块
4. `KSampler（高效）` → 采样设置
5. `VAE 解码` → 解码潜变量
6. `视频合并` （VideoHelperSuite）→ 导出为 GIF/MP4

### 推荐采样设置

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

***

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

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

   ```
   一只雄伟的狮子在日落时分穿过高草，电影感，4k
   ```
2. 在负向提示词节点：

   ```
   最差质量、低质量、模糊、水印、畸形、NSFW
   ```
3. 在 `AnimateDiff 加载器`中，选择 `v3_sd15_mm.ckpt`
4. 点击 **队列提示**

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

***

## 高级技巧

### 在 AnimateDiff 中使用 ControlNet

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 应用` 和 `加载 ControlNet 模型`KSampler

### 。使用 OpenPose 骨架图像作为条件输入。

提示词移动（关键帧动画） **AnimateDiff-Evolved 节点支持** 提示词移动

```
——在不同帧使用不同的文本提示词：
“黎明的森林” → 第 0 帧
“正午的森林” → 第 8 帧
```

“日落的森林” → 第 16 帧

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

```bash
在 AnimateDiff 中使用 LoRA
# 下载运动 LoRA
cd /workspace/ComfyUI/models/loras
  wget -O v2_lora_PanLeft.ckpt \
```

添加一个 `"https://huggingface.co/guoyww/animatediff/resolve/main/v2_lora_PanLeft.ckpt"` LoRA 加载器

***

## 节点用于应用相机运动效果：PanLeft、PanRight、ZoomIn、ZoomOut、RollingAnticlockwise。

输出格式

| 通过 VideoHelperSuite，AnimateDiff 支持： | 格式     | 说明        |
| ----------------------------------- | ------ | --------- |
| 节点                                  | `视频合并` | GIF       |
| 最适合分享                               | `视频合并` | MP4（h264） |
| 文件最小                                | `视频合并` | WebP      |
| 质量/大小兼备                             | `保存图像` | PNG 帧     |

***

## 故障排除

### 用于后期处理

```
降低分辨率（1024→768 或 512）
```

**将批量大小减小到 1**

* 内存不足（CUDA OOM）
* 减少帧数（尝试 8 帧而不是 16 帧）
* 在生成面板中启用 `降低分辨率（512×512 是 SD 1.5 的最佳平衡点）` 在 ComfyUI 启动命令中使用
* 使用 `--lowvram` 在 `加载检查点` 节点中使用

### fp16

```
运动模块未找到
```

**解决方案：** 错误：未找到运动模块 `验证` .ckpt

```
文件位于：
```

/workspace/ComfyUI/custom\_nodes/ComfyUI-AnimateDiff-Evolved/models/

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

**将批量大小减小到 1**

* 增加 `闪烁 / 帧不一致` 将
* 使用 `v3_sd15_mm.ckpt` 设置为匹配总帧数
* 而不是 v2（更好的时间一致性）
* 降低 CFG 比例（尝试 7 而不是 9） `DPM++ 2M Karras` 或 `使用低方差采样器：`

### Euler a

```bash
SSH 连接被拒绝
```

**解决方案：** ssh: 连接主机 \<ip> 端口 \<port>：连接被拒绝

***

## Clore.ai 的 GPU 建议

等待 1–2 分钟以让 SSH 守护进程启动，或通过 Clore.ai 仪表板日志检查容器是否已完全初始化。

| GPU                                     | 显存（VRAM） | Clore.ai 价格   | AnimateDiff 使用 SD 1.5 主干——与现代视频模型相比，显存需求较低，更加经济实惠。 | 说明              |
| --------------------------------------- | -------- | ------------- | -------------------------------------------------- | --------------- |
| RTX 3090                                | 24 GB    | \~$0.12/小时    | 16 帧 @ 512px                                       | 约 50 秒          |
| RTX 4090                                | 24 GB    | \~$0.70/小时    | ≈30 秒                                              | 最佳性价比——运行多个排队批次 |
| A100 40GB                               | 40 GB    | \~$1.20/小时    | 最快的消费者级 GPU                                        | 约 18 秒          |
| 对 SD 1.5 来说有点过剩，但对 SDXL+AnimateDiff 很有用 | 10 GB    | RTX 3080 10GB | 约 $0.07/小时                                         | 约 90 秒          |

{% hint style="info" %}
**预算最低配置——仅限 512px、较短片段** RTX 3090 是 AnimateDiff 的最佳选择
{% endhint %}

**每小时约 $0.12。16 帧动画大约需要 \~50 秒，这意味着每美元可以生成 70+ 个片段。对于大批量内容创建，可在 ComfyUI 中排队批量运行并通宵处理。** SDXL AnimateDiff 用户：

***

## 有用的资源

* [SDXL 运动模块在 768px 下需要 12GB+ VRAM。RTX 3090/4090 可以很好地处理。RTX 3080（10GB）对于 SDXL 工作流来说显得不足。](https://github.com/guoyww/AnimateDiff)
* [AnimateDiff GitHub](https://github.com/Kosinkadink/ComfyUI-AnimateDiff-Evolved)
* [ComfyUI-AnimateDiff-Evolved](https://github.com/comfyanonymous/ComfyUI)
* [ComfyUI 官方](https://huggingface.co/guoyww/animatediff)
* [AnimateDiff 运动模型（HuggingFace）](https://civitai.com)


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
