import time import subprocess import random from ffmpy import FFmpeg async def motion(imagen): current_timestamp_int = int(time.time()) print("Ésto es current time stamp: ", current_timestamp_int) print("Esto es imagen en monomotion: ", imagen) video_filters = ( f"scale=1280:720:force_original_aspect_ratio=increase," f"crop=1280:720," f"zoompan=z='zoom+0.0005':d=1500" ) inputs = { imagen: ['-loop', '1'] # -loop 1 es una opción para la entrada } outputs = { f'{current_timestamp_int}.mp4': [ '-t', str(3), # Duración del video '-vf', video_filters, # Tus filtros de video complejos '-r', str(25), # Velocidad de fotogramas '-pix_fmt', 'yuv420p', # Formato de píxeles '-c:v', 'libx264', # Códec de video '-preset', 'fast', # Preset de codificación '-movflags', '+faststart', # Optimización MOOV atom '-y' # Sobrescribir sin preguntar ] } # Instancia FFmpeg ff = FFmpeg(inputs=inputs, outputs=outputs) # Imprime el comando que ffmpy va a ejecutar (para depuración) print("Comando ffmpy generado:") print(ff.cmd) # Ejecuta el comando try: ff.run() print(f"Video creado exitosamente: resultados/{current_timestamp_int}.mp4") except Exception as e: print(f"Error al crear el video: {e}") # ffmpy captura la salida estándar y de error, puedes acceder a ellas si necesitas depurar más a fondo: print(f"Salida de FFmpeg:\n{e.args[0]}") print(f"Error de FFmpeg:\n{e.args[1]}") return f'{current_timestamp_int}.mp4' async def motion_old(imagen): current_timestamp_int = int(time.time()) print("Ésto es current time stamp: ", current_timestamp_int) print("Esto es imagen en monomotion: ", imagen) #ffmpeg_path = "/usr/bin/ffmpeg" ffmpeg_command = [ 'ffmpeg', '-y', #f'{ffmpeg_path}', '-y', '-loop', '1', '-i', f'{imagen}', '-t', str(3), '-vf', f"scale=1280:720:force_original_aspect_ratio=increase," f"crop=1280:720," f"zoompan=z='zoom+0.0005':d=1500", #al zoom actual le vas a aumentar '-r', str(25), '-pix_fmt', 'yuv420p', '-c:v', 'libx264', '-preset', 'fast', '-movflags', '+faststart', # Agregar esta línea f'resultados/{current_timestamp_int}.mp4' ] print("Comando:") print(ffmpeg_command) subprocess.run(ffmpeg_command, check=True) return f'resultados/{current_timestamp_int}.mp4' async def cinema(lista): #lista = herramientas.lista_archivos('media') # print("Ésto es lista:", lista) # for elemento in lista: # ffmpeg_command = [ # 'ffmpeg', '-y', # '-loop', '1', # '-i', # f'media/{elemento}', # '-t', str(3), # '-vf', # f"scale=1280:720:force_original_aspect_ratio=increase," # f"crop=1280:720," # f"zoompan=z='zoom+0.0005':d=1500", #al zoom actual le vas a aumentar # '-r', str(25), # '-pix_fmt', 'yuv420p', # '-c:v', 'libx264', # '-preset', 'fast', # '-movflags', '+faststart', # Agregar esta línea # f'resultados1/{elemento}.mp4' # ] # print("Comando:") # print(ffmpeg_command) # subprocess.run(ffmpeg_command, check=True) return random.choice(lista)