fix: use ffmpeg -progress pipe for reliable apply progress
This commit is contained in:
1 parent
d0b7d1e07b
commit
f5af9c534a
2 files changed
+144
-46
No files matched your search
+29
-5
@@ -136,6 +136,8 @@ def main():
|
||||
ap.add_argument("--b", default=None, help="Video file B (delayed audio source)")
|
||||
ap.add_argument("--lag", type=float, required=True, help="Lag in seconds (B relative to A, positive = B delayed)")
|
||||
ap.add_argument("--out", default=None, help="Output file path (overrides config)")
|
||||
ap.add_argument("--progress", action="store_true",
|
||||
help="Stream ffmpeg -progress key=value lines to stdout for GUI parsing")
|
||||
args = ap.parse_args()
|
||||
|
||||
file_a = args.a
|
||||
@@ -176,11 +178,33 @@ def main():
|
||||
print(f"Output: {out_path}")
|
||||
|
||||
cmd = build_ffmpeg_cmd(file_a, file_b, args.lag, out_path)
|
||||
print(f"\nRunning: {' '.join(cmd)}")
|
||||
r = subprocess.run(cmd)
|
||||
if r.returncode != 0:
|
||||
print(f"ERROR: ffmpeg failed with code {r.returncode}", file=sys.stderr)
|
||||
sys.exit(r.returncode)
|
||||
print(f"\nRunning: {' '.join(cmd)}", file=sys.stderr, flush=True)
|
||||
if args.progress:
|
||||
# Machine-readable progress on stdout: frame=, out_time_ms=, progress=end.
|
||||
# -nostats suppresses the \r human stats that GUIs cannot parse line-wise.
|
||||
# Output options must precede the output path (last element).
|
||||
cmd = cmd[:-1] + ["-progress", "pipe:1", "-nostats", cmd[-1]]
|
||||
# stderr stays attached to the terminal: ffmpeg's final summary line
|
||||
# (video:/audio: sizes) must remain visible, only stats are silenced.
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
||||
universal_newlines=True, bufsize=1)
|
||||
assert proc.stdout is not None
|
||||
for line in proc.stdout:
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
# Forward only progress protocol lines; keep stdout parseable.
|
||||
if "=" in line:
|
||||
print(line, flush=True)
|
||||
rc = proc.wait()
|
||||
if rc != 0:
|
||||
print(f"ERROR: ffmpeg failed with code {rc}", file=sys.stderr)
|
||||
sys.exit(rc)
|
||||
else:
|
||||
r = subprocess.run(cmd)
|
||||
if r.returncode != 0:
|
||||
print(f"ERROR: ffmpeg failed with code {r.returncode}", file=sys.stderr)
|
||||
sys.exit(r.returncode)
|
||||
|
||||
print(f"\nSynced output: {out_path}")
|
||||
|
||||
|
||||
Reference in new issue
Block a user