|
48 | 48 | Examples: |
49 | 49 | ```py |
50 | 50 | >>> import torch |
51 | | - >>> from diffusers import LTX2ImageToVideoPipeline |
52 | | - >>> from diffusers.utils import export_to_video, load_image |
| 51 | + >>> from diffusers import LTX2Pipeline |
| 52 | + >>> from diffusers.pipelines.ltx2.export_utils import encode_video |
| 53 | + >>> from diffusers.utils import load_image |
53 | 54 |
|
54 | | - >>> pipe = LTX2ImageToVideoPipeline.from_pretrained("Lightricks/LTX-Video-2", torch_dtype=torch.bfloat16) |
55 | | - >>> pipe.to("cuda") |
| 55 | + >>> pipe = LTX2ImageToVideoPipeline.from_pretrained("Lightricks/LTX-2", torch_dtype=torch.bfloat16) |
| 56 | + >>> pipe.enable_model_cpu_offload() |
56 | 57 |
|
57 | 58 | >>> image = load_image( |
58 | 59 | ... "https://huggingface.co/datasets/a-r-r-o-w/tiny-meme-dataset-captioned/resolve/main/images/8.png" |
59 | 60 | ... ) |
60 | 61 | >>> prompt = "A young girl stands calmly in the foreground, looking directly at the camera, as a house fire rages in the background." |
61 | 62 | >>> negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted" |
62 | 63 |
|
| 64 | + >>> frame_rate = 24.0 |
63 | 65 | >>> video = pipe( |
64 | 66 | ... image=image, |
65 | 67 | ... prompt=prompt, |
66 | 68 | ... negative_prompt=negative_prompt, |
67 | | - ... width=704, |
68 | | - ... height=480, |
| 69 | + ... width=768, |
| 70 | + ... height=512, |
69 | 71 | ... num_frames=121, |
70 | | - ... num_inference_steps=40, |
71 | | - ... ).frames[0] |
72 | | - >>> export_to_video(video, "output.mp4", fps=24) |
| 72 | + ... frame_rate=frame_rate, |
| 73 | + ... output_type="np", |
| 74 | + ... return_dict=False, |
| 75 | + ... ) |
| 76 | + >>> video = (video * 255).round().astype("uint8") |
| 77 | + >>> video = torch.from_numpy(video) |
| 78 | +
|
| 79 | + >>> encode_video( |
| 80 | + ... video[0], |
| 81 | + ... fps=frame_rate, |
| 82 | + ... audio=audio[0].float().cpu(), |
| 83 | + ... audio_sample_rate=pipe.vocoder.config.output_sampling_rate, # should be 24000 |
| 84 | + ... output_path="video.mp4", |
| 85 | + ... ) |
73 | 86 | ``` |
74 | 87 | """ |
75 | 88 |
|
|
0 commit comments