Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,11 +5,9 @@ def convert_video(input_video):
|
|
| 5 |
output_path = "output_9x16.mp4"
|
| 6 |
clip = VideoFileClip(input_video)
|
| 7 |
|
| 8 |
-
# Safety check: reject videos longer than 2 minutes
|
| 9 |
if clip.duration > 120:
|
| 10 |
return "⚠️ Video too long! Please upload a clip shorter than 2 minutes."
|
| 11 |
|
| 12 |
-
# Crop center to 9:16 ratio
|
| 13 |
target_width = int(clip.h * 9 / 16)
|
| 14 |
x_center = clip.w // 2
|
| 15 |
x1 = x_center - target_width // 2
|
|
@@ -18,7 +16,6 @@ def convert_video(input_video):
|
|
| 18 |
clip_resized = clip.crop(x1=x1, x2=x2, y1=0, y2=clip.h)
|
| 19 |
clip_resized = clip_resized.resize(height=1920, width=1080)
|
| 20 |
|
| 21 |
-
# Write output video
|
| 22 |
clip_resized.write_videofile(output_path, codec="libx264", audio_codec="aac")
|
| 23 |
return output_path
|
| 24 |
|
|
|
|
| 5 |
output_path = "output_9x16.mp4"
|
| 6 |
clip = VideoFileClip(input_video)
|
| 7 |
|
|
|
|
| 8 |
if clip.duration > 120:
|
| 9 |
return "⚠️ Video too long! Please upload a clip shorter than 2 minutes."
|
| 10 |
|
|
|
|
| 11 |
target_width = int(clip.h * 9 / 16)
|
| 12 |
x_center = clip.w // 2
|
| 13 |
x1 = x_center - target_width // 2
|
|
|
|
| 16 |
clip_resized = clip.crop(x1=x1, x2=x2, y1=0, y2=clip.h)
|
| 17 |
clip_resized = clip_resized.resize(height=1920, width=1080)
|
| 18 |
|
|
|
|
| 19 |
clip_resized.write_videofile(output_path, codec="libx264", audio_codec="aac")
|
| 20 |
return output_path
|
| 21 |
|