Update app.py
Browse files
app.py
CHANGED
|
@@ -139,26 +139,40 @@ if pagina == "🎬 Gerador de Vídeo":
|
|
| 139 |
ativar_blur_fundo_n = ativar_blur_fundo
|
| 140 |
ativar_espelhar_n = ativar_espelhar
|
| 141 |
|
| 142 |
-
# Etapa 1 - Fundo
|
| 143 |
if usar_fundo:
|
| 144 |
fundo_origem = random.choice(cortes_names)
|
| 145 |
fundo_convertido = os.path.join(temp_dir, f"fundo_convertido_{n}.mp4")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
subprocess.run([
|
| 147 |
-
"ffmpeg", "-ss",
|
| 148 |
"-t", str(duracao_final),
|
| 149 |
-
"-vf",
|
| 150 |
-
"-
|
|
|
|
|
|
|
| 151 |
fundo_convertido
|
| 152 |
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 153 |
else:
|
| 154 |
fundo_convertido = os.path.join(temp_dir, f"fundo_vazio_{n}.mp4")
|
| 155 |
subprocess.run([
|
| 156 |
"ffmpeg", "-f", "lavfi", "-i", f"color=color=black:size=720x1280:d={duracao_final}:rate=30",
|
| 157 |
-
"-c:v", "libx264", "-preset", "veryfast", "-crf", "18",
|
| 158 |
fundo_convertido
|
| 159 |
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
|
|
|
|
|
| 160 |
|
| 161 |
-
# Etapa 2 - Cortes
|
| 162 |
tentativas = 0
|
| 163 |
while tempo_total < duracao_final and tentativas < 100:
|
| 164 |
tentativas += 1
|
|
@@ -204,6 +218,9 @@ if pagina == "🎬 Gerador de Vídeo":
|
|
| 204 |
"-c:v", "libx264", "-preset", "veryfast", "-crf", "18", video_raw
|
| 205 |
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 206 |
|
|
|
|
|
|
|
|
|
|
| 207 |
# Etapa 3 - Filtros e Efeitos
|
| 208 |
filtros_main = ["scale=720:1280:force_original_aspect_ratio=decrease"]
|
| 209 |
if zoom_n != 1.0:
|
|
@@ -272,6 +289,8 @@ if pagina == "🎬 Gerador de Vídeo":
|
|
| 272 |
video_editado
|
| 273 |
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 274 |
|
|
|
|
|
|
|
| 275 |
# Etapa 4 - Tutorial
|
| 276 |
if usar_tutorial and tutorials_salvos:
|
| 277 |
tutorial_path = random.choice(tutorials_salvos)
|
|
@@ -309,6 +328,8 @@ if pagina == "🎬 Gerador de Vídeo":
|
|
| 309 |
video_final_raw], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 310 |
else:
|
| 311 |
video_final_raw = video_editado
|
|
|
|
|
|
|
| 312 |
|
| 313 |
# Etapa 5 - Velocidade final
|
| 314 |
video_com_velocidade = os.path.join(temp_dir, f"video_com_velocidade_{n}.mp4")
|
|
@@ -355,7 +376,6 @@ if pagina == "🎬 Gerador de Vídeo":
|
|
| 355 |
st.error(f"❌ Erro inesperado: {str(e)}")
|
| 356 |
finally:
|
| 357 |
shutil.rmtree(temp_dir)
|
| 358 |
-
|
| 359 |
# ======================== GERENCIADOR ========================
|
| 360 |
elif pagina == "📂 Gerenciador de Arquivos":
|
| 361 |
st.header("📂 Vídeos Salvos por Categoria")
|
|
@@ -441,16 +461,6 @@ elif pagina == "🔐 Admin":
|
|
| 441 |
out.write(f.read())
|
| 442 |
|
| 443 |
final = os.path.join(path, nome_aleatorio)
|
| 444 |
-
shutil.move(temp, final)
|
| 445 |
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
st.write("Arquivos existentes:")
|
| 449 |
-
for arq in os.listdir(path):
|
| 450 |
-
col1, col2 = st.columns([5, 1])
|
| 451 |
-
with col1:
|
| 452 |
-
st.markdown(f"`{arq}`")
|
| 453 |
-
with col2:
|
| 454 |
-
if st.button("🗑", key=f"{tipo}_{cat}_{arq}"):
|
| 455 |
-
os.remove(os.path.join(path, arq))
|
| 456 |
-
st.rerun()
|
|
|
|
| 139 |
ativar_blur_fundo_n = ativar_blur_fundo
|
| 140 |
ativar_espelhar_n = ativar_espelhar
|
| 141 |
|
| 142 |
+
# Etapa 1 - Fundo com ponto aleatório
|
| 143 |
if usar_fundo:
|
| 144 |
fundo_origem = random.choice(cortes_names)
|
| 145 |
fundo_convertido = os.path.join(temp_dir, f"fundo_convertido_{n}.mp4")
|
| 146 |
+
dur_proc = subprocess.run([
|
| 147 |
+
"ffprobe", "-v", "error", "-show_entries", "format=duration",
|
| 148 |
+
"-of", "default=noprint_wrappers=1:nokey=1", fundo_origem
|
| 149 |
+
], stdout=subprocess.PIPE)
|
| 150 |
+
try:
|
| 151 |
+
dur_total = float(dur_proc.stdout.decode().strip())
|
| 152 |
+
ponto_inicio = random.uniform(0, max(0, dur_total - duracao_final))
|
| 153 |
+
except:
|
| 154 |
+
ponto_inicio = 0.0
|
| 155 |
+
|
| 156 |
subprocess.run([
|
| 157 |
+
"ffmpeg", "-ss", str(ponto_inicio), "-i", fundo_origem,
|
| 158 |
"-t", str(duracao_final),
|
| 159 |
+
"-vf",
|
| 160 |
+
"scale='if(gt(iw/ih,720/1280),max(720,iw),-2)':'if(gt(iw/ih,720/1280),-2,max(1280,ih))',"
|
| 161 |
+
"scale=720:1280:force_original_aspect_ratio=increase,crop=720:1280,fps=30",
|
| 162 |
+
"-preset", "veryfast", "-crf", "18",
|
| 163 |
fundo_convertido
|
| 164 |
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 165 |
else:
|
| 166 |
fundo_convertido = os.path.join(temp_dir, f"fundo_vazio_{n}.mp4")
|
| 167 |
subprocess.run([
|
| 168 |
"ffmpeg", "-f", "lavfi", "-i", f"color=color=black:size=720x1280:d={duracao_final}:rate=30",
|
| 169 |
+
"-c:v", "libx264", "-t", str(duracao_final), "-preset", "veryfast", "-crf", "18",
|
| 170 |
fundo_convertido
|
| 171 |
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 172 |
+
etapa_atual += 1
|
| 173 |
+
atualizar_barra(n, etapa_atual, num_videos_finais, total_etapas)
|
| 174 |
|
| 175 |
+
# Etapa 2 - Cortes (início)
|
| 176 |
tentativas = 0
|
| 177 |
while tempo_total < duracao_final and tentativas < 100:
|
| 178 |
tentativas += 1
|
|
|
|
| 218 |
"-c:v", "libx264", "-preset", "veryfast", "-crf", "18", video_raw
|
| 219 |
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 220 |
|
| 221 |
+
etapa_atual += 1
|
| 222 |
+
atualizar_barra(n, etapa_atual, num_videos_finais, total_etapas)
|
| 223 |
+
|
| 224 |
# Etapa 3 - Filtros e Efeitos
|
| 225 |
filtros_main = ["scale=720:1280:force_original_aspect_ratio=decrease"]
|
| 226 |
if zoom_n != 1.0:
|
|
|
|
| 289 |
video_editado
|
| 290 |
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 291 |
|
| 292 |
+
etapa_atual += 1
|
| 293 |
+
atualizar_barra(n, etapa_atual, num_videos_finais, total_etapas)
|
| 294 |
# Etapa 4 - Tutorial
|
| 295 |
if usar_tutorial and tutorials_salvos:
|
| 296 |
tutorial_path = random.choice(tutorials_salvos)
|
|
|
|
| 328 |
video_final_raw], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 329 |
else:
|
| 330 |
video_final_raw = video_editado
|
| 331 |
+
etapa_atual += 1
|
| 332 |
+
atualizar_barra(n, etapa_atual, num_videos_finais, total_etapas)
|
| 333 |
|
| 334 |
# Etapa 5 - Velocidade final
|
| 335 |
video_com_velocidade = os.path.join(temp_dir, f"video_com_velocidade_{n}.mp4")
|
|
|
|
| 376 |
st.error(f"❌ Erro inesperado: {str(e)}")
|
| 377 |
finally:
|
| 378 |
shutil.rmtree(temp_dir)
|
|
|
|
| 379 |
# ======================== GERENCIADOR ========================
|
| 380 |
elif pagina == "📂 Gerenciador de Arquivos":
|
| 381 |
st.header("📂 Vídeos Salvos por Categoria")
|
|
|
|
| 461 |
out.write(f.read())
|
| 462 |
|
| 463 |
final = os.path.join(path, nome_aleatorio)
|
|
|
|
| 464 |
|
| 465 |
+
# 🚀 Não reencoda mais, só salva
|
| 466 |
+
shutil.move(temp, final)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|