Spaces:
Running
Running
Commit Β·
e75f322
1
Parent(s): 3c7c247
feat(video): preserve audio track and fix video frame assembly
Browse files- Pass original input.mp4 as second ffmpeg input to copy audio stream
- Use -c:a aac + -shortest for broad browser compatibility
- Push PROJECT_SCOPE.md to repo
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
app.py
CHANGED
|
@@ -479,15 +479,20 @@ async def pipeline_video(body: dict,
|
|
| 479 |
if written == 0:
|
| 480 |
raise HTTPException(status_code=400, detail="Video contained no readable frames")
|
| 481 |
|
| 482 |
-
# ββ assemble H264 MP4 with ffmpeg βββββββββ
|
| 483 |
subprocess.run([
|
| 484 |
"ffmpeg", "-y",
|
| 485 |
"-r", str(fps),
|
| 486 |
-
"-i", os.path.join(frm_dir, "%06d.jpg"),
|
|
|
|
|
|
|
|
|
|
| 487 |
"-vcodec", "libx264",
|
| 488 |
"-pix_fmt", "yuv420p",
|
| 489 |
"-crf", "23",
|
| 490 |
"-preset", "fast",
|
|
|
|
|
|
|
| 491 |
out_path,
|
| 492 |
], check=True, capture_output=True)
|
| 493 |
|
|
|
|
| 479 |
if written == 0:
|
| 480 |
raise HTTPException(status_code=400, detail="Video contained no readable frames")
|
| 481 |
|
| 482 |
+
# ββ assemble H264 MP4 with ffmpeg (preserve original audio) βββββββββ
|
| 483 |
subprocess.run([
|
| 484 |
"ffmpeg", "-y",
|
| 485 |
"-r", str(fps),
|
| 486 |
+
"-i", os.path.join(frm_dir, "%06d.jpg"), # annotated frames (video)
|
| 487 |
+
"-i", in_path, # original file (audio)
|
| 488 |
+
"-map", "0:v:0",
|
| 489 |
+
"-map", "1:a?", # copy audio track if present; '?' = optional
|
| 490 |
"-vcodec", "libx264",
|
| 491 |
"-pix_fmt", "yuv420p",
|
| 492 |
"-crf", "23",
|
| 493 |
"-preset", "fast",
|
| 494 |
+
"-c:a", "aac", # re-encode audio to AAC for max compatibility
|
| 495 |
+
"-shortest", # stop when shorter stream ends
|
| 496 |
out_path,
|
| 497 |
], check=True, capture_output=True)
|
| 498 |
|