Update app.py
Browse files
app.py
CHANGED
@@ -125,10 +125,10 @@ if st.session_state.processando:
|
|
125 |
status.markdown("🔎 Analisando duração e resolução do vídeo...")
|
126 |
barra.progress(5)
|
127 |
|
|
|
128 |
duracao_cmd = [
|
129 |
"ffprobe", "-v", "error", "-show_entries",
|
130 |
-
"format=duration", "-of",
|
131 |
-
"default=noprint_wrappers=1:nokey=1", video_path
|
132 |
]
|
133 |
resultado = subprocess.run(duracao_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
134 |
dur = float(resultado.stdout.decode().strip())
|
@@ -148,29 +148,66 @@ if st.session_state.processando:
|
|
148 |
excluir_fim = st.session_state.excluir_fim
|
149 |
velocidade_cortes = st.session_state.velocidade_cortes
|
150 |
|
151 |
-
|
152 |
-
|
153 |
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
corte_min = st.session_state.corte_min
|
159 |
-
corte_max = st.session_state.corte_max
|
160 |
|
161 |
-
partes = []
|
162 |
if excluir_inicio > 0:
|
163 |
-
|
|
|
|
|
|
|
|
|
|
|
164 |
if excluir_fim < dur:
|
165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
if tam_possivel < corte_min:
|
172 |
break
|
173 |
-
tamanho = random.randint(corte_min, tam_possivel)
|
174 |
fim_corte = pos + tamanho
|
175 |
|
176 |
if (pos, fim_corte) not in usados:
|
@@ -178,24 +215,20 @@ if st.session_state.processando:
|
|
178 |
usados.add((pos, fim_corte))
|
179 |
pos = fim_corte
|
180 |
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
if excluir_fim < dur:
|
187 |
-
cortes.append((excluir_fim, dur))
|
188 |
-
barra.progress(25)
|
189 |
|
190 |
-
# --- PROCESSAR OS CORTES ---
|
191 |
-
with tempfile.TemporaryDirectory() as tmpdir:
|
192 |
arquivos_cortes = []
|
193 |
total_cortes = len(cortes)
|
|
|
194 |
for idx, (start, end) in enumerate(cortes):
|
195 |
saida = os.path.join(tmpdir, f"clip_{idx}.mp4")
|
196 |
|
197 |
subprocess.call([
|
198 |
-
"ffmpeg", "-y", "-i",
|
199 |
"-ss", str(start), "-to", str(end),
|
200 |
"-filter:v", f"setpts=PTS/{velocidade_cortes}",
|
201 |
"-an",
|
|
|
125 |
status.markdown("🔎 Analisando duração e resolução do vídeo...")
|
126 |
barra.progress(5)
|
127 |
|
128 |
+
# Duração e resolução
|
129 |
duracao_cmd = [
|
130 |
"ffprobe", "-v", "error", "-show_entries",
|
131 |
+
"format=duration", "-of", "default=noprint_wrappers=1:nokey=1", video_path
|
|
|
132 |
]
|
133 |
resultado = subprocess.run(duracao_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
134 |
dur = float(resultado.stdout.decode().strip())
|
|
|
148 |
excluir_fim = st.session_state.excluir_fim
|
149 |
velocidade_cortes = st.session_state.velocidade_cortes
|
150 |
|
151 |
+
barra.progress(10)
|
152 |
+
status.markdown("🧹 Removendo parte indesejada...")
|
153 |
|
154 |
+
with tempfile.TemporaryDirectory() as tmpdir:
|
155 |
+
parte1 = os.path.join(tmpdir, "parte1.mp4")
|
156 |
+
parte2 = os.path.join(tmpdir, "parte2.mp4")
|
157 |
+
video_base = os.path.join(tmpdir, "video_base.mp4")
|
|
|
|
|
158 |
|
|
|
159 |
if excluir_inicio > 0:
|
160 |
+
subprocess.call([
|
161 |
+
"ffmpeg", "-y", "-i", video_path,
|
162 |
+
"-t", str(excluir_inicio),
|
163 |
+
"-c", "copy",
|
164 |
+
parte1
|
165 |
+
])
|
166 |
if excluir_fim < dur:
|
167 |
+
subprocess.call([
|
168 |
+
"ffmpeg", "-y", "-i", video_path,
|
169 |
+
"-ss", str(excluir_fim),
|
170 |
+
"-c", "copy",
|
171 |
+
parte2
|
172 |
+
])
|
173 |
+
|
174 |
+
with open(os.path.join(tmpdir, "lista_remocao.txt"), "w") as f:
|
175 |
+
if os.path.exists(parte1):
|
176 |
+
f.write(f"file '{parte1}'\n")
|
177 |
+
if os.path.exists(parte2):
|
178 |
+
f.write(f"file '{parte2}'\n")
|
179 |
|
180 |
+
subprocess.call([
|
181 |
+
"ffmpeg", "-y", "-f", "concat", "-safe", "0", "-i",
|
182 |
+
os.path.join(tmpdir, "lista_remocao.txt"),
|
183 |
+
"-c", "copy",
|
184 |
+
video_base
|
185 |
+
])
|
186 |
+
|
187 |
+
barra.progress(15)
|
188 |
+
status.markdown("✂️ Preparando cortes...")
|
189 |
+
|
190 |
+
cortes = []
|
191 |
+
usados = set()
|
192 |
+
|
193 |
+
if st.session_state.embaralhar_cortes:
|
194 |
+
corte_min = st.session_state.corte_min
|
195 |
+
corte_max = st.session_state.corte_max
|
196 |
+
|
197 |
+
# Duração nova (do vídeo já limpo)
|
198 |
+
resultado = subprocess.run([
|
199 |
+
"ffprobe", "-v", "error", "-show_entries",
|
200 |
+
"format=duration", "-of",
|
201 |
+
"default=noprint_wrappers=1:nokey=1", video_base
|
202 |
+
], stdout=subprocess.PIPE)
|
203 |
+
dur_base = float(resultado.stdout.decode().strip())
|
204 |
+
|
205 |
+
pos = 0
|
206 |
+
while pos < dur_base:
|
207 |
+
tam_possivel = min(corte_max, dur_base - pos)
|
208 |
if tam_possivel < corte_min:
|
209 |
break
|
210 |
+
tamanho = random.randint(corte_min, int(tam_possivel))
|
211 |
fim_corte = pos + tamanho
|
212 |
|
213 |
if (pos, fim_corte) not in usados:
|
|
|
215 |
usados.add((pos, fim_corte))
|
216 |
pos = fim_corte
|
217 |
|
218 |
+
random.shuffle(cortes)
|
219 |
+
else:
|
220 |
+
# Sem cortes — usa vídeo já limpo
|
221 |
+
cortes = [(0, dur)] # isso será ignorado e o vídeo_base usado direto mais abaixo
|
222 |
+
barra.progress(25)
|
|
|
|
|
|
|
223 |
|
|
|
|
|
224 |
arquivos_cortes = []
|
225 |
total_cortes = len(cortes)
|
226 |
+
|
227 |
for idx, (start, end) in enumerate(cortes):
|
228 |
saida = os.path.join(tmpdir, f"clip_{idx}.mp4")
|
229 |
|
230 |
subprocess.call([
|
231 |
+
"ffmpeg", "-y", "-i", video_base,
|
232 |
"-ss", str(start), "-to", str(end),
|
233 |
"-filter:v", f"setpts=PTS/{velocidade_cortes}",
|
234 |
"-an",
|