Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,7 +25,7 @@ for file in [INTRO_VIDEO, OUTRO_VIDEO, MUSIC_BG, EJEMPLO_VIDEO]:
|
|
| 25 |
# Configuraci贸n de chunks
|
| 26 |
CHUNK_SIZE = 60 # 1 minuto por chunk
|
| 27 |
SEGMENT_DURATION = 18 # Duraci贸n de cada segmento
|
| 28 |
-
|
| 29 |
|
| 30 |
def eliminar_archivo_tiempo(ruta, delay=1800):
|
| 31 |
def eliminar():
|
|
@@ -66,6 +66,17 @@ def crear_musica_fondo(duracion_total):
|
|
| 66 |
bg_music.export(tmp_bg.name, format="mp3")
|
| 67 |
return AudioFileClip(tmp_bg.name).volumex(0.15), tmp_bg.name
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
| 70 |
temp_files = []
|
| 71 |
intro, outro, video_original = None, None, None
|
|
@@ -87,28 +98,38 @@ async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
|
| 87 |
audios.append(tts_audio.set_start(0).volumex(0.85))
|
| 88 |
audio_final = CompositeAudioClip(audios).set_duration(duracion_video)
|
| 89 |
|
| 90 |
-
# Dividir video en segmentos
|
| 91 |
segments = []
|
| 92 |
current_time = 0
|
| 93 |
while current_time < duracion_video:
|
| 94 |
end_time = current_time + SEGMENT_DURATION
|
| 95 |
if end_time > duracion_video:
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
if segments and full_segment.duration >= OVERLAP:
|
| 101 |
-
full_segment = full_segment.subclip(0, full_segment.duration - OVERLAP)
|
| 102 |
-
|
| 103 |
-
segments.append(full_segment)
|
| 104 |
-
current_time += (SEGMENT_DURATION - OVERLAP)
|
| 105 |
|
| 106 |
# Asegurar que haya al menos un segmento
|
| 107 |
if not segments:
|
| 108 |
logging.warning("Video demasiado corto, devolviendo el video original.")
|
| 109 |
video_final = video_original.set_audio(audio_final)
|
| 110 |
else:
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
video_final = video_final.set_audio(audio_final)
|
| 113 |
|
| 114 |
# Agregar intro y outro
|
|
|
|
| 25 |
# Configuraci贸n de chunks
|
| 26 |
CHUNK_SIZE = 60 # 1 minuto por chunk
|
| 27 |
SEGMENT_DURATION = 18 # Duraci贸n de cada segmento
|
| 28 |
+
TRANSITION_DURATION = 1 # Duraci贸n de la transici贸n en segundos
|
| 29 |
|
| 30 |
def eliminar_archivo_tiempo(ruta, delay=1800):
|
| 31 |
def eliminar():
|
|
|
|
| 66 |
bg_music.export(tmp_bg.name, format="mp3")
|
| 67 |
return AudioFileClip(tmp_bg.name).volumex(0.15), tmp_bg.name
|
| 68 |
|
| 69 |
+
def create_slide_transition(clip1, clip2, duration=1):
|
| 70 |
+
"""Crea transici贸n slide entre dos clips"""
|
| 71 |
+
transition = CompositeVideoClip([
|
| 72 |
+
clip1.fx(vfx.fadeout, duration).set_end(clip1.duration),
|
| 73 |
+
clip2.fx(vfx.fadein, duration)
|
| 74 |
+
.set_start(clip1.duration - duration)
|
| 75 |
+
.set_position(lambda t: ('center', -clip2.h + (clip2.h*2)*(t/duration)))
|
| 76 |
+
], size=(1280, 720))
|
| 77 |
+
|
| 78 |
+
return transition.set_duration(clip1.duration + duration)
|
| 79 |
+
|
| 80 |
async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
| 81 |
temp_files = []
|
| 82 |
intro, outro, video_original = None, None, None
|
|
|
|
| 98 |
audios.append(tts_audio.set_start(0).volumex(0.85))
|
| 99 |
audio_final = CompositeAudioClip(audios).set_duration(duracion_video)
|
| 100 |
|
| 101 |
+
# Dividir video en segmentos SIN solapamiento
|
| 102 |
segments = []
|
| 103 |
current_time = 0
|
| 104 |
while current_time < duracion_video:
|
| 105 |
end_time = current_time + SEGMENT_DURATION
|
| 106 |
if end_time > duracion_video:
|
| 107 |
+
end_time = duracion_video
|
| 108 |
+
segment = video_original.subclip(current_time, end_time)
|
| 109 |
+
segments.append(segment)
|
| 110 |
+
current_time = end_time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
# Asegurar que haya al menos un segmento
|
| 113 |
if not segments:
|
| 114 |
logging.warning("Video demasiado corto, devolviendo el video original.")
|
| 115 |
video_final = video_original.set_audio(audio_final)
|
| 116 |
else:
|
| 117 |
+
# Aplicar transiciones slide entre segmentos
|
| 118 |
+
clips = []
|
| 119 |
+
for i in range(len(segments)):
|
| 120 |
+
if i == 0:
|
| 121 |
+
clips.append(segments[i])
|
| 122 |
+
else:
|
| 123 |
+
transition = create_slide_transition(
|
| 124 |
+
clips[-1],
|
| 125 |
+
segments[i],
|
| 126 |
+
duration=TRANSITION_DURATION
|
| 127 |
+
)
|
| 128 |
+
clips.pop()
|
| 129 |
+
clips.append(transition)
|
| 130 |
+
clips.append(segments[i])
|
| 131 |
+
|
| 132 |
+
video_final = concatenate_videoclips(clips, method="compose")
|
| 133 |
video_final = video_final.set_audio(audio_final)
|
| 134 |
|
| 135 |
# Agregar intro y outro
|