sofia-rivera-factory / modules /video_maker.py
GoGma's picture
Create modules/video_maker.py
ed231a2 verified
Raw
History Blame Contribute Delete
3.98 kB
"""
Módulo creador de videos reels/TikTok.
Usa MoviePy para edición básica (opcional).
"""
import tempfile
import os
def create_reel_from_images(image_paths, duration_per_image=2,
total_duration=None, music_track="chill"):
"""
Crea video reel a partir de imágenes.
Args:
image_paths: Lista de rutas a imágenes
duration_per_image: Segundos por imagen
total_duration: Duración total deseada (si None, usa todas)
music_track: Tipo de música ("chill", "energetic", "romantic")
Returns:
str: Ruta al archivo de video creado
"""
# ====== IMPLEMENTACIÓN PLACEHOLDER ======
# Aquí conectarías MoviePy o similar para crear video real
try:
print(f"Creando reel con {len(image_paths)} imágenes...")
# Crear archivo de video placeholder (texto en negro)
from PIL import Image, ImageDraw, ImageFont
# Dimensiones estándar TikTok/Reel (vertical 9:16)
width, height = 1080, 1920
# Crear imagen negra con texto
img = Image.new('RGB', (width, height), color=(0, 0, 0))
draw = ImageDraw.Draw(img)
# Texto informativo
text_lines = [
"🎬 VIDEO REEL SOFÍA RIVERA",
f"Imágenes: {len(image_paths)}",
f"Duración por imagen: {duration_per_image}s",
f"Música: {music_track}",
"",
"✨ Implementa MoviePy aquí ✨",
"",
"Para video real:",
"1. pip install moviepy",
"2. Conectar con tu modelo de IA"
]
# Intentar usar fuente más grande
try:
font = ImageFont.truetype("arial.ttf", 40)
except:
font = ImageFont.load_default()
# Dibujar líneas de texto
y_position = height // 4
for line in text_lines:
# Calcular ancho texto para centrar
if hasattr(font, 'getbbox'):
bbox = font.getbbox(line)
text_width = bbox[2] - bbox[0]
else:
text_width = len(line) * 20
x_position = (width - text_width) // 2
draw.text((x_position, y_position),
line,
fill=(255, 105, 180), # Rosa Sofía
font=font)
y_position += 60
# Guardar como video placeholder (en realidad es imagen)
temp_file = tempfile.NamedTemporaryFile(suffix='.mp4', delete=False)
# Convertir imagen a video (placeholder simple)
img.save(temp_file.name.replace('.mp4', '.jpg'))
# Renombrar extensión para que Gradio lo reconozca como video
os.rename(temp_file.name.replace('.mp4', '.jpg'), temp_file.name)
print(f"Video placeholder creado: {temp_file.name}")
return temp_file.name
except Exception as e:
print(f"Error creando video: {e}")
# Fallback: archivo vacío
temp_file = tempfile.NamedTemporaryFile(suffix='.mp4', delete=False)
with open(temp_file.name, 'wb') as f:
f.write(b"") # Archivo vacío
return temp_file.name
def add_music_to_video(video_path, music_track="chill"):
"""Añade música a video (placeholder)"""
return video_path # Implementar con MoviePy
def get_free_music_tracks():
"""Devuelve lista de pistas musicales gratuitas"""
return [
{"name": "Chill Vibes", "genre": "Lo-fi", "duration": 30},
{"name": "Energetic Pop", "genre": "Pop", "duration": 25},
{"name": "Romantic Piano", "genre": "Classical", "duration": 40},
{"name": "Summer Beats", "genre": "Electronic", "duration": 35}
]