Spaces:
Paused
Paused
Update app_4k.py
Browse files
app_4k.py
CHANGED
|
@@ -21,37 +21,22 @@ import subprocess
|
|
| 21 |
import os
|
| 22 |
import uuid
|
| 23 |
|
| 24 |
-
|
| 25 |
-
output_name = f"ultrawan_{uuid.uuid4().hex[:8]}"
|
| 26 |
-
output_path = os.path.join(out_dir, output_name)
|
| 27 |
-
os.makedirs(out_dir, exist_ok=True)
|
| 28 |
|
|
|
|
|
|
|
| 29 |
cmd = [
|
| 30 |
-
"
|
| 31 |
-
"
|
| 32 |
-
"
|
| 33 |
-
"
|
| 34 |
-
"
|
| 35 |
-
"
|
| 36 |
-
"
|
| 37 |
-
|
| 38 |
-
"--num_frames", "33",
|
| 39 |
-
"--prompt", prompt,
|
| 40 |
-
"--seed", str(seed),
|
| 41 |
-
"--out_dir", output_path
|
| 42 |
]
|
|
|
|
| 43 |
|
| 44 |
-
env = os.environ.copy()
|
| 45 |
-
env["CUDA_VISIBLE_DEVICES"] = "0"
|
| 46 |
-
|
| 47 |
-
subprocess.run(cmd, env=env, check=True)
|
| 48 |
-
|
| 49 |
-
# Assume the output is a .mp4 inside output_path
|
| 50 |
-
generated_files = [f for f in os.listdir(output_path) if f.endswith(".mp4")]
|
| 51 |
-
if not generated_files:
|
| 52 |
-
raise FileNotFoundError("No output video found.")
|
| 53 |
-
|
| 54 |
-
return os.path.join(output_path, generated_files[0])
|
| 55 |
|
| 56 |
|
| 57 |
|
|
@@ -255,6 +240,8 @@ def generate_video(prompt, height, width,
|
|
| 255 |
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmpfile:
|
| 256 |
video_path = tmpfile.name
|
| 257 |
export_to_video(output_frames_list, video_path, fps=FIXED_OUTPUT_FPS)
|
|
|
|
|
|
|
| 258 |
|
| 259 |
return video_path, current_seed
|
| 260 |
|
|
|
|
| 21 |
import os
|
| 22 |
import uuid
|
| 23 |
|
| 24 |
+
import subprocess
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
def upscale_to_4k(input_video_path, output_video_path):
|
| 27 |
+
# Use Lanczos for better quality upscale
|
| 28 |
cmd = [
|
| 29 |
+
"ffmpeg",
|
| 30 |
+
"-i", input_video_path,
|
| 31 |
+
"-vf", "scale=3840:2160:flags=lanczos", # upscale to 4K (3840x2160)
|
| 32 |
+
"-c:v", "libx264", # or libx265 for smaller size
|
| 33 |
+
"-crf", "18", # quality: lower is better (range 0-51)
|
| 34 |
+
"-preset", "slow", # better compression
|
| 35 |
+
"-y", # overwrite output file
|
| 36 |
+
output_video_path,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
]
|
| 38 |
+
subprocess.run(cmd, check=True)
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
|
| 42 |
|
|
|
|
| 240 |
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmpfile:
|
| 241 |
video_path = tmpfile.name
|
| 242 |
export_to_video(output_frames_list, video_path, fps=FIXED_OUTPUT_FPS)
|
| 243 |
+
upscale_to_4k(video_path, os.path.join(temp_dir, "upscaled_4k.mp4"))
|
| 244 |
+
|
| 245 |
|
| 246 |
return video_path, current_seed
|
| 247 |
|