Spaces:
Running on Zero
Running on Zero
fix: resize generated video back to the exact input dimensions after AniDoc inference
Browse files- gradio_app.py +3 -5
gradio_app.py
CHANGED
|
@@ -206,20 +206,18 @@ def get_video_dimensions(video_path: str) -> tuple[int, int]:
|
|
| 206 |
return width, height
|
| 207 |
|
| 208 |
|
| 209 |
-
def
|
| 210 |
output_video_path: str,
|
| 211 |
input_video_path: str,
|
| 212 |
) -> str:
|
| 213 |
target_width, target_height = get_video_dimensions(input_video_path)
|
| 214 |
resized_output_path = os.path.splitext(output_video_path)[0] + "_resized.mp4"
|
| 215 |
|
| 216 |
-
vf = f"scale={target_width}:{target_height}:force_original_aspect_ratio=decrease"
|
| 217 |
-
|
| 218 |
cmd = [
|
| 219 |
"ffmpeg",
|
| 220 |
"-y",
|
| 221 |
"-i", output_video_path,
|
| 222 |
-
"-vf",
|
| 223 |
"-c:v", "libx264",
|
| 224 |
"-pix_fmt", "yuv420p",
|
| 225 |
resized_output_path,
|
|
@@ -481,7 +479,7 @@ def run_anidoc(
|
|
| 481 |
final_output_path = mp4_candidates[0]
|
| 482 |
|
| 483 |
if control_path.lower().endswith(".mp4"):
|
| 484 |
-
final_output_path =
|
| 485 |
final_output_path,
|
| 486 |
control_path,
|
| 487 |
)
|
|
|
|
| 206 |
return width, height
|
| 207 |
|
| 208 |
|
| 209 |
+
def resize_output_video_to_input_size(
|
| 210 |
output_video_path: str,
|
| 211 |
input_video_path: str,
|
| 212 |
) -> str:
|
| 213 |
target_width, target_height = get_video_dimensions(input_video_path)
|
| 214 |
resized_output_path = os.path.splitext(output_video_path)[0] + "_resized.mp4"
|
| 215 |
|
|
|
|
|
|
|
| 216 |
cmd = [
|
| 217 |
"ffmpeg",
|
| 218 |
"-y",
|
| 219 |
"-i", output_video_path,
|
| 220 |
+
"-vf", f"scale={target_width}:{target_height}",
|
| 221 |
"-c:v", "libx264",
|
| 222 |
"-pix_fmt", "yuv420p",
|
| 223 |
resized_output_path,
|
|
|
|
| 479 |
final_output_path = mp4_candidates[0]
|
| 480 |
|
| 481 |
if control_path.lower().endswith(".mp4"):
|
| 482 |
+
final_output_path = resize_output_video_to_input_size(
|
| 483 |
final_output_path,
|
| 484 |
control_path,
|
| 485 |
)
|