Spaces:
Running on Zero
Running on Zero
| """Headless end-to-end check. Runs before app.py exists, and keeps working after.""" | |
| import argparse, pathlib, sys, time | |
| sys.path.insert(0, str(pathlib.Path(__file__).parent)) | |
| import rife_core as R | |
| def main() -> int: | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("src") | |
| ap.add_argument("-o", "--out", default="out.mp4") | |
| ap.add_argument("-x", "--factor", type=int, default=2) | |
| ap.add_argument("--budget", type=float, default=100.0, help="seconds per segment") | |
| a = ap.parse_args() | |
| clip = R.probe(a.src) | |
| print(f"[probe] {clip.width}x{clip.height} {clip.fps:.3f}fps " | |
| f"{clip.frames} frames {clip.duration:.2f}s") | |
| be = R.OnnxBackend() | |
| print(f"[backend] {be.name}, {R.CPUS} threads") | |
| rate = R.measure_rate(be, clip.height, clip.width) | |
| new_frames = clip.frames * (a.factor - 1) | |
| print(f"[rate] {rate:.3f} s/frame -> est {rate*new_frames:.1f}s " | |
| f"for {new_frames} generated frames") | |
| seg_s = R.plan_segments(clip, a.factor, rate, a.budget) | |
| nseg = max(1, int(clip.duration / seg_s + 0.999)) | |
| print(f"[plan] {nseg} segment(s) of {seg_s:.2f}s") | |
| parts, t0 = [], time.time() | |
| tmpdir = pathlib.Path(a.out).parent / "_segs" | |
| tmpdir.mkdir(exist_ok=True) | |
| total = 0 | |
| for i in range(nseg): | |
| p = str(tmpdir / f"seg{i:04d}.mp4") | |
| n = R.interpolate_segment(a.src, p, i * seg_s, seg_s, a.factor, be, clip) | |
| total += n | |
| parts.append(p) | |
| print(f"[+{time.time()-t0:6.1f}s] [{i+1}/{nseg}] {n} frames -> {pathlib.Path(p).name}") | |
| R.concat(parts, a.out) | |
| print(f"[done] {total} frames in {time.time()-t0:.1f}s -> {a.out}") | |
| got = R.probe(a.out) | |
| print(f"[verify] {got.width}x{got.height} {got.fps:.3f}fps {got.frames} frames " | |
| f"{got.duration:.2f}s") | |
| ok = abs(got.fps - clip.fps * a.factor) < 0.5 and got.frames >= clip.frames * a.factor * 0.8 | |
| print(f"[verify] fps x{a.factor} and frame count plausible: {ok}") | |
| return 0 if ok else 1 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |