Update app.py
Browse files
app.py
CHANGED
@@ -262,3 +262,61 @@ if st.button("Gerar Vídeo(s)"):
|
|
262 |
f.write(f"file '{part1}'\nfile '{tutorial_mp4}'\nfile '{part2}'\n")
|
263 |
video_final_raw = os.path.join(temp_dir, f"video_final_raw_{n}.mp4")
|
264 |
subprocess.run(["ffmpeg", "-f", "concat", "-safe", "0", "-i", final_txt, "-c:v", "libx264", "-preset", "ultrafast", "-crf", str(crf_value), video_final_raw], check=True, stderr=subprocess.PIPE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
f.write(f"file '{part1}'\nfile '{tutorial_mp4}'\nfile '{part2}'\n")
|
263 |
video_final_raw = os.path.join(temp_dir, f"video_final_raw_{n}.mp4")
|
264 |
subprocess.run(["ffmpeg", "-f", "concat", "-safe", "0", "-i", final_txt, "-c:v", "libx264", "-preset", "ultrafast", "-crf", str(crf_value), video_final_raw], check=True, stderr=subprocess.PIPE)
|
265 |
+
# 🎵 Música final
|
266 |
+
dur_proc = subprocess.run([
|
267 |
+
"ffprobe", "-v", "error", "-show_entries", "format=duration",
|
268 |
+
"-of", "default=noprint_wrappers=1:nokey=1", video_final_raw
|
269 |
+
], stdout=subprocess.PIPE)
|
270 |
+
dur_video_real = float(dur_proc.stdout.decode().strip())
|
271 |
+
|
272 |
+
if musica:
|
273 |
+
musica_path = os.path.join(temp_dir, "musica_original.mp3")
|
274 |
+
with open(musica_path, "wb") as f:
|
275 |
+
f.write(musica.read())
|
276 |
+
musica_cortada = os.path.join(temp_dir, f"musica_cortada_{n}.aac")
|
277 |
+
subprocess.run([
|
278 |
+
"ffmpeg", "-i", musica_path, "-ss", "0", "-t", str(dur_video_real),
|
279 |
+
"-vn", "-acodec", "aac", "-y", musica_cortada
|
280 |
+
], check=True, stderr=subprocess.PIPE)
|
281 |
+
final_name = f"video_final_{n}_{int(time.time())}.mp4"
|
282 |
+
subprocess.run([
|
283 |
+
"ffmpeg", "-i", video_final_raw, "-i", musica_cortada,
|
284 |
+
"-map", "0:v:0", "-map", "1:a:0",
|
285 |
+
"-c:v", "copy", "-c:a", "aac",
|
286 |
+
"-shortest", final_name
|
287 |
+
], check=True, stderr=subprocess.PIPE)
|
288 |
+
else:
|
289 |
+
final_name = f"video_final_{n}_{int(time.time())}.mp4"
|
290 |
+
shutil.copy(video_final_raw, final_name)
|
291 |
+
|
292 |
+
# 🔒 APLICAR ANTI-FLOP NO FINAL
|
293 |
+
if ativar_antiflop:
|
294 |
+
antiflop_out = f"antiflop_{n}_{int(time.time())}.mp4"
|
295 |
+
vf_af = (
|
296 |
+
f"scale=iw*{zoom_af}:ih*{zoom_af},"
|
297 |
+
f"crop=iw/{zoom_af}:ih/{zoom_af},"
|
298 |
+
f"eq=brightness={brilho_af}:contrast={contraste_af}:saturation={saturacao_af},"
|
299 |
+
f"noise=alls={ruido_af}:allf=t,"
|
300 |
+
f"rotate={rotacao_af}*PI/180:[email protected]"
|
301 |
+
)
|
302 |
+
subprocess.run([
|
303 |
+
"ffmpeg", "-i", final_name, "-vf", vf_af,
|
304 |
+
"-c:v", "libx264", "-preset", "fast", "-crf", str(crf_value),
|
305 |
+
antiflop_out
|
306 |
+
], check=True)
|
307 |
+
st.video(antiflop_out)
|
308 |
+
with open(antiflop_out, "rb") as f:
|
309 |
+
st.download_button(f"📥 Baixar vídeo {n+1} Anti-Flop", f, file_name=antiflop_out)
|
310 |
+
else:
|
311 |
+
st.video(final_name)
|
312 |
+
with open(final_name, "rb") as f:
|
313 |
+
st.download_button(f"📥 Baixar vídeo {n+1}", f, file_name=final_name)
|
314 |
+
|
315 |
+
progresso.progress(100)
|
316 |
+
st.success("✅ Todos os vídeos foram gerados com sucesso!")
|
317 |
+
|
318 |
+
except subprocess.CalledProcessError as e:
|
319 |
+
st.error(f"❌ Erro ao gerar vídeo:\n\n{e.stderr.decode(errors='ignore')}")
|
320 |
+
|
321 |
+
finally:
|
322 |
+
shutil.rmtree(temp_dir)
|