-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideo_generation.py
More file actions
160 lines (136 loc) · 3.82 KB
/
video_generation.py
File metadata and controls
160 lines (136 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
"""Video generation examples.
Demonstrates text-to-video, image-to-video, audio-to-video, video replace,
upscale, and background removal.
Usage:
export DEAPI_API_KEY="sk-your-api-key"
python examples/video_generation.py
"""
from deapi import DeapiClient
client = DeapiClient()
# --- Text-to-video ---
print("Generating video from text...")
job = client.video.generate(
prompt="a rocket launching into space, cinematic, slow motion",
negative_prompt="blurry, low quality",
model="Ltx2_19B_Dist_FP8",
width=768,
height=512,
steps=1,
seed=42,
frames=120,
fps=24,
)
print(f"Job submitted: {job.request_id}")
result = job.wait()
print(f"Status: {result.status}")
print(f"Video URL: {result.result_url}")
# --- Image-to-video (animate a still image) ---
# Uncomment to run — requires an image file:
#
# print("\nAnimating image...")
# job = client.video.animate(
# prompt="gentle camera pan across the landscape with clouds moving",
# first_frame_image="landscape.jpg",
# model="Ltx2_19B_Dist_FP8",
# seed=42,
# width=768,
# height=512,
# frames=120,
# fps=24,
# )
# result = job.wait()
# print(f"Animated video: {result.result_url}")
# --- With first and last frame (for controlled transitions) ---
# Uncomment to run — requires two image files:
#
# job = client.video.animate(
# prompt="smooth transition from day to night",
# first_frame_image="daytime.jpg",
# last_frame_image="nighttime.jpg",
# model="Ltx2_19B_Dist_FP8",
# seed=42,
# width=768,
# height=512,
# frames=120,
# fps=24,
# )
# --- Audio-to-video ---
# Uncomment to run — requires an audio file:
#
# print("\nGenerating video from audio...")
# job = client.video.generate_from_audio(
# prompt="abstract shapes pulsing to the beat",
# audio="track.mp3",
# model="ltx-audio2video",
# width=512,
# height=512,
# seed=42,
# frames=97,
# fps=24,
# )
# result = job.wait()
# print(f"Audio-to-video: {result.result_url}")
# With optional first/last frame images for more control:
#
# job = client.video.generate_from_audio(
# prompt="music visualization",
# audio="track.mp3",
# first_frame_image="start_frame.png",
# last_frame_image="end_frame.png",
# model="ltx-audio2video",
# width=512,
# height=512,
# seed=42,
# frames=97,
# fps=24,
# guidance=7.5,
# steps=20,
# )
# --- Video replace (swap character) ---
# Uncomment to run — requires a video and a reference image:
#
# print("\nReplacing character in video...")
# job = client.video.replace(
# video="input.mp4",
# ref_image="reference_face.png",
# model="vid-replace-model",
# prompt="replace the character",
# )
# result = job.wait()
# print(f"Video replace: {result.result_url}")
# Price calculation for video replace:
#
# price = client.video.replace_price(
# model="vid-replace-model",
# duration=10.5, # or pass video=b"..." to auto-detect duration
# width=512,
# height=512,
# )
# print(f"Replace price: ${price.price}")
# --- Video upscale ---
# Uncomment to run — requires a video file:
#
# print("\nUpscaling video...")
# job = client.video.upscale(video="low_res.mp4", model="vid-upscale-model")
# result = job.wait()
# print(f"Upscaled: {result.result_url}")
# --- Video background removal ---
# Uncomment to run — requires a video file:
#
# print("\nRemoving video background...")
# job = client.video.remove_background(video="greenscreen.mp4", model="vid-rmbg-model")
# result = job.wait()
# print(f"Background removed: {result.result_url}")
# --- Price calculation ---
price = client.video.generate_price(
prompt="a rocket launching",
model="Ltx2_19B_Dist_FP8",
width=768,
height=512,
steps=1,
seed=42,
frames=120,
fps=24,
)
print(f"\nVideo generation price: ${price.price}")
client.close()