Spaces:
Running
Running
Download source/scripts/make-example-video.mjs from Segizu/rotoscopia-lab: direct link, hf CLI and curl.
- Browser
- Download file 1.93 kB
-
https://huggingface.co/spaces/Segizu/rotoscopia-lab/resolve/main/source/scripts/make-example-video.mjs
- Command line
-
hf download hf://spaces/Segizu/rotoscopia-lab/source/scripts/make-example-video.mjs
-
curl -L -o make-example-video.mjs https://huggingface.co/spaces/Segizu/rotoscopia-lab/resolve/main/source/scripts/make-example-video.mjs
1.93 kB
| // Generates the SYNTHETIC example clip: a deterministic virtual camera pan+zoom over the CC0 photo | |
| // example-desk-laptop.jpg (no generative editing). The exact crop of every frame is written to | |
| // public/examples/video-pan.json so the tracking evidence can compute ground truth by geometry. | |
| import sharp from 'sharp'; | |
| import { mkdirSync, writeFileSync, rmSync } from 'node:fs'; | |
| import { execFileSync } from 'node:child_process'; | |
| const root = new URL('../', import.meta.url).pathname; | |
| const src = root + 'public/examples/example-desk-laptop.jpg'; | |
| const OUT_W = 640, OUT_H = 426, FPS = 10, N = 40; | |
| const meta = await sharp(src).metadata(); | |
| const tmp = '/tmp/rotoscopia-frames'; rmSync(tmp, { recursive: true, force: true }); mkdirSync(tmp); | |
| const frames = []; | |
| for (let i = 0; i < N; i++) { | |
| const u = i / (N - 1), e = 0.5 - 0.5 * Math.cos(Math.PI * u); // ease in-out | |
| const w = Math.round(820 - 140 * e), h = Math.round((w * OUT_H) / OUT_W); | |
| const left = Math.round(180 + 260 * e), top = Math.round(10 + 130 * e); | |
| frames.push({ i, t: i / FPS, left, top, width: w, height: h }); | |
| await sharp(src).extract({ left, top, width: w, height: h }).resize(OUT_W, OUT_H, { kernel: 'lanczos3' }).png().toFile(`${tmp}/f${String(i).padStart(3, '0')}.png`); | |
| } | |
| const mp4 = root + 'public/examples/example-desk-pan.mp4'; | |
| execFileSync('ffmpeg', ['-y', '-loglevel', 'error', '-framerate', String(FPS), '-i', `${tmp}/f%03d.png`, '-c:v', 'libx264', '-preset', 'veryslow', '-crf', '20', '-pix_fmt', 'yuv420p', '-movflags', '+faststart', '-an', mp4]); | |
| execFileSync('ffmpeg', ['-nostdin', '-y', '-loglevel', 'error', '-i', `${tmp}/f000.png`, '-q:v', '3', root + 'public/examples/example-desk-pan-poster.jpg']); | |
| writeFileSync(root + 'public/examples/video-pan.json', JSON.stringify({ source: 'example-desk-laptop.jpg', sourceSize: [meta.width, meta.height], out: [OUT_W, OUT_H], fps: FPS, frames }, null, 1)); | |
| console.log('wrote', mp4, N, 'frames'); | |