File size: 4,248 Bytes
993fe8a
 
9afcbd8
2313c20
993fe8a
 
 
 
 
 
 
 
2313c20
 
 
 
 
 
 
 
 
 
 
2ffdcde
2313c20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c7a6699
 
2313c20
2ffdcde
2313c20
 
 
 
 
 
 
 
190328a
b240689
993fe8a
190328a
 
993fe8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4c9fdb
9afcbd8
993fe8a
9afcbd8
993fe8a
9afcbd8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
993fe8a
9afcbd8
 
993fe8a
9afcbd8
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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)