Update app.py
Browse files
app.py
CHANGED
@@ -243,10 +243,39 @@ if st.session_state.processando:
|
|
243 |
barra.progress(75)
|
244 |
status.markdown("📌 Inserindo tutorial (se houver)...")
|
245 |
|
246 |
-
lista_final_txt = os.path.join(tmpdir, "lista_final.txt")
|
247 |
-
lista_cortes_final = [video_processado]
|
248 |
-
|
249 |
if st.session_state.tutorial_path:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
tutorial_pad = os.path.join(tmpdir, "tutorial_pad.mp4")
|
251 |
subprocess.call([
|
252 |
"ffmpeg", "-y", "-i", st.session_state.tutorial_path,
|
@@ -256,20 +285,22 @@ if st.session_state.processando:
|
|
256 |
tutorial_pad
|
257 |
])
|
258 |
|
259 |
-
#
|
260 |
-
|
261 |
-
|
|
|
|
|
|
|
262 |
|
263 |
-
|
264 |
-
|
265 |
-
f
|
|
|
|
|
|
|
266 |
|
267 |
-
|
268 |
-
|
269 |
-
"ffmpeg", "-y", "-f", "concat", "-safe", "0", "-i", lista_final_txt,
|
270 |
-
"-c:v", "libx264", "-preset", "veryfast",
|
271 |
-
video_com_tutorial
|
272 |
-
])
|
273 |
|
274 |
barra.progress(80)
|
275 |
status.markdown("🚀 Aplicando velocidade final...")
|
@@ -341,7 +372,6 @@ if st.session_state.processando:
|
|
341 |
video_final_permanente = os.path.join(tempfile.gettempdir(), "video_final_final.mp4")
|
342 |
shutil.copy(video_final_meta, video_final_permanente)
|
343 |
st.session_state.video_final = video_final_permanente
|
344 |
-
|
345 |
# --- PLAYER DOS VÍDEOS E BOTÕES ---
|
346 |
|
347 |
if st.session_state.video_final:
|
@@ -408,4 +438,3 @@ if st.session_state.video_final:
|
|
408 |
if st.button("🔄 Gerar novamente com os mesmos ajustes"):
|
409 |
st.session_state.processando = True
|
410 |
st.session_state.video_final = None
|
411 |
-
|
|
|
243 |
barra.progress(75)
|
244 |
status.markdown("📌 Inserindo tutorial (se houver)...")
|
245 |
|
|
|
|
|
|
|
246 |
if st.session_state.tutorial_path:
|
247 |
+
# Pega duração do vídeo processado
|
248 |
+
duracao_cmd = [
|
249 |
+
"ffprobe", "-v", "error", "-show_entries",
|
250 |
+
"format=duration", "-of",
|
251 |
+
"default=noprint_wrappers=1:nokey=1", video_processado
|
252 |
+
]
|
253 |
+
resultado = subprocess.run(duracao_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
254 |
+
duracao_video = float(resultado.stdout.decode().strip())
|
255 |
+
|
256 |
+
# Escolhe posição aleatória depois de 3 segundos e antes do final - 1s
|
257 |
+
pos_tutorial = random.uniform(3, duracao_video - 1)
|
258 |
+
|
259 |
+
parte1 = os.path.join(tmpdir, "parte1.mp4")
|
260 |
+
parte2 = os.path.join(tmpdir, "parte2.mp4")
|
261 |
+
|
262 |
+
# Corta a parte 1
|
263 |
+
subprocess.call([
|
264 |
+
"ffmpeg", "-y", "-i", video_processado,
|
265 |
+
"-t", str(pos_tutorial),
|
266 |
+
"-c", "copy",
|
267 |
+
parte1
|
268 |
+
])
|
269 |
+
|
270 |
+
# Corta a parte 2
|
271 |
+
subprocess.call([
|
272 |
+
"ffmpeg", "-y", "-i", video_processado,
|
273 |
+
"-ss", str(pos_tutorial),
|
274 |
+
"-c", "copy",
|
275 |
+
parte2
|
276 |
+
])
|
277 |
+
|
278 |
+
# Prepara tutorial padronizado
|
279 |
tutorial_pad = os.path.join(tmpdir, "tutorial_pad.mp4")
|
280 |
subprocess.call([
|
281 |
"ffmpeg", "-y", "-i", st.session_state.tutorial_path,
|
|
|
285 |
tutorial_pad
|
286 |
])
|
287 |
|
288 |
+
# Criar lista para concatenação
|
289 |
+
lista_final_txt = os.path.join(tmpdir, "lista_final.txt")
|
290 |
+
with open(lista_final_txt, "w") as f:
|
291 |
+
f.write(f"file '{parte1}'\n")
|
292 |
+
f.write(f"file '{tutorial_pad}'\n")
|
293 |
+
f.write(f"file '{parte2}'\n")
|
294 |
|
295 |
+
video_com_tutorial = os.path.join(tmpdir, "video_com_tutorial.mp4")
|
296 |
+
subprocess.call([
|
297 |
+
"ffmpeg", "-y", "-f", "concat", "-safe", "0", "-i", lista_final_txt,
|
298 |
+
"-c:v", "libx264", "-preset", "veryfast",
|
299 |
+
video_com_tutorial
|
300 |
+
])
|
301 |
|
302 |
+
else:
|
303 |
+
video_com_tutorial = video_processado
|
|
|
|
|
|
|
|
|
304 |
|
305 |
barra.progress(80)
|
306 |
status.markdown("🚀 Aplicando velocidade final...")
|
|
|
372 |
video_final_permanente = os.path.join(tempfile.gettempdir(), "video_final_final.mp4")
|
373 |
shutil.copy(video_final_meta, video_final_permanente)
|
374 |
st.session_state.video_final = video_final_permanente
|
|
|
375 |
# --- PLAYER DOS VÍDEOS E BOTÕES ---
|
376 |
|
377 |
if st.session_state.video_final:
|
|
|
438 |
if st.button("🔄 Gerar novamente com os mesmos ajustes"):
|
439 |
st.session_state.processando = True
|
440 |
st.session_state.video_final = None
|
|