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

# OpenSora

使用 OpenSora 生成视频，开源的 Sora 替代方案

{% hint style="info" %}
**有更新的替代方案可用！** [**FramePack**](/guides/guides_v2-zh/shi-pin-sheng-cheng/framepack.md) 仅用 6GB 显存即可生成视频， [**Wan2.1**](/guides/guides_v2-zh/shi-pin-sheng-cheng/wan-video.md) 提供更优质的效果，且 [**LTX-2**](/guides/guides_v2-zh/shi-pin-sheng-cheng/ltx-video-2.md) 还支持原生音频生成。
{% endhint %}

在 CLORE.AI GPU 上使用开源 Sora 替代方案 OpenSora 生成视频。

{% hint style="success" %}
所有示例都可以在通过以下方式租用的 GPU 服务器上运行 [CLORE.AI 市场](https://clore.ai/marketplace).
{% endhint %}

## 为什么选择 OpenSora？

* **开源** - 完整的 Apache 2.0 许可证
* **受 Sora 启发** - 类似 OpenAI Sora 的 DiT 架构
* **可扩展** - 多种模型尺寸和分辨率
* **长视频** - 最长可生成 16 秒
* **持续开发中** - 定期更新和改进

## 模型变体

| 模型             | 分辨率  | 时长  | 显存   | 质量 |
| -------------- | ---- | --- | ---- | -- |
| OpenSora 1.2   | 720p | 16秒 | 24GB | 优秀 |
| OpenSora 1.1   | 480p | 8秒  | 16GB | 好  |
| OpenSora 1.0   | 256p | 4秒  | 8GB  | 基础 |
| Open-Sora-Plan | 512p | 10秒 | 20GB | 很高 |

## 在 CLORE.AI 上快速部署

**Docker 镜像：**

```
pytorch/pytorch:2.11.0-cuda12.8-cudnn9-devel
```

**端口：**

```
22/tcp
7860/http
```

**命令：**

```bash
git clone https://github.com/hpcaitech/Open-Sora && \
cd Open-Sora && \
pip install -e . && \
pip install gradio && \
python scripts/inference.py \
    --prompt "一只玩毛线球的猫" \
    --num-frames 51 \
    --resolution 480p \
    --save-dir ./outputs
```

## 访问你的服务

部署后，找到你的 `http_pub` URL 在 **我的订单**:

1. 前往 **我的订单** 页面
2. 点击你的订单
3. 找到 `http_pub` URL（例如， `abc123.clorecloud.net`)

使用 `https://YOUR_HTTP_PUB_URL` 替代 `localhost` 在下面的示例中。

## 硬件要求

| 模型版本         | 最低 GPU        | 推荐            | 最佳        |
| ------------ | ------------- | ------------- | --------- |
| OpenSora 1.0 | RTX 3070 8GB  | RTX 3090 24GB | RTX 4090  |
| OpenSora 1.1 | RTX 3090 16GB | RTX 4090 24GB | A100 40GB |
| OpenSora 1.2 | RTX 4090 24GB | A100 40GB     | A100 80GB |

## 安装

### 从源码安装

```bash
git clone https://github.com/hpcaitech/Open-Sora
cd Open-Sora

# 安装依赖
pip install -e .

# 下载模型权重
python scripts/download_weights.py --version 1.2
```

### 使用 pip

```bash
pip install opensora
```

## 基础用法

### 命令行

```bash
# 简单生成
python scripts/inference.py \
    --prompt "海面上壮丽的日落，电影感" \
    --num-frames 51 \
    --resolution 480p \
    --save-dir ./outputs

# 高质量
python scripts/inference.py \
    --prompt "一只雄伟的鹰翱翔于云间" \
    --num-frames 102 \
    --resolution 720p \
    --num-sampling-steps 100 \
    --save-dir ./outputs
```

### Python API

```python
import torch
from opensora.models import OpenSoraModel
from opensora.utils import export_to_video

# 加载模型
model = OpenSoraModel.from_pretrained("hpcaitech/OpenSora-v1.2")
model.to("cuda")

# 生成视频
prompt = "一枚火箭发射升空，戏剧性光照，电影感"

video = model.generate(
    prompt=prompt,
    num_frames=51,
    height=480,
    width=854,
    num_inference_steps=50,
    guidance_scale=7.0
)

# 保存
export_to_video(video, "rocket.mp4", fps=24)
```

## 高级生成

### 使用负面提示词

```python
video = model.generate(
    prompt="野外老虎的专业摄影",
    negative_prompt="模糊、低质量、失真、伪影",
    num_frames=51,
    num_inference_steps=75,
    guidance_scale=7.5
)
```

### 长视频

```python
# 以 24fps 生成 16 秒视频
video = model.generate(
    prompt="花园中花朵绽放的延时摄影",
    num_frames=384,  # 24fps 下 16 秒
    height=480,
    width=854,
    num_inference_steps=100
)

export_to_video(video, "timelapse.mp4", fps=24)
```

### 高分辨率

```python
# 720p 生成（需要更多显存）
video = model.generate(
    prompt="夜晚灯火通明的城市俯视图",
    num_frames=51,
    height=720,
    width=1280,
    num_inference_steps=75
)
```

## 提示词示例

### 电影感

```python
prompts = [
    "武士拔刀的电影镜头，戏剧性光照，4K",
    "暴风雨中悬崖上的城堡的史诗广角镜头",
    "水滴慢动作落入静止池塘",
    "夜晚穿过霓虹灯照亮的赛博朋克小巷的跟拍镜头"
]
```

### 自然

```python
prompts = [
    "极光在雪山上舞动，延时摄影",
    "蝴蝶破茧而出的微距镜头",
    "日落时分，海浪拍击火山岩",
    "黎明时薄雾在古老森林中流动"
]
```

### 抽象

```python
prompts = [
    "彩色颜料滴入水中，慢动作",
    "分形不断演化和变形，迷幻色彩",
    "液态金属变形为不同形状"
]
```

## 配置选项

### 分辨率预设

```python
resolutions = {
    "256p": (256, 455),
    "360p": (360, 640),
    "480p": (480, 854),
    "720p": (720, 1280),
    "1080p": (1080, 1920)  # 需要高显存
}
```

### 质量设置

```python
# 快速预览
config_fast = {
    "num_frames": 25,
    "num_inference_steps": 25,
    "guidance_scale": 5.0
}

# 平衡
config_balanced = {
    "num_frames": 51,
    "num_inference_steps": 50,
    "guidance_scale": 7.0
}

# 最高画质
config_quality = {
    "num_frames": 102,
    "num_inference_steps": 100,
    "guidance_scale": 7.5
}
```

## Gradio 界面

```python
import gradio as gr
import torch
from opensora.models import OpenSoraModel
from opensora.utils import export_to_video
import tempfile

model = OpenSoraModel.from_pretrained("hpcaitech/OpenSora-v1.2")
model.to("cuda")

def generate_video(prompt, negative_prompt, frames, steps, guidance, resolution, seed):
    res_map = {"480p": (480, 854), "720p": (720, 1280)}
    height, width = res_map.get(resolution, (480, 854))

    generator = torch.Generator("cuda").manual_seed(seed) if seed > 0 else None

    video = model.generate(
        prompt=prompt,
        negative_prompt=negative_prompt,
        num_frames=frames,
        height=height,
        width=width,
        num_inference_steps=steps,
        guidance_scale=guidance,
        generator=generator
    )

    with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as f:
        export_to_video(video, f.name, fps=24)
        return f.name

demo = gr.Interface(
    fn=generate_video,
    inputs=[
        gr.Textbox(label="提示词", lines=2),
        gr.Textbox(label="负面提示词", value="模糊、低质量"),
        gr.Slider(25, 200, value=51, step=1, label="帧数"),
        gr.Slider(20, 150, value=50, step=5, label="步数"),
        gr.Slider(3, 15, value=7, step=0.5, label="引导"),
        gr.Dropdown(["480p", "720p"], value="480p", label="分辨率"),
        gr.Number(value=-1, label="种子")
    ],
    outputs=gr.Video(label="生成的视频"),
    title="OpenSora - 文本转视频",
    description="使用 OpenSora 生成视频。在 CLORE.AI 上运行。"
)

demo.launch(server_name="0.0.0.0", server_port=7860)
```

## 内存优化

```python
# 启用内存优化
model.enable_model_cpu_offload()
model.enable_vae_tiling()

# 适用于超低显存
model.enable_sequential_cpu_offload()

# 使用更低精度
model = OpenSoraModel.from_pretrained(
    "hpcaitech/OpenSora-v1.2",
    torch_dtype=torch.float16
)
```

## 批量生成

```python
import os

prompts = [
    "从火焰中重生的凤凰",
    "夜晚雨水落在城市街道上",
    "花朵绽放的延时摄影",
    "山脉上空的北极光"
]

output_dir = "./videos"
os.makedirs(output_dir, exist_ok=True)

for i, prompt in enumerate(prompts):
    print(f"正在生成 {i+1}/{len(prompts)}：{prompt[:40]}...")

    video = model.generate(
        prompt=prompt,
        num_frames=51,
        num_inference_steps=50
    )

    export_to_video(video, f"{output_dir}/video_{i:03d}.mp4", fps=24)

    # 在每次生成之间清理内存
    torch.cuda.empty_cache()
```

## 性能

| 分辨率  | 帧数  | 步数  | GPU       | 时间      |
| ---- | --- | --- | --------- | ------- |
| 480p | 51  | 50  | RTX 4090  | \~3 分钟  |
| 480p | 51  | 50  | A100 40GB | 约 2 分钟  |
| 720p | 51  | 50  | A100 40GB | \~5 分钟  |
| 720p | 102 | 100 | A100 80GB | \~15 分钟 |

## 成本估算

CLORE.AI 市场的典型费率：

| GPU           | 小时费率    | \~每小时 51 个 480p 视频 |
| ------------- | ------- | ------------------ |
| RTX 4090 24GB | \~$0.10 | \~15-20            |
| A100 40GB     | \~$0.17 | \~25-30            |
| A100 80GB     | \~$0.25 | \~35（可支持 720p）     |

*价格会变化。请查看* [*CLORE.AI 市场*](https://clore.ai/marketplace) *以获取当前费率。*

## 故障排查

### 内存不足

```bash
# 使用更小的分辨率
python scripts/inference.py --resolution 360p --num-frames 25

# 启用 CPU 卸载
python scripts/inference.py --cpu-offload

# 减小批次大小
python scripts/inference.py --batch-size 1
```

### 生成缓慢

* 减少 `推理步数` （30-50 通常就足够）
* 预览使用更低分辨率
* 确保 GPU 正在被使用（检查 `nvidia-smi`)

### 质量较差

* 将步数提高到 75-100
* 使用更具描述性的提示词
* 为伪影添加负面提示词
* 尝试不同的引导强度（5-10）

### 视频伪影

* 降低引导强度
* 增加推理步数
* 使用时间平滑
* 使用视频稳定化进行后期处理

## OpenSora 与其他方案对比

| 功能    | OpenSora 1.2 | Hunyuan | Wan2.1     | SVD   |
| ----- | ------------ | ------- | ---------- | ----- |
| 架构    | DiT          | DiT     | DiT        | U-Net |
| 最大时长  | 16秒          | 5秒      | 5秒         | 4秒    |
| 最大分辨率 | 720p         | 720p    | 720p       | 576p  |
| 质量    | 很高           | 优秀      | 优秀         | 好     |
| 速度    | 中等           | 慢       | 快          | 快     |
| 许可证   | Apache 2.0   | 打开      | Apache 2.0 | 打开    |

**在以下情况下使用 OpenSora：**

* 需要更长的视频生成
* 希望使用完整的 Apache 2.0 许可证
* 对类似 Sora 的架构感兴趣
* 需要活跃的社区支持

## Open-Sora-Plan 替代方案

另一个开源选项：

```bash
git clone https://github.com/PKU-YuanGroup/Open-Sora-Plan
cd Open-Sora-Plan
pip install -e .

python scripts/inference.py \
    --prompt "你的提示词" \
    --output video.mp4
```

## 下一步

* [Hunyuan Video](/guides/guides_v2-zh/shi-pin-sheng-cheng/hunyuan-video.md) - 高质量文本生成视频
* [Wan2.1 视频](/guides/guides_v2-zh/shi-pin-sheng-cheng/wan-video.md) - 快速生成
* [Stable Video Diffusion](/guides/guides_v2-zh/shi-pin-sheng-cheng/stable-video-diffusion.md) - 图像动画
* [RIFE 插帧](/guides/guides_v2-zh/shi-pin-chu-li/rife-interpolation.md) - 帧插值


---

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