#
# 根据 Apache 许可证 2.0 版本（“许可证”）授权
# 您只能在遵守许可证的情况下使用本文件。
# 您可以在以下位置获取许可证副本
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# 除非适用法律要求或双方书面同意，软件
# 根据许可证分发，本软件按“原样”
# 不附带任何明示或暗示的保证或条件。
# 请参阅许可证中关于权限的具体语言
# 许可证下的限制。-->

# HunyuanVideo-1.5

HunyuanVideo-1.5 是一款轻量级但功能强大的视频生成模型，仅使用 83 亿参数即可实现最先进的视觉质量和运动连贯性，从而支持在消费级 GPU 上进行高效推理。这一成果建立在多个关键组件之上，包括精细的数据筛选、采用选择性滑动块注意力（SSTA）的先进 DiT 架构、通过字形感知文本编码增强的双语理解能力、渐进式预训练和后训练，以及高效的视频超分辨率网络。借助这些设计，我们开发了一个统一框架，能够在多种时长和分辨率下实现高质量的文本到视频和图像到视频生成。大量实验表明，这款紧凑且高效的模型在开源模型中确立了新的最先进水平。

您可以在 [Tencent](https://huggingface.co/tencent) 组织下找到所有原始的 HunyuanVideo 检查点。

> [!TIP]
> 点击右侧边栏中的 HunyuanVideo 模型，以查看更多视频生成任务的示例。
>
> 以下示例使用 [hunyuanvideo-community](https://huggingface.co/hunyuanvideo-community) 的检查点，因为其权重存储在与 Diffusers 兼容的布局中。

下面的示例演示了如何生成针对内存或推理速度进行优化的视频。

有关各种内存节省技术的详细信息，请参阅 [减少内存使用](../../optimization/memory) 指南。

```py
import torch
from diffusers import AutoModel, HunyuanVideo15Pipeline
from diffusers.utils import export_to_video

pipeline = HunyuanVideo15Pipeline.from_pretrained(
    "HunyuanVideo-1.5-Diffusers-480p_t2v",
    dtype=torch.bfloat16,
)

# model-offloading and tiling
pipeline.enable_model_cpu_offload()
pipeline.vae.enable_tiling()

prompt = "A fluffy teddy bear sits on a bed of soft pillows surrounded by children's toys."
video = pipeline(prompt=prompt, num_frames=61, num_inference_steps=30).frames[0]
export_to_video(video, "output.mp4", fps=15)
```

## 备注

- HunyuanVideo1.5 使用注意力掩码来处理变长序列。为了获得最佳性能，我们建议使用能够高效处理填充的注意力后端。

    - **H100/H800：** `_flash_3_hub` 或 `_flash_3_varlen_hub`
    - **A100/A800/RTX 4090：**`flash_hub` 或 `flash_varlen_hub`
    - **其他 GPU：** `sage_hub`

有关使用不同后端的详细信息，请参阅 [Attention 后端](../../optimization/attention_backends) 指南。

```py
pipe.transformer.set_attention_backend("flash_hub")  # or your preferred backend
```

- [HunyuanVideo15Pipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/hunyuan_video15#diffusers.HunyuanVideo15Pipeline) 使用 guider，运行时不接受 `guidance_scale` 参数。

您可以使用 `pipe.guider` 查看默认的 guider 配置：

```py
>>> pipe.guider 
ClassifierFreeGuidance {
  "_class_name": "ClassifierFreeGuidance",
  "_diffusers_version": "0.36.0.dev0",
  "enabled": true,
  "guidance_rescale": 0.0,
  "guidance_scale": 6.0,
  "start": 0.0,
  "stop": 1.0,
  "use_original_formulation": false
}

State:
  step: None
  num_inference_steps: None
  timestep: None
  count_prepared: 0
  enabled: True
  num_conditions: 2
```

要更新 guider 配置，您可以运行 `pipe.guider = pipe.guider.new(...)`

```py
pipe.guider = pipe.guider.new(guidance_scale=5.0)
```

有关 Guider 的更多信息，请参见[此处](../../using-diffusers/guiders)。

## HunyuanVideo15Pipeline[[diffusers.HunyuanVideo15Pipeline]]

#### diffusers.HunyuanVideo15Pipeline[[diffusers.HunyuanVideo15Pipeline]]

```python
diffusers.HunyuanVideo15Pipeline(text_encoder: Qwen2_5_VLTextModel, tokenizer: Qwen2Tokenizer, transformer: HunyuanVideo15Transformer3DModel, vae: AutoencoderKLHunyuanVideo15, scheduler: FlowMatchEulerDiscreteScheduler, text_encoder_2: T5EncoderModel, tokenizer_2: ByT5Tokenizer, guider: ClassifierFreeGuidance)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/hunyuan_video1_5/pipeline_hunyuan_video1_5.py#L166)

**参数：**

transformer ([HunyuanVideo15Transformer3DModel](/docs/diffusers/v0.43.0/zh/api/models/hunyuan_video15_transformer_3d#diffusers.HunyuanVideo15Transformer3DModel))：用于对编码后的视频潜变量进行去噪的条件 Transformer (MMDiT) 架构。

scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/v0.43.0/zh/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler))：用于与 `transformer` 配合，对编码后的视频潜变量进行去噪的调度器。

vae ([AutoencoderKLHunyuanVideo15](/docs/diffusers/v0.43.0/zh/api/models/autoencoder_kl_hunyuan_video15#diffusers.AutoencoderKLHunyuanVideo15))：变分自编码器（VAE）模型，用于将视频编码为潜在表示，以及从潜在表示解码为视频。

text_encoder (`Qwen2.5-VL-7B-Instruct`)：即 [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct)，具体为 [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct) 变体。

tokenizer (`Qwen2Tokenizer`)：[Qwen2Tokenizer] 类的分词器。

text_encoder_2 (`T5EncoderModel`) : [T5EncoderModel](https://huggingface.co/docs/transformers/en/model_doc/t5#transformers.T5EncoderModel) 变体。

tokenizer_2 (`ByT5Tokenizer`)：[ByT5Tokenizer] 类的分词器

guider ([ClassifierFreeGuidance](/docs/diffusers/v0.43.0/zh/api/modular_diffusers/guiders#diffusers.ClassifierFreeGuidance))：[ClassifierFreeGuidance]，用于无分类器引导。

使用 HunyuanVideo1.5 进行文本到视频生成的 Pipeline。

该模型继承自 [DiffusionPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/overview#diffusers.DiffusionPipeline)。有关为所有流水线实现的通用方法（下载、保存、在特定设备上运行等），请参阅父类文档。

#### __调用__[[diffusers.HunyuanVideo15Pipeline.__call__]]

```python
__call__(prompt: str | list[str] = None, negative_prompt: str | list[str] = None, height: int | None = None, width: int | None = None, num_frames: int = 121, num_inference_steps: int = 50, sigmas: list[float] = None, num_videos_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_mask: typing.Optional[torch.Tensor] = None, prompt_embeds_2: typing.Optional[torch.Tensor] = None, prompt_embeds_mask_2: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_2: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_mask_2: typing.Optional[torch.Tensor] = None, output_type: str | None = 'np', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/hunyuan_video1_5/pipeline_hunyuan_video1_5.py#L542)

**参数：**

prompt (`str` 或 `list[str]`，*可选*)：用于引导图像生成的提示词或提示词列表。如果未定义，则必须传入 `prompt_embeds`。

negative_prompt (`str` 或 `list[str]`，*可选*)：用于引导图像生成的负面提示词。如果未定义，则必须传入 `negative_prompt_embeds`。

height (`int`, *可选*) : 生成视频的高度（以像素为单位）。

width (`int`，*可选*)：生成视频的像素宽度。

num_frames (`int`，默认为 `121`)：生成视频的帧数。

num_inference_steps (`int`，默认为 `50`)：去噪步数。更多的去噪步数通常能带来更高质量的视频，但代价是推理速度变慢。

sigmas (`list[float]`, *可选*) : 用于支持在 `set_timesteps` 方法中接受 `sigmas` 参数的调度器的去噪过程的自定义 sigmas。如果未定义，将使用传入 `num_inference_steps` 时的默认行为。

num_videos_per_prompt (`int`，*可选*，默认为 1)：每个提示词生成的视频数量。

generator (`torch.Generator` 或 `list[torch.Generator]`，*可选*)：用于使生成过程确定性的 [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html)。

latents (`torch.Tensor`, *可选*) : 从高斯分布中采样的预生成噪声潜变量，用作视频生成的输入。可用于使用不同的提示词对同一生成过程进行微调。如果未提供，则使用提供的随机`generator`进行采样来生成潜变量张量。

prompt_embeds (`torch.Tensor`, *可选*) : 预生成的文本嵌入。可用于轻松调整文本输入（提示词权重）。如果未提供，则从 `prompt` 输入参数生成文本嵌入。

prompt_embeds_mask (`torch.Tensor`, *可选*) : 为提示嵌入预生成的掩码。

negative_prompt_embeds (`torch.Tensor`, *可选*) : 预生成的负向文本嵌入。可用于轻松调整文本输入，*例如* 提示词权重。如果未提供，negative_prompt_embeds 将从 `negative_prompt` 输入参数生成。

negative_prompt_embeds_mask (`torch.Tensor`, *可选*) : 用于负提示嵌入的预生成掩码。

prompt_embeds_2 (`torch.Tensor`, *可选*) : 来自第二个文本编码器的预生成文本嵌入。可用于轻松调整文本输入。

prompt_embeds_mask_2 (`torch.Tensor`, *可选*) : 来自第二个文本编码器的提示嵌入的预生成掩码。

negative_prompt_embeds_2 (`torch.Tensor`, *可选*) : 由第二个文本编码器预生成的负样本文本嵌入。

negative_prompt_embeds_mask_2 (`torch.Tensor`, *可选*) : 来自第二个文本编码器的负提示嵌入的预生成掩码。

output_type (`str`，*可选*，默认为 `"np"`)：生成视频的输出格式。可选值为 "np"、"pt" 或 "latent"。

return_dict (`bool`，*可选*，默认为 `True`)：是否返回 `HunyuanVideo15PipelineOutput` 而不是普通元组。

attention_kwargs (`dict`, *可选*) : 一个 kwargs 字典，如果指定，将作为参数传递给 [diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py) 中 `self.processor` 下定义的 `AttentionProcessor`。

**返回：** `~HunyuanVideo15PipelineOutput` 或 `tuple`

如果 `return_dict` 为 `True`，则返回 `HunyuanVideo15PipelineOutput`；否则返回一个 `tuple`，其中第一个元素是包含生成视频的列表。

用于生成的 pipeline 的调用函数。

示例：
```python
>>> import torch
>>> from diffusers import HunyuanVideo15Pipeline
>>> from diffusers.utils import export_to_video

>>> model_id = "hunyuanvideo-community/HunyuanVideo-1.5-480p_t2v"
>>> pipe = HunyuanVideo15Pipeline.from_pretrained(model_id, torch_dtype=torch.float16)
>>> pipe.vae.enable_tiling()
>>> pipe.to("cuda")

>>> output = pipe(
...     prompt="A cat walks on the grass, realistic",
...     num_inference_steps=50,
... ).frames[0]
>>> export_to_video(output, "output.mp4", fps=15)
```

#### encode_prompt[[diffusers.HunyuanVideo15Pipeline.encode_prompt]]

```python
encode_prompt(prompt: str | list[str], device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None, batch_size: int = 1, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, prompt_embeds_2: typing.Optional[torch.Tensor] = None, prompt_embeds_mask_2: typing.Optional[torch.Tensor] = None)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/hunyuan_video1_5/pipeline_hunyuan_video1_5.py#L334)

**参数：**

prompt (`str` 或 `list[str]`，*可选*)：要编码的提示

device : (`torch.device`): torch 设备

batch_size (`int`)：提示词的批次大小，默认为 1

num_videos_per_prompt (`int`) : 每个提示词应生成的图像数量

prompt_embeds (`torch.Tensor`, *可选*) : 预生成的文本嵌入。如果未提供，则将从 `prompt` 输入参数生成文本嵌入。

prompt_embeds_mask (`torch.Tensor`，*可选*)：预生成的文本掩码。如果未提供，则会根据 `prompt` 输入参数生成文本掩码。

prompt_embeds_2 (`torch.Tensor`, *可选*) : 由 ByT5 预生成的字形文本嵌入。如果未提供，将使用 self.tokenizer_2 和 self.text_encoder_2 从 `prompt` 输入参数生成。

prompt_embeds_mask_2 (`torch.Tensor`, *可选*) : 由 ByT5 预生成的字形文本掩码。如果未提供，将使用 self.tokenizer_2 和 self.text_encoder_2 从 `prompt` 输入参数生成。

#### prepare_cond_latents_and_mask[[diffusers.HunyuanVideo15Pipeline.prepare_cond_latents_and_mask]]

```python
prepare_cond_latents_and_mask(latents, dtype: typing.Optional[torch.dtype], device: typing.Optional[torch.device])
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/hunyuan_video1_5/pipeline_hunyuan_video1_5.py#L508)

**参数：**

latents : 主潜在张量 (B, C, F, H, W)

**返回：** `tuple`

(cond_latents_concat, mask_concat) - 对于 t2v，两者均为零张量

为 t2v 生成准备条件潜变量和掩码。

## HunyuanVideo15ImageToVideoPipeline[[diffusers.HunyuanVideo15ImageToVideoPipeline]]

#### diffusers.HunyuanVideo15ImageToVideoPipeline[[diffusers.HunyuanVideo15ImageToVideoPipeline]]

```python
diffusers.HunyuanVideo15ImageToVideoPipeline(text_encoder: Qwen2_5_VLTextModel, tokenizer: Qwen2Tokenizer, transformer: HunyuanVideo15Transformer3DModel, vae: AutoencoderKLHunyuanVideo15, scheduler: FlowMatchEulerDiscreteScheduler, text_encoder_2: T5EncoderModel, tokenizer_2: ByT5Tokenizer, guider: ClassifierFreeGuidance, image_encoder: SiglipVisionModel, feature_extractor: SiglipImageProcessorPil)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/hunyuan_video1_5/pipeline_hunyuan_video1_5_image2video.py#L193)

**参数：**

transformer ([HunyuanVideo15Transformer3DModel](/docs/diffusers/v0.43.0/zh/api/models/hunyuan_video15_transformer_3d#diffusers.HunyuanVideo15Transformer3DModel))：用于对编码后的视频潜变量进行去噪的条件 Transformer (MMDiT) 架构。

scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/v0.43.0/zh/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler))：用于与 `transformer` 配合，对编码后的视频潜变量进行去噪的调度器。

vae ([AutoencoderKLHunyuanVideo15](/docs/diffusers/v0.43.0/zh/api/models/autoencoder_kl_hunyuan_video15#diffusers.AutoencoderKLHunyuanVideo15))：变分自编码器（VAE）模型，用于将视频编码为潜在表示，以及从潜在表示解码为视频。

text_encoder (`Qwen2.5-VL-7B-Instruct`)：即 [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct)，具体为 [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct) 变体。

tokenizer (`Qwen2Tokenizer`)：[Qwen2Tokenizer] 类的分词器。

text_encoder_2 (`T5EncoderModel`) : [T5EncoderModel](https://huggingface.co/docs/transformers/en/model_doc/t5#transformers.T5EncoderModel) 变体。

tokenizer_2 (`ByT5Tokenizer`)：[ByT5Tokenizer] 类的分词器

guider ([ClassifierFreeGuidance](/docs/diffusers/v0.43.0/zh/api/modular_diffusers/guiders#diffusers.ClassifierFreeGuidance))：[ClassifierFreeGuidance]，用于无分类器引导。

image_encoder (`SiglipVisionModel`)：[SiglipVisionModel](https://huggingface.co/docs/transformers/en/model_doc/siglip#transformers.SiglipVisionModel) 变体。

feature_extractor (`SiglipImageProcessor`) : [SiglipImageProcessor](https://huggingface.co/docs/transformers/en/model_doc/siglip#transformers.SiglipImageProcessor) 变体。

使用 HunyuanVideo1.5 进行图像到视频生成的 Pipeline。

该模型继承自 [DiffusionPipeline](/docs/diffusers/v0.43.0/zh/api/pipelines/overview#diffusers.DiffusionPipeline)。有关为所有流水线实现的通用方法（下载、保存、在特定设备上运行等），请参阅父类文档。

#### __调用__[[diffusers.HunyuanVideo15ImageToVideoPipeline.__call__]]

```python
__call__(image: Image, prompt: str | list[str] = None, negative_prompt: str | list[str] = None, num_frames: int = 121, num_inference_steps: int = 50, sigmas: list[float] = None, num_videos_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_mask: typing.Optional[torch.Tensor] = None, prompt_embeds_2: typing.Optional[torch.Tensor] = None, prompt_embeds_mask_2: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_2: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_mask_2: typing.Optional[torch.Tensor] = None, output_type: str | None = 'np', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/hunyuan_video1_5/pipeline_hunyuan_video1_5_image2video.py#L650)

**参数：**

image (`PIL.Image.Image`)：用于条件化视频生成的输入图像。

prompt (`str` 或 `list[str]`，*可选*)：用于引导视频生成的提示词或提示词列表。如果未定义，则必须传入 `prompt_embeds`。

negative_prompt (`str` 或 `list[str]`，*可选*)：用于引导视频生成的负面提示词。如果未定义，则必须传入 `negative_prompt_embeds`。

num_frames (`int`，默认为 `121`)：生成视频的帧数。

num_inference_steps (`int`，默认为 `50`)：去噪步数。更多的去噪步数通常能带来更高质量的视频，但代价是推理速度变慢。

sigmas (`list[float]`, *可选*) : 用于支持在 `set_timesteps` 方法中接受 `sigmas` 参数的调度器的去噪过程的自定义 sigmas。如果未定义，将使用传入 `num_inference_steps` 时的默认行为。

num_videos_per_prompt (`int`，*可选*，默认为 1)：每个提示词生成的视频数量。

generator (`torch.Generator` 或 `list[torch.Generator]`，*可选*)：用于使生成过程确定性的 [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html)。

latents (`torch.Tensor`, *可选*) : 从高斯分布中采样的预生成噪声潜变量，用作视频生成的输入。可用于使用不同的提示词对同一生成过程进行微调。如果未提供，则使用提供的随机`generator`进行采样来生成潜变量张量。

prompt_embeds (`torch.Tensor`, *可选*) : 预生成的文本嵌入。可用于轻松调整文本输入（提示词权重）。如果未提供，则从 `prompt` 输入参数生成文本嵌入。

prompt_embeds_mask (`torch.Tensor`, *可选*) : 为提示嵌入预生成的掩码。

negative_prompt_embeds (`torch.Tensor`, *可选*) : 预生成的负向文本嵌入。可用于轻松调整文本输入，*例如* 提示词权重。如果未提供，negative_prompt_embeds 将从 `negative_prompt` 输入参数生成。

negative_prompt_embeds_mask (`torch.Tensor`, *可选*) : 用于负提示嵌入的预生成掩码。

prompt_embeds_2 (`torch.Tensor`, *可选*) : 来自第二个文本编码器的预生成文本嵌入。可用于轻松调整文本输入。

prompt_embeds_mask_2 (`torch.Tensor`, *可选*) : 来自第二个文本编码器的提示嵌入的预生成掩码。

negative_prompt_embeds_2 (`torch.Tensor`, *可选*) : 由第二个文本编码器预生成的负样本文本嵌入。

negative_prompt_embeds_mask_2 (`torch.Tensor`, *可选*) : 来自第二个文本编码器的负提示嵌入的预生成掩码。

output_type (`str`，*可选*，默认为 `"np"`)：生成视频的输出格式。可选值为 "np"、"pt" 或 "latent"。

return_dict (`bool`，*可选*，默认为 `True`)：是否返回 `HunyuanVideo15PipelineOutput` 而不是普通元组。

attention_kwargs (`dict`, *可选*) : 一个 kwargs 字典，如果指定，将作为参数传递给 [diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py) 中 `self.processor` 下定义的 `AttentionProcessor`。

**返回：** `~HunyuanVideo15PipelineOutput` 或 `tuple`

如果 `return_dict` 为 `True`，则返回 `HunyuanVideo15PipelineOutput`；否则返回一个 `tuple`，其中第一个元素是包含生成视频的列表。

用于生成的 pipeline 的调用函数。

示例：
```python
>>> import torch
>>> from diffusers import HunyuanVideo15ImageToVideoPipeline
>>> from diffusers.utils import export_to_video

>>> model_id = "hunyuanvideo-community/HunyuanVideo-1.5-480p_i2v"
>>> pipe = HunyuanVideo15ImageToVideoPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
>>> pipe.vae.enable_tiling()
>>> pipe.to("cuda")

>>> image = load_image("https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/wan_i2v_input.JPG")

>>> output = pipe(
...     prompt="Summer beach vacation style, a white cat wearing sunglasses sits on a surfboard. The fluffy-furred feline gazes directly at the camera with a relaxed expression. Blurred beach scenery forms the background featuring crystal-clear waters, distant green hills, and a blue sky dotted with white clouds. The cat assumes a naturally relaxed posture, as if savoring the sea breeze and warm sunlight. A close-up shot highlights the feline's intricate details and the refreshing atmosphere of the seaside.",
...     image=image,
...     num_inference_steps=50,
... ).frames[0]
>>> export_to_video(output, "output.mp4", fps=24)
```

#### encode_prompt[[diffusers.HunyuanVideo15ImageToVideoPipeline.encode_prompt]]

```python
encode_prompt(prompt: str | list[str], device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None, batch_size: int = 1, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, prompt_embeds_2: typing.Optional[torch.Tensor] = None, prompt_embeds_mask_2: typing.Optional[torch.Tensor] = None)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/hunyuan_video1_5/pipeline_hunyuan_video1_5_image2video.py#L422)

**参数：**

prompt (`str` 或 `list[str]`，*可选*)：要编码的提示

device : (`torch.device`): torch 设备

batch_size (`int`)：提示词的批次大小，默认为 1

num_videos_per_prompt (`int`) : 每个提示词应生成的图像数量

prompt_embeds (`torch.Tensor`, *可选*) : 预生成的文本嵌入。如果未提供，则将从 `prompt` 输入参数生成文本嵌入。

prompt_embeds_mask (`torch.Tensor`，*可选*)：预生成的文本掩码。如果未提供，则会根据 `prompt` 输入参数生成文本掩码。

prompt_embeds_2 (`torch.Tensor`, *可选*) : 由 ByT5 预生成的字形文本嵌入。如果未提供，将使用 self.tokenizer_2 和 self.text_encoder_2 从 `prompt` 输入参数生成。

prompt_embeds_mask_2 (`torch.Tensor`, *可选*) : 由 ByT5 预生成的字形文本掩码。如果未提供，将使用 self.tokenizer_2 和 self.text_encoder_2 从 `prompt` 输入参数生成。

#### prepare_cond_latents_and_mask[[diffusers.HunyuanVideo15ImageToVideoPipeline.prepare_cond_latents_and_mask]]

```python
prepare_cond_latents_and_mask(latents: Tensor, image: Image, batch_size: int, height: int, width: int, dtype: dtype, device: device)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/hunyuan_video1_5/pipeline_hunyuan_video1_5_image2video.py#L594)

**参数：**

latents : 主潜在张量 (B, C, F, H, W)

**返回：** `tuple`

(cond_latents_concat, mask_concat) - 对于 t2v，两者均为零张量

为 t2v 生成准备条件潜变量和掩码。

## HunyuanVideo15PipelineOutput[[diffusers.pipelines.hunyuan_video1_5.pipeline_output.HunyuanVideo15PipelineOutput]]

#### diffusers.pipelines.hunyuan_video1_5.pipeline_output.HunyuanVideo15PipelineOutput[[diffusers.pipelines.hunyuan_video1_5.pipeline_output.HunyuanVideo15PipelineOutput]]

```python
diffusers.pipelines.hunyuan_video1_5.pipeline_output.HunyuanVideo15PipelineOutput(frames: Tensor)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/hunyuan_video1_5/pipeline_output.py#L9)

**参数：**

frames (`torch.Tensor`、`np.ndarray` 或 list[list[PIL.Image.Image]]) : 视频输出列表 - 它可以是一个长度为 `batch_size,` 的嵌套列表，其中每个子列表包含长度为 `num_frames.` 的去噪 PIL 图像序列。它也可以是一个形状为 `(batch_size, num_frames, channels, height, width)` 的 NumPy 数组或 Torch 张量。

HunyuanVideo1.5 管道的输出类。

