Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -121,15 +121,20 @@ async def procesar_fragmento(chunk, texto_tts, voz_seleccionada, start_time):
|
|
121 |
current_time = 0
|
122 |
while current_time < duracion_chunk:
|
123 |
end_time = current_time + segment_duration
|
124 |
-
|
125 |
-
break # Terminar si ya no hay suficiente tiempo
|
126 |
|
127 |
full_segment = chunk.subclip(current_time, end_time)
|
128 |
segments.append(full_segment)
|
129 |
current_time += (segment_duration - overlap)
|
130 |
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
return video_chunk, tts_temp_files + [bg_temp_file]
|
134 |
|
135 |
except Exception as e:
|
@@ -138,6 +143,7 @@ async def procesar_fragmento(chunk, texto_tts, voz_seleccionada, start_time):
|
|
138 |
|
139 |
async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
140 |
temp_files = []
|
|
|
141 |
try:
|
142 |
logging.info("Iniciando procesamiento de video")
|
143 |
video_original = VideoFileClip(video_input, target_resolution=(720, 1280))
|
@@ -192,9 +198,12 @@ async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
|
192 |
raise
|
193 |
finally:
|
194 |
try:
|
195 |
-
video_original
|
196 |
-
|
197 |
-
|
|
|
|
|
|
|
198 |
for file in temp_files:
|
199 |
try:
|
200 |
os.remove(file)
|
|
|
121 |
current_time = 0
|
122 |
while current_time < duracion_chunk:
|
123 |
end_time = current_time + segment_duration
|
124 |
+
end_time = min(end_time, duracion_chunk)
|
|
|
125 |
|
126 |
full_segment = chunk.subclip(current_time, end_time)
|
127 |
segments.append(full_segment)
|
128 |
current_time += (segment_duration - overlap)
|
129 |
|
130 |
+
# Asegurar que haya al menos un segmento
|
131 |
+
if not segments:
|
132 |
+
logging.warning("Chunk demasiado corto, devolviendo el chunk original.")
|
133 |
+
video_chunk = chunk.set_audio(audio_final)
|
134 |
+
else:
|
135 |
+
video_chunk = concatenate_videoclips(segments, method="compose")
|
136 |
+
video_chunk = video_chunk.set_audio(audio_final)
|
137 |
+
|
138 |
return video_chunk, tts_temp_files + [bg_temp_file]
|
139 |
|
140 |
except Exception as e:
|
|
|
143 |
|
144 |
async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
145 |
temp_files = []
|
146 |
+
intro, outro = None, None # Inicializar variables para evitar errores
|
147 |
try:
|
148 |
logging.info("Iniciando procesamiento de video")
|
149 |
video_original = VideoFileClip(video_input, target_resolution=(720, 1280))
|
|
|
198 |
raise
|
199 |
finally:
|
200 |
try:
|
201 |
+
if video_original:
|
202 |
+
video_original.close()
|
203 |
+
if intro:
|
204 |
+
intro.close()
|
205 |
+
if outro:
|
206 |
+
outro.close()
|
207 |
for file in temp_files:
|
208 |
try:
|
209 |
os.remove(file)
|