Update app.py
Browse files
app.py
CHANGED
|
@@ -191,8 +191,19 @@ def infer_video_depth(
|
|
| 191 |
# Speichern wir den Originalnamen
|
| 192 |
original_path = stitched_video_path
|
| 193 |
|
| 194 |
-
#
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
|
| 197 |
# Erstelle eine temporäre Textdatei für die stitched Videos
|
| 198 |
concat_stitched_file_path = os.path.join(output_dir, 'concat_stitched_list.txt')
|
|
@@ -200,8 +211,11 @@ def infer_video_depth(
|
|
| 200 |
for _ in range(loop_factor):
|
| 201 |
f.write(f"file '{original_path}'\n")
|
| 202 |
|
| 203 |
-
#
|
| 204 |
-
|
|
|
|
|
|
|
|
|
|
| 205 |
"ffmpeg",
|
| 206 |
"-y",
|
| 207 |
"-f", "concat",
|
|
@@ -210,61 +224,72 @@ def infer_video_depth(
|
|
| 210 |
"-c", "copy",
|
| 211 |
temp_looped_path
|
| 212 |
]
|
| 213 |
-
subprocess.run(
|
| 214 |
-
|
| 215 |
-
# Extrahiere den Audio-Track aus dem ursprünglichen Input-Video
|
| 216 |
-
audio_path = os.path.join(output_dir, 'extracted_audio.aac')
|
| 217 |
-
extract_audio_cmd = [
|
| 218 |
-
"ffmpeg",
|
| 219 |
-
"-y",
|
| 220 |
-
"-i", input_video,
|
| 221 |
-
"-vn", "-acodec", "copy",
|
| 222 |
-
audio_path
|
| 223 |
-
]
|
| 224 |
-
subprocess.run(extract_audio_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 225 |
-
|
| 226 |
-
# Erstelle eine Textdatei für das Audio-Looping
|
| 227 |
-
concat_audio_file_path = os.path.join(output_dir, 'concat_audio_list.txt')
|
| 228 |
-
with open(concat_audio_file_path, 'w') as f:
|
| 229 |
-
for _ in range(loop_factor):
|
| 230 |
-
f.write(f"file '{audio_path}'\n")
|
| 231 |
-
|
| 232 |
-
# Erstelle den geloopten Audio-Track
|
| 233 |
-
looped_audio_path = os.path.join(output_dir, 'looped_audio.aac')
|
| 234 |
-
audio_loop_cmd = [
|
| 235 |
-
"ffmpeg",
|
| 236 |
-
"-y",
|
| 237 |
-
"-f", "concat",
|
| 238 |
-
"-safe", "0",
|
| 239 |
-
"-i", concat_audio_file_path,
|
| 240 |
-
"-c", "copy",
|
| 241 |
-
looped_audio_path
|
| 242 |
-
]
|
| 243 |
-
subprocess.run(audio_loop_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 244 |
-
|
| 245 |
-
# Kombiniere das geloopte Video mit dem geloopten Audio
|
| 246 |
-
# Aber schreibe zurück in den originalen Pfad
|
| 247 |
-
final_cmd = [
|
| 248 |
-
"ffmpeg",
|
| 249 |
-
"-y",
|
| 250 |
-
"-i", temp_looped_path,
|
| 251 |
-
"-i", looped_audio_path,
|
| 252 |
-
"-c:v", "copy",
|
| 253 |
-
"-c:a", "aac",
|
| 254 |
-
"-map", "0:v:0",
|
| 255 |
-
"-map", "1:a:0",
|
| 256 |
-
"-shortest",
|
| 257 |
-
original_path # Verwenden des originalen Pfads als Ziel
|
| 258 |
-
]
|
| 259 |
-
subprocess.run(final_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 260 |
|
| 261 |
-
#
|
| 262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
# Bereinige temporäre Dateien
|
| 265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
if os.path.exists(file_path):
|
| 267 |
-
|
|
|
|
|
|
|
|
|
|
| 268 |
|
| 269 |
gc.collect()
|
| 270 |
torch.cuda.empty_cache()
|
|
|
|
| 191 |
# Speichern wir den Originalnamen
|
| 192 |
original_path = stitched_video_path
|
| 193 |
|
| 194 |
+
# Überprüfen wir, ob das Input-Video einen Audio-Stream hat
|
| 195 |
+
has_audio = False
|
| 196 |
+
check_audio_cmd = [
|
| 197 |
+
"ffmpeg",
|
| 198 |
+
"-i", input_video,
|
| 199 |
+
"-c", "copy",
|
| 200 |
+
"-f", "null",
|
| 201 |
+
"-"
|
| 202 |
+
]
|
| 203 |
+
result = subprocess.run(check_audio_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 204 |
+
stderr = result.stderr.decode('utf-8')
|
| 205 |
+
if "Audio" in stderr:
|
| 206 |
+
has_audio = True
|
| 207 |
|
| 208 |
# Erstelle eine temporäre Textdatei für die stitched Videos
|
| 209 |
concat_stitched_file_path = os.path.join(output_dir, 'concat_stitched_list.txt')
|
|
|
|
| 211 |
for _ in range(loop_factor):
|
| 212 |
f.write(f"file '{original_path}'\n")
|
| 213 |
|
| 214 |
+
# Temporärer Pfad für das geloopte Video ohne Audio
|
| 215 |
+
temp_looped_path = os.path.join(output_dir, 'temp_looped_rgbd.mp4')
|
| 216 |
+
|
| 217 |
+
# Verwende ffmpeg, um das Video zu loopen
|
| 218 |
+
concat_cmd = [
|
| 219 |
"ffmpeg",
|
| 220 |
"-y",
|
| 221 |
"-f", "concat",
|
|
|
|
| 224 |
"-c", "copy",
|
| 225 |
temp_looped_path
|
| 226 |
]
|
| 227 |
+
subprocess.run(concat_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
|
| 229 |
+
# Wenn Audio vorhanden ist, müssen wir es separat behandeln
|
| 230 |
+
if has_audio:
|
| 231 |
+
# Extrahiere den Audio-Track aus dem originalen Input-Video
|
| 232 |
+
# Dies ist die sauberste Quelle
|
| 233 |
+
audio_path = os.path.join(output_dir, 'extracted_audio.aac')
|
| 234 |
+
extract_audio_cmd = [
|
| 235 |
+
"ffmpeg",
|
| 236 |
+
"-y",
|
| 237 |
+
"-i", input_video, # Original Input-Video verwenden
|
| 238 |
+
"-vn", "-acodec", "copy",
|
| 239 |
+
audio_path
|
| 240 |
+
]
|
| 241 |
+
subprocess.run(extract_audio_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 242 |
+
|
| 243 |
+
# Erstelle eine Textdatei für das Audio-Looping
|
| 244 |
+
concat_audio_file_path = os.path.join(output_dir, 'concat_audio_list.txt')
|
| 245 |
+
with open(concat_audio_file_path, 'w') as f:
|
| 246 |
+
for _ in range(loop_factor):
|
| 247 |
+
f.write(f"file '{audio_path}'\n")
|
| 248 |
+
|
| 249 |
+
# Erstelle den geloopten Audio-Track
|
| 250 |
+
looped_audio_path = os.path.join(output_dir, 'looped_audio.aac')
|
| 251 |
+
audio_loop_cmd = [
|
| 252 |
+
"ffmpeg",
|
| 253 |
+
"-y",
|
| 254 |
+
"-f", "concat",
|
| 255 |
+
"-safe", "0",
|
| 256 |
+
"-i", concat_audio_file_path,
|
| 257 |
+
"-c", "copy",
|
| 258 |
+
looped_audio_path
|
| 259 |
+
]
|
| 260 |
+
subprocess.run(audio_loop_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 261 |
+
|
| 262 |
+
# Kombiniere das geloopte Video mit dem geloopten Audio
|
| 263 |
+
final_cmd = [
|
| 264 |
+
"ffmpeg",
|
| 265 |
+
"-y",
|
| 266 |
+
"-i", temp_looped_path,
|
| 267 |
+
"-i", looped_audio_path,
|
| 268 |
+
"-c:v", "copy",
|
| 269 |
+
"-c:a", "aac",
|
| 270 |
+
"-map", "0:v:0",
|
| 271 |
+
"-map", "1:a:0",
|
| 272 |
+
"-shortest",
|
| 273 |
+
original_path # Verwenden des originalen Pfads als Ziel
|
| 274 |
+
]
|
| 275 |
+
subprocess.run(final_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 276 |
+
else:
|
| 277 |
+
# Wenn kein Audio vorhanden ist, einfach das Video umbenennen
|
| 278 |
+
os.replace(temp_looped_path, original_path)
|
| 279 |
|
| 280 |
# Bereinige temporäre Dateien
|
| 281 |
+
temp_files = [concat_file_path, concat_stitched_file_path]
|
| 282 |
+
if has_audio:
|
| 283 |
+
temp_files.extend([concat_audio_file_path, audio_path, looped_audio_path])
|
| 284 |
+
if os.path.exists(temp_looped_path):
|
| 285 |
+
temp_files.append(temp_looped_path)
|
| 286 |
+
|
| 287 |
+
for file_path in temp_files:
|
| 288 |
if os.path.exists(file_path):
|
| 289 |
+
try:
|
| 290 |
+
os.remove(file_path)
|
| 291 |
+
except:
|
| 292 |
+
pass
|
| 293 |
|
| 294 |
gc.collect()
|
| 295 |
torch.cuda.empty_cache()
|