pcdoido2 commited on
Commit
69d05a9
·
verified ·
1 Parent(s): d05904f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -17
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
- # Inserir em uma posição aleatória
260
- pos = random.randint(0, len(lista_cortes_final))
261
- lista_cortes_final.insert(pos, tutorial_pad)
 
 
 
262
 
263
- with open(lista_final_txt, "w") as f:
264
- for arquivo in lista_cortes_final:
265
- f.write(f"file '{arquivo}'\n")
 
 
 
266
 
267
- video_com_tutorial = os.path.join(tmpdir, "video_com_tutorial.mp4")
268
- subprocess.call([
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