# Motif-Video

[Báo cáo kỹ thuật](https://arxiv.org/abs/2604.16503)

Motif-Video là một diffusion transformer có 2B tham số, được thiết kế cho việc tạo video từ văn bản và tạo video từ hình ảnh. Nó có kiến trúc ba giai đoạn với 12 lớp dual-stream + 16 lớp single-stream + 8 lớp DDT decoder, Shared Cross-Attention để đảm bảo sự căn chỉnh ổn định giữa văn bản và video trong các chuỗi video dài, text encoder T5Gemma2, và rectified flow matching để dự đoán vận tốc.

  

## Tạo video từ văn bản

Sử dụng `MotifVideoPipeline` để tạo video từ văn bản:

```python
import torch
from diffusers import MotifVideoPipeline
from diffusers.utils import export_to_video

pipe = MotifVideoPipeline.from_pretrained(
    "Motif-Technologies/Motif-Video-2B",
    dtype=torch.bfloat16,
)
pipe.to("cuda")  # or "mps", "xpu", "cpu"

prompt = "A woman with long brown hair and light skin smiles at another woman with long blonde hair."
negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted"

video = pipe(
    prompt=prompt,
    negative_prompt=negative_prompt,
    width=1280,
    height=736,
    num_frames=121,
    num_inference_steps=50,
).frames[0]
export_to_video(video, "output.mp4", fps=24)
```

## Tạo video từ ảnh

Sử dụng `MotifVideoImage2VideoPipeline` để tạo video từ ảnh:

```python
import torch
from diffusers import MotifVideoImage2VideoPipeline
from diffusers.utils import export_to_video, load_image

pipe = MotifVideoImage2VideoPipeline.from_pretrained(
    "Motif-Technologies/Motif-Video-2B",
    dtype=torch.bfloat16,
)
pipe.to("cuda")  # or "mps", "xpu", "cpu"

image = load_image("input_image.png")
prompt = "A cinematic scene with vivid colors."
negative_prompt = "worst quality, blurry, jittery, distorted"

video = pipe(
    image=image,
    prompt=prompt,
    negative_prompt=negative_prompt,
    width=1280,
    height=736,
    num_frames=121,
    num_inference_steps=50,
).frames[0]
export_to_video(video, "i2v_output.mp4", fps=24)
```

### Suy luận tiết kiệm bộ nhớ

Đối với GPU có VRAM dưới 30GB (ví dụ: RTX 4090), hãy sử dụng model CPU offloading:

```bash
export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
```

```python
import torch
from diffusers import MotifVideoPipeline
from diffusers.utils import export_to_video

pipe = MotifVideoPipeline.from_pretrained(
    "Motif-Technologies/Motif-Video-2B",
    dtype=torch.bfloat16,
)
pipe.enable_model_cpu_offload()

prompt = "A woman with long brown hair and light skin smiles at another woman with long blonde hair."
negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted"

video = pipe(
    prompt=prompt,
    negative_prompt=negative_prompt,
    width=1280,
    height=736,
    num_frames=121,
    num_inference_steps=50,
).frames[0]
export_to_video(video, "output.mp4", fps=24)
```

## MotifVideoPipeline[[diffusers.MotifVideoPipeline]]

#### diffusers.MotifVideoPipeline[[diffusers.MotifVideoPipeline]]

```python
diffusers.MotifVideoPipeline(scheduler: SchedulerMixin, vae: AutoencoderKLWan, text_encoder: T5Gemma2Encoder, tokenizer: PreTrainedTokenizerBase, transformer: MotifVideoTransformer3DModel, guider: BaseGuidance, feature_extractor: typing.Optional[transformers.models.siglip.image_processing_pil_siglip.SiglipImageProcessorPil] = None)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/motif_video/pipeline_motif_video.py#L148)

**Tham số:**

transformer ([MotifVideoTransformer3DModel](/docs/diffusers/main/vi/api/models/motif_video_transformer_3d#diffusers.MotifVideoTransformer3DModel)) : Kiến trúc Transformer có điều kiện để khử nhiễu các latents video đã mã hóa.

scheduler ([SchedulerMixin](/docs/diffusers/main/vi/api/schedulers/overview#diffusers.SchedulerMixin)) : Một scheduler được sử dụng kết hợp với `transformer` để khử nhiễu các video latents đã được mã hóa. Phải là một instance của một class kế thừa từ `SchedulerMixin`, chẳng hạn như [DPMSolverMultistepScheduler](/docs/diffusers/main/vi/api/schedulers/multistep_dpm_solver#diffusers.DPMSolverMultistepScheduler). Nếu không được cung cấp, sẽ sử dụng scheduler gắn với model được huấn luyện trước.

vae ([AutoencoderKLWan](/docs/diffusers/main/vi/api/models/autoencoder_kl_wan#diffusers.AutoencoderKLWan)) : Mô hình Variational Auto-Encoder (VAE) để mã hóa và giải mã video sang và từ các biểu diễn ẩn.

text_encoder (`T5Gemma2Encoder`) : Bộ mã hóa văn bản chính để mã hóa các prompt văn bản thành các embedding.

tokenizer (`PreTrainedTokenizerBase`) : Tokenizer tương ứng với bộ mã hóa văn bản chính.

guider ([BaseGuidance](/docs/diffusers/main/vi/api/modular_diffusers/guiders#diffusers.BaseGuidance)) : Phương pháp guidance cần sử dụng. Phải là một instance của class kế thừa từ `BaseGuidance`, chẳng hạn như [ClassifierFreeGuidance](/docs/diffusers/main/vi/api/modular_diffusers/guiders#diffusers.ClassifierFreeGuidance), [AdaptiveProjectedGuidance](/docs/diffusers/main/vi/api/modular_diffusers/guiders#diffusers.AdaptiveProjectedGuidance), hoặc [SkipLayerGuidance](/docs/diffusers/main/vi/api/modular_diffusers/guiders#diffusers.SkipLayerGuidance). Nếu không được cung cấp, mặc định là `ClassifierFreeGuidance`.

Pipeline để tạo video từ văn bản sử dụng Motif-Video.

Mô hình này kế thừa từ [DiffusionPipeline](/docs/diffusers/main/vi/api/pipelines/overview#diffusers.DiffusionPipeline). Xem tài liệu của lớp cha để biết các phương thức chung được triển khai cho tất cả các pipeline (tải xuống, lưu, chạy trên một thiết bị cụ thể, v.v.).

#### __call__[[diffusers.MotifVideoPipeline.__call__]]

```python
__call__(prompt: typing.Union[str, typing.List[str], NoneType] = None, negative_prompt: typing.Union[str, typing.List[str], NoneType] = None, height: int = 736, width: int = 1280, num_frames: int = 121, num_inference_steps: int = 50, timesteps: typing.Optional[typing.List[int]] = None, num_videos_per_prompt: typing.Optional[int] = 1, generator: typing.Union[torch.Generator, typing.List[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_attention_mask: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_attention_mask: typing.Optional[torch.Tensor] = None, output_type: typing.Optional[str] = 'pil', return_dict: bool = True, attention_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = None, callback_on_step_end: typing.Union[typing.Callable[[int, int, typing.Dict], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'], max_sequence_length: int = 512, vae_batch_size: int | None = None)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/motif_video/pipeline_motif_video.py#L492)

**Tham số:**

prompt (`str` hoặc `List[str]`, *tùy chọn*) : Prompt hoặc các prompt để định hướng việc tạo video. Nếu không được định nghĩa, bạn phải truyền `prompt_embeds`.

negative_prompt (`str` hoặc `List[str]`, *tùy chọn*) : Prompt hoặc các prompt không được dùng để định hướng việc tạo video. Nếu không được định nghĩa, bạn phải truyền `negative_prompt_embeds` thay thế. Bỏ qua khi không sử dụng guidance.

height (`int`, mặc định là `736`) : Chiều cao của video được tạo ra, tính bằng pixel.

width (`int`, mặc định là `1280`) : Độ rộng của video được tạo ra, tính bằng pixel.

num_frames (`int`, mặc định là `121`) : Số khung hình video cần tạo.

num_inference_steps (`int`, *optional*, mặc định là 50) : Số bước khử nhiễu. Số bước khử nhiễu nhiều hơn thường dẫn đến video có chất lượng cao hơn, đổi lại là suy luận chậm hơn.

timesteps (`List[int]`, *tùy chọn*) : Các bước thời gian tùy chỉnh để sử dụng cho quá trình khử nhiễu.

num_videos_per_prompt (`int`, *tuỳ chọn*, mặc định là 1) : Số lượng video cần tạo cho mỗi prompt.

generator (`torch.Generator` hoặc `List[torch.Generator]`, *tùy chọn*) : Đối tượng Generator của PyTorch để tạo ra kết quả xác định.

latents (`torch.Tensor`, *tùy chọn*) : Các latents nhiễu đã được tạo trước.

prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước.

prompt_attention_mask (`torch.Tensor`, *tùy chọn*) : Mặt nạ chú ý (attention mask) được tạo trước cho các vector nhúng văn bản.

negative_prompt_embeds (`torch.FloatTensor`, *tùy chọn*) : Các vector nhúng văn bản âm đã được tạo trước.

negative_prompt_attention_mask (`torch.FloatTensor`, *tùy chọn*) : Mặt nạ chú ý (attention mask) được tạo trước cho các vector nhúng văn bản âm.

output_type (`str`, *tùy chọn*, mặc định là `"pil"`) : Định dạng đầu ra của video được tạo. Chọn giữa `"pil"`, `"np"` hoặc `"latent"`.

return_dict (`bool`, *tuỳ chọn*, mặc định là `True`) : Có nên trả về một [~MotifVideoPipelineOutput](/docs/diffusers/main/vi/api/pipelines/motif_video#diffusers.MotifVideoPipelineOutput) thay vì một tuple thông thường hay không.

attention_kwargs (`dict`, *tùy chọn*) : Các đối số được truyền cho bộ xử lý chú ý.

callback_on_step_end (`Callable`, *tùy chọn*) : Một hàm hoặc lớp con của `PipelineCallback` hoặc `MultiPipelineCallbacks` được gọi vào cuối mỗi bước khử nhiễu.

callback_on_step_end_tensor_inputs (`List`, *tùy chọn*) : Danh sách các đầu vào tensor cho hàm `callback_on_step_end`.

max_sequence_length (`int`, mặc định là `512`) : Độ dài tối đa của chuỗi cho tokenizer.

vae_batch_size (`int`, *optional*) : Kích thước batch cho việc giải mã VAE. Nếu được cung cấp và kích thước batch của latents lớn hơn, việc giải mã VAE sẽ được thực hiện theo từng phần.

**Trả về:** [~MotifVideoPipelineOutput](/docs/diffusers/main/vi/api/pipelines/motif_video#diffusers.MotifVideoPipelineOutput) hoặc `tuple`

Nếu `return_dict` là `True`, [~MotifVideoPipelineOutput](/docs/diffusers/main/vi/api/pipelines/motif_video#diffusers.MotifVideoPipelineOutput) sẽ được trả về, ngược lại một `tuple` sẽ được trả về trong đó phần tử đầu tiên là một danh sách các khung hình video đã tạo.

Hàm gọi call của pipeline để tạo video từ văn bản.

Ví dụ:
```python
>>> import torch
>>> from diffusers import MotifVideoPipeline
>>> from diffusers.utils import export_to_video

>>> # Load the Motif-Video pipeline
>>> motif_video_model_id = "Motif-Technologies/Motif-Video-2B"
>>> pipe = MotifVideoPipeline.from_pretrained(motif_video_model_id, torch_dtype=torch.bfloat16)
>>> pipe.to("cuda")

>>> prompt = "A woman with long brown hair and light skin smiles at another woman with long blonde hair. The woman with brown hair wears a black jacket and has a small, barely noticeable mole on her right cheek. The camera angle is a close-up, focused on the woman with brown hair's face. The lighting is warm and natural, likely from the setting sun, casting a soft glow on the scene. The scene appears to be real-life footage"
>>> negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted"

>>> video = pipe(
...     prompt=prompt,
...     negative_prompt=negative_prompt,
...     width=1280,
...     height=736,
...     num_frames=121,
...     num_inference_steps=50,
... ).frames[0]
>>> export_to_video(video, "output.mp4", fps=24)
```

#### encode_prompt[[diffusers.MotifVideoPipeline.encode_prompt]]

```python
encode_prompt(prompt: typing.Union[str, typing.List[str]], negative_prompt: typing.Union[str, typing.List[str], NoneType] = None, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_attention_mask: typing.Optional[torch.Tensor] = None, negative_prompt_attention_mask: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 512, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/motif_video/pipeline_motif_video.py#L247)

**Tham số:**

prompt (`str` hoặc `List[str]`, *tùy chọn*) : Prompt hoặc các prompt cần được mã hóa.

negative_prompt (`str` hoặc `List[str]`, *tùy chọn*) : Prompt hoặc các prompt không được dùng để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `negative_prompt_embeds` thay thế. Bỏ qua khi không sử dụng guidance (tức là bị bỏ qua nếu `guidance_scale` nhỏ hơn `1`).

num_videos_per_prompt (`int`, *tuỳ chọn*, mặc định là 1) : Số lượng video cần tạo cho mỗi prompt.

prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước.

negative_prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản âm đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, negative_prompt_embeds sẽ được tạo từ đối số đầu vào `negative_prompt`.

prompt_attention_mask (`torch.Tensor`, *tùy chọn*) : Mặt nạ chú ý (attention mask) được tạo trước cho các vector nhúng văn bản.

negative_prompt_attention_mask (`torch.Tensor`, *tùy chọn*) : Mặt nạ chú ý (attention mask) được tạo trước cho các vector nhúng văn bản âm.

max_sequence_length (`int`, mặc định là 512) : Độ dài tối đa của chuỗi cho tokenizer.

device (`torch.device`, *tùy chọn*) : Thiết bị để đặt các tensor lên.

dtype (`torch.dtype`, *tùy chọn*) : Kiểu dữ liệu cho các tensor.

**Trả về:** `tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]`

Một tuple chứa:
- `prompt_embeds`: Các vector nhúng văn bản cho prompt tích cực
- `negative_prompt_embeds`: Các vector nhúng văn bản cho prompt tiêu cực (None nếu không sử dụng guidance)
- `prompt_attention_mask`: Mặt nạ chú ý (attention mask) cho prompt tích cực
- `negative_prompt_attention_mask`: Mặt nạ chú ý cho prompt âm (None nếu không sử dụng guidance)

Mã hóa prompt thành các trạng thái ẩn của text encoder.

## MotifVideoImage2VideoPipeline[[diffusers.MotifVideoImage2VideoPipeline]]

#### diffusers.MotifVideoImage2VideoPipeline[[diffusers.MotifVideoImage2VideoPipeline]]

```python
diffusers.MotifVideoImage2VideoPipeline(scheduler: SchedulerMixin, vae: AutoencoderKLWan, text_encoder: T5Gemma2Encoder, tokenizer: PreTrainedTokenizerBase, transformer: MotifVideoTransformer3DModel, guider: BaseGuidance, feature_extractor: SiglipImageProcessorPil)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/motif_video/pipeline_motif_video_image2video.py#L157)

**Tham số:**

transformer ([MotifVideoTransformer3DModel](/docs/diffusers/main/vi/api/models/motif_video_transformer_3d#diffusers.MotifVideoTransformer3DModel)) : Kiến trúc Transformer có điều kiện để khử nhiễu các latents video đã mã hóa.

scheduler ([SchedulerMixin](/docs/diffusers/main/vi/api/schedulers/overview#diffusers.SchedulerMixin)) : Một scheduler được sử dụng kết hợp với `transformer` để khử nhiễu các video latents đã được mã hóa. Phải là một instance của một class kế thừa từ `SchedulerMixin`, chẳng hạn như [DPMSolverMultistepScheduler](/docs/diffusers/main/vi/api/schedulers/multistep_dpm_solver#diffusers.DPMSolverMultistepScheduler). Nếu không được cung cấp, sẽ sử dụng scheduler gắn với model được huấn luyện trước.

vae ([AutoencoderKLWan](/docs/diffusers/main/vi/api/models/autoencoder_kl_wan#diffusers.AutoencoderKLWan)) : Mô hình Variational Auto-Encoder (VAE) để mã hóa và giải mã video sang và từ các biểu diễn ẩn.

text_encoder (`T5Gemma2Encoder`) : Bộ mã hóa văn bản chính để mã hóa các prompt văn bản thành các embedding.

tokenizer (`PreTrainedTokenizerBase`) : Tokenizer tương ứng với bộ mã hóa văn bản chính.

feature_extractor (`SiglipImageProcessor`) : Bộ xử lý ảnh cho bộ mã hóa thị giác SigLIP.

guider ([BaseGuidance](/docs/diffusers/main/vi/api/modular_diffusers/guiders#diffusers.BaseGuidance)) : Phương pháp guidance cần sử dụng. Phải là một instance của class kế thừa từ `BaseGuidance`, chẳng hạn như [ClassifierFreeGuidance](/docs/diffusers/main/vi/api/modular_diffusers/guiders#diffusers.ClassifierFreeGuidance), [AdaptiveProjectedGuidance](/docs/diffusers/main/vi/api/modular_diffusers/guiders#diffusers.AdaptiveProjectedGuidance), hoặc [SkipLayerGuidance](/docs/diffusers/main/vi/api/modular_diffusers/guiders#diffusers.SkipLayerGuidance). Nếu không được cung cấp, mặc định là `ClassifierFreeGuidance`.

Pipeline để tạo video từ hình ảnh sử dụng Motif-Video với điều kiện khung hình đầu tiên.

Mô hình này kế thừa từ [DiffusionPipeline](/docs/diffusers/main/vi/api/pipelines/overview#diffusers.DiffusionPipeline). Xem tài liệu của lớp cha để biết các phương thức chung được triển khai cho tất cả các pipeline (tải xuống, lưu, chạy trên một thiết bị cụ thể, v.v.).

#### __call__[[diffusers.MotifVideoImage2VideoPipeline.__call__]]

```python
__call__(image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]], prompt: typing.Union[str, typing.List[str]], negative_prompt: typing.Union[str, typing.List[str], NoneType] = None, height: int = 736, width: int = 1280, num_frames: int = 121, num_inference_steps: int = 50, timesteps: typing.Optional[typing.List[int]] = None, num_videos_per_prompt: typing.Optional[int] = 1, generator: typing.Union[torch.Generator, typing.List[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_attention_mask: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_attention_mask: typing.Optional[torch.Tensor] = None, output_type: typing.Optional[str] = 'pil', return_dict: bool = True, attention_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = None, callback_on_step_end: typing.Union[typing.Callable[[int, int, typing.Dict], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'], max_sequence_length: int = 512)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/motif_video/pipeline_motif_video_image2video.py#L620)

**Tham số:**

image (`PipelineImageInput`) : Ảnh đầu vào được sử dụng làm khung hình đầu tiên cho việc tạo video.

prompt (`str` hoặc `List[str]`) : Prompt hoặc các prompt để hướng dẫn việc tạo video.

negative_prompt (`str` hoặc `List[str]`, *tùy chọn*) : Prompt hoặc các prompt không được dùng để định hướng việc tạo video.

height (`int`, mặc định là `736`) : Chiều cao của video được tạo ra, tính bằng pixel.

width (`int`, mặc định là `1280`) : Độ rộng của video được tạo ra, tính bằng pixel.

num_frames (`int`, mặc định là `121`) : Số khung hình video cần tạo.

num_inference_steps (`int`, *tuỳ chọn*, mặc định là 50) : Số bước khử nhiễu.

timesteps (`List[int]`, *tùy chọn*) : Các bước thời gian tùy chỉnh để sử dụng cho quá trình khử nhiễu.

num_videos_per_prompt (`int`, *tuỳ chọn*, mặc định là 1) : Số lượng video cần tạo cho mỗi prompt.

generator (`torch.Generator` hoặc `List[torch.Generator]`, *tùy chọn*) : Đối tượng Generator của PyTorch để tạo ra kết quả xác định.

latents (`torch.Tensor`, *tùy chọn*) : Các latents nhiễu đã được tạo trước.

prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước.

prompt_attention_mask (`torch.Tensor`, *tùy chọn*) : Mặt nạ chú ý (attention mask) được tạo trước cho các vector nhúng văn bản.

negative_prompt_embeds (`torch.FloatTensor`, *tùy chọn*) : Các vector nhúng văn bản âm đã được tạo trước.

negative_prompt_attention_mask (`torch.FloatTensor`, *tùy chọn*) : Mặt nạ chú ý (attention mask) được tạo trước cho các vector nhúng văn bản âm.

output_type (`str`, *tùy chọn*, mặc định là `"pil"`) : Định dạng đầu ra của video được tạo.

return_dict (`bool`, *tuỳ chọn*, mặc định là `True`) : Có nên trả về một [~MotifVideoPipelineOutput](/docs/diffusers/main/vi/api/pipelines/motif_video#diffusers.MotifVideoPipelineOutput) thay vì một tuple thông thường hay không.

attention_kwargs (`dict`, *tùy chọn*) : Các đối số được truyền cho bộ xử lý chú ý.

callback_on_step_end (`Callable`, *tùy chọn*) : Một hàm hoặc lớp con của `PipelineCallback` được gọi vào cuối mỗi bước khử nhiễu.

callback_on_step_end_tensor_inputs (`List`, *tùy chọn*) : Danh sách các đầu vào tensor cho hàm `callback_on_step_end`.

max_sequence_length (`int`, mặc định là `512`) : Độ dài tối đa của chuỗi cho tokenizer.

**Trả về:** [~MotifVideoPipelineOutput](/docs/diffusers/main/vi/api/pipelines/motif_video#diffusers.MotifVideoPipelineOutput) hoặc `tuple`

Nếu `return_dict` là `True`, [~MotifVideoPipelineOutput](/docs/diffusers/main/vi/api/pipelines/motif_video#diffusers.MotifVideoPipelineOutput) sẽ được trả về, ngược lại một `tuple` sẽ được trả về trong đó phần tử đầu tiên là một danh sách các khung hình video đã tạo.

Hàm gọi của pipeline để tạo video từ ảnh.

Ví dụ:
```python
>>> import torch
>>> from PIL import Image
>>> from diffusers import MotifVideoImage2VideoPipeline
>>> from diffusers.utils import export_to_video, load_image

>>> # Load the Motif-Video image-to-video pipeline
>>> motif_video_model_id = "Motif-Technologies/Motif-Video-2B"
>>> pipe = MotifVideoImage2VideoPipeline.from_pretrained(motif_video_model_id, torch_dtype=torch.bfloat16)
>>> pipe.to("cuda")

>>> # Load an image
>>> image = load_image(
...     "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/astronaut.png"
... )

>>> prompt = "An astronaut is walking on the moon surface, kicking up dust with each step"
>>> negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted"

>>> video = pipe(
...     image=image,
...     prompt=prompt,
...     negative_prompt=negative_prompt,
...     width=1280,
...     height=736,
...     num_frames=121,
...     num_inference_steps=50,
... ).frames[0]
>>> export_to_video(video, "output.mp4", fps=24)
```

#### encode_prompt[[diffusers.MotifVideoImage2VideoPipeline.encode_prompt]]

```python
encode_prompt(prompt: typing.Union[str, typing.List[str]], negative_prompt: typing.Union[str, typing.List[str], NoneType] = None, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_attention_mask: typing.Optional[torch.Tensor] = None, negative_prompt_attention_mask: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 512, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/motif_video/pipeline_motif_video_image2video.py#L259)

**Tham số:**

prompt (`str` hoặc `List[str]`, *tùy chọn*) : Prompt hoặc các prompt cần được mã hóa.

negative_prompt (`str` hoặc `List[str]`, *tùy chọn*) : Prompt hoặc các prompt không được dùng để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `negative_prompt_embeds` thay thế. Bỏ qua khi không sử dụng guidance (tức là bị bỏ qua nếu `guidance_scale` nhỏ hơn `1`).

num_videos_per_prompt (`int`, *tuỳ chọn*, mặc định là 1) : Số lượng video cần tạo cho mỗi prompt.

prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước.

negative_prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản âm đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, negative_prompt_embeds sẽ được tạo từ đối số đầu vào `negative_prompt`.

prompt_attention_mask (`torch.Tensor`, *tùy chọn*) : Mặt nạ chú ý (attention mask) được tạo trước cho các vector nhúng văn bản.

negative_prompt_attention_mask (`torch.Tensor`, *tùy chọn*) : Mặt nạ chú ý (attention mask) được tạo trước cho các vector nhúng văn bản âm.

max_sequence_length (`int`, mặc định là 512) : Độ dài tối đa của chuỗi cho tokenizer.

device (`torch.device`, *tùy chọn*) : Thiết bị để đặt các tensor lên.

dtype (`torch.dtype`, *tùy chọn*) : Kiểu dữ liệu cho các tensor.

**Trả về:** `tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]`

Một tuple chứa:
- `prompt_embeds`: Các vector nhúng văn bản cho prompt tích cực
- `negative_prompt_embeds`: Các vector nhúng văn bản cho prompt tiêu cực (None nếu không sử dụng guidance)
- `prompt_attention_mask`: Mặt nạ chú ý (attention mask) cho prompt tích cực
- `negative_prompt_attention_mask`: Mặt nạ chú ý cho prompt âm (None nếu không sử dụng guidance)

Mã hóa prompt thành các trạng thái ẩn của text encoder.

## MotifVideoPipelineOutput[[diffusers.MotifVideoPipelineOutput]]

#### diffusers.MotifVideoPipelineOutput[[diffusers.MotifVideoPipelineOutput]]

```python
diffusers.MotifVideoPipelineOutput(frames: Tensor)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/motif_video/pipeline_output.py#L9)

**Tham số:**

frames (`torch.Tensor`, `np.ndarray`, hoặc List[List[PIL.Image.Image]]) : Danh sách các đầu ra video - Có thể là một danh sách lồng nhau có độ dài `batch_size,` trong đó mỗi danh sách con chứa các chuỗi hình ảnh PIL đã khử nhiễu có độ dài `num_frames.` Nó cũng có thể là một mảng NumPy hoặc tensor Torch có hình dạng `(batch_size, num_frames, channels, height, width)`.

Lớp đầu ra cho các pipeline Motif-Video.

