Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -29,29 +29,38 @@ os.makedirs(output_folder, exist_ok=True)
|
|
29 |
# ID de la carpeta de destino en Google Drive
|
30 |
FOLDER_ID = "12S6adpanAXjf71pKKGRRPqpzbJa5XEh3" # Reemplaza con tu ID de carpeta
|
31 |
|
32 |
-
def resize_and_blur_video(clip,
|
33 |
-
"""Redimensiona
|
34 |
try:
|
35 |
w, h = clip.size
|
36 |
current_aspect_ratio = w / h
|
|
|
|
|
37 |
if abs(current_aspect_ratio - target_aspect_ratio) < 0.1:
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
if current_aspect_ratio < target_aspect_ratio: # Video vertical
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
background = background.fx(vfx.blur, sigma=50)
|
45 |
-
except Exception as e:
|
46 |
-
print(f"Error al aplicar blur: {e}")
|
47 |
-
foreground = clip.resize(height=target_h)
|
48 |
-
x_center = (target_w - foreground.w) / 2
|
49 |
-
return CompositeVideoClip(
|
50 |
-
[background, foreground.set_position((x_center, 0))],
|
51 |
-
size=(target_w, target_h)
|
52 |
-
)
|
53 |
else: # Video horizontal
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
except Exception as e:
|
56 |
print(f"Error en resize_and_blur_video: {e}")
|
57 |
return clip
|
|
|
29 |
# ID de la carpeta de destino en Google Drive
|
30 |
FOLDER_ID = "12S6adpanAXjf71pKKGRRPqpzbJa5XEh3" # Reemplaza con tu ID de carpeta
|
31 |
|
32 |
+
def resize_and_blur_video(clip, target_width=1920, target_height=1080):
|
33 |
+
"""Redimensiona el video al tama帽o 1080p (16:9) y aplica desenfoque si es necesario."""
|
34 |
try:
|
35 |
w, h = clip.size
|
36 |
current_aspect_ratio = w / h
|
37 |
+
target_aspect_ratio = target_width / target_height
|
38 |
+
|
39 |
if abs(current_aspect_ratio - target_aspect_ratio) < 0.1:
|
40 |
+
# Si la relaci贸n de aspecto ya es cercana a 16:9, solo redimensionamos
|
41 |
+
return clip.resize((target_width, target_height))
|
42 |
+
|
43 |
+
# Crear un fondo borroso con las dimensiones objetivo
|
44 |
+
background = ColorClip(size=(target_width, target_height), color=[0, 0, 0]).set_duration(clip.duration)
|
45 |
+
try:
|
46 |
+
background = background.fx(vfx.blur, sigma=50)
|
47 |
+
except Exception as e:
|
48 |
+
print(f"Error al aplicar blur: {e}")
|
49 |
+
|
50 |
+
# Redimensionar el video original para mantener su proporci贸n
|
51 |
if current_aspect_ratio < target_aspect_ratio: # Video vertical
|
52 |
+
new_height = target_height
|
53 |
+
new_width = int(new_height * current_aspect_ratio)
|
54 |
+
x_center = (target_width - new_width) / 2
|
55 |
+
resized_clip = clip.resize(width=new_width).set_position((x_center, 0))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
else: # Video horizontal
|
57 |
+
new_width = target_width
|
58 |
+
new_height = int(new_width / current_aspect_ratio)
|
59 |
+
y_center = (target_height - new_height) / 2
|
60 |
+
resized_clip = clip.resize(height=new_height).set_position((0, y_center))
|
61 |
+
|
62 |
+
# Combinar el fondo borroso con el video redimensionado
|
63 |
+
return CompositeVideoClip([background, resized_clip], size=(target_width, target_height))
|
64 |
except Exception as e:
|
65 |
print(f"Error en resize_and_blur_video: {e}")
|
66 |
return clip
|