Spaces:
Running
Running
Speed up prepared video playback
Browse files
app.py
CHANGED
|
@@ -447,6 +447,8 @@ def probe_video(path):
|
|
| 447 |
return 0
|
| 448 |
|
| 449 |
duration = numeric(video.get("duration")) or numeric(metadata.get("format", {}).get("duration"))
|
|
|
|
|
|
|
| 450 |
fps_text = video.get("avg_frame_rate", "0/1")
|
| 451 |
try:
|
| 452 |
numerator, denominator = fps_text.split("/", 1)
|
|
@@ -462,6 +464,7 @@ def probe_video(path):
|
|
| 462 |
Path(path).suffix.lower() == ".mp4"
|
| 463 |
and video.get("codec_name") == "h264"
|
| 464 |
and video.get("pix_fmt") == "yuv420p"
|
|
|
|
| 465 |
and duration > 0
|
| 466 |
)
|
| 467 |
return {"duration": duration, "frames": total_frames, "compatible": compatible}
|
|
@@ -506,8 +509,11 @@ def finalize_videos(work, cameras, job):
|
|
| 506 |
temporary.unlink(missing_ok=True)
|
| 507 |
command = [
|
| 508 |
"ffmpeg", "-hide_banner", "-loglevel", "error", "-nostats", "-y", "-i", str(source),
|
| 509 |
-
"-map", "0:v:0", "-an", "-sn", "-dn",
|
|
|
|
| 510 |
"-c:v", "libx264", "-preset", "veryfast", "-crf", "23", "-pix_fmt", "yuv420p",
|
|
|
|
|
|
|
| 511 |
"-fps_mode", "passthrough", "-movflags", "+faststart", "-progress", "pipe:1", str(temporary),
|
| 512 |
]
|
| 513 |
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1)
|
|
|
|
| 447 |
return 0
|
| 448 |
|
| 449 |
duration = numeric(video.get("duration")) or numeric(metadata.get("format", {}).get("duration"))
|
| 450 |
+
width = int(video.get("width") or 0)
|
| 451 |
+
height = int(video.get("height") or 0)
|
| 452 |
fps_text = video.get("avg_frame_rate", "0/1")
|
| 453 |
try:
|
| 454 |
numerator, denominator = fps_text.split("/", 1)
|
|
|
|
| 464 |
Path(path).suffix.lower() == ".mp4"
|
| 465 |
and video.get("codec_name") == "h264"
|
| 466 |
and video.get("pix_fmt") == "yuv420p"
|
| 467 |
+
and max(width, height) <= 1920
|
| 468 |
and duration > 0
|
| 469 |
)
|
| 470 |
return {"duration": duration, "frames": total_frames, "compatible": compatible}
|
|
|
|
| 509 |
temporary.unlink(missing_ok=True)
|
| 510 |
command = [
|
| 511 |
"ffmpeg", "-hide_banner", "-loglevel", "error", "-nostats", "-y", "-i", str(source),
|
| 512 |
+
"-map", "0:v:0", "-an", "-sn", "-dn",
|
| 513 |
+
"-vf", "scale=w='if(gte(iw,ih),min(1920,iw),-2)':h='if(gte(iw,ih),-2,min(1920,ih))'",
|
| 514 |
"-c:v", "libx264", "-preset", "veryfast", "-crf", "23", "-pix_fmt", "yuv420p",
|
| 515 |
+
"-g", "60", "-keyint_min", "60", "-sc_threshold", "0",
|
| 516 |
+
"-force_key_frames", "expr:gte(t,n_forced*2)",
|
| 517 |
"-fps_mode", "passthrough", "-movflags", "+faststart", "-progress", "pipe:1", str(temporary),
|
| 518 |
]
|
| 519 |
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1)
|