remotion-ffmpeg-skill 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/SKILL.md +14 -1
- package/package.json +3 -2
- package/references/scripts.md +5 -3
- package/scripts/_contract.py +5 -3
- package/scripts/_sparse.py +87 -0
- package/scripts/render.py +77 -3
- package/templates/remotion-project/src/compositions/Karaoke.tsx +3 -1
package/README.md
CHANGED
|
@@ -116,10 +116,12 @@ This skill is MIT. **Remotion itself has its own licence**: free for individuals
|
|
|
116
116
|
|
|
117
117
|
Remotion renders in a headless browser. Measured on a 2-core Linux machine: a 30 s 1080p30 render takes about 80 s (≈ 2.6× the clip length) with render.py's default of all CPU cores — Remotion's own default (half the cores) took 170 s. More cores scale it further. Check with `still.py` and `--fast` before a full render of long footage.
|
|
118
118
|
|
|
119
|
+
**`--sparse`** (Captioned, Karaoke): only the frames that show a caption are drawn; ffmpeg-skill places each stretch back at its time over the untouched source. Same picture frame for frame (checked by an integration test), and the render time follows the captioned share of the footage: 60 s with 7 s of captions took 46 s instead of 152 s. Needs an ffmpeg-skill whose `overlay.py` has `--place`; otherwise it draws the full layer and says why.
|
|
120
|
+
|
|
119
121
|
## Agent evals
|
|
120
122
|
|
|
121
|
-
Plain requests ("captions for YouTube", a Japanese Reels jump cut, "cut to the beat", a lower third without a name, a plain trim that is *not* this skill's job, a square highlight reel), run by an agent that only has the skill files, graded on what it leaves behind — plus a transparent layer for an editor, joining clips with titles, and karaoke from word timings: **9 / 9** ([run 1](evals/results/2026-10-24.md), [run 2](evals/results/2026-10-24b.md), [how to run](evals/README.md)).
|
|
123
|
+
Plain requests ("captions for YouTube", a Japanese Reels jump cut, "cut to the beat", a lower third without a name, a plain trim that is *not* this skill's job, a square highlight reel), run by an agent that only has the skill files, graded on what it leaves behind — plus a transparent layer for an editor, joining clips with titles, and karaoke from word timings: **9 / 9** ([run 1](evals/results/2026-10-24.md), [run 2](evals/results/2026-10-24b.md), [how to run](evals/README.md)). A third run with a neutral prompt (both skills installed, no hint) went to ffmpeg-skill alone for three requests it can finish by itself — 6 / 9 by the original checks, 9 / 9 once that route is accepted ([run 3](evals/results/2026-10-24c.md)).
|
|
122
124
|
|
|
123
125
|
## Status
|
|
124
126
|
|
|
125
|
-
0.
|
|
127
|
+
0.5. CI renders every composition on Linux, macOS and Windows (Node 22, Remotion 4.0.538, ffmpeg-skill main).
|
package/SKILL.md
CHANGED
|
@@ -20,6 +20,7 @@ Shared flags (every script): `--json` (one JSON object on stdout; prefer it), `-
|
|
|
20
20
|
- **Shape:** draw in the shape it will be delivered in. `--aspect 9:16` for Reels / TikTok / Shorts (`1:1`, `4:5`, `16:9` too); `--fit blur` (default when the shape changes: contained over a blurred copy), `contain` (bars) or `cover` (crop — check the subject in the still first). Never render 16:9 and let a 9:16 template crop it: captions lose their edges. `pipeline.py --platform` picks the aspect from ffmpeg-skill's template for you.
|
|
21
21
|
- **Fonts:** Japanese / Chinese / Korean captions get the CJK font ffmpeg-skill finds on the machine automatically (staged into the project, so no tofu); `--font-file F.ttf` uses a specific font; the report line `font:` says which was used, or that none was found.
|
|
22
22
|
- **Editing-app layer:** `--overlay --keep-graphics` (Captioned / PeakPulse, source shape) draws the graphics alone as a transparent ProRes 4444 `.graphics.mov` and composites it over the untouched source with ffmpeg-skill `overlay.py`; hand the `.mov` to someone finishing in Premiere / Resolve / Final Cut. It is not faster than a normal render.
|
|
23
|
+
- **Long footage with gaps between captions:** `--sparse` (Captioned / Karaoke) draws only the frames where a caption shows and places each stretch back at its time with ffmpeg-skill `overlay.py --place` — same picture, frame for frame. It needs an ffmpeg-skill with `--place`; without it (or when the source does not start at 0) it draws the full layer and says why in `sparse.reason`.
|
|
23
24
|
5. **Deliver.** `deliver.py OUT.mp4 --platform youtube|reels|tiktok|shorts|x|...` runs ffmpeg-skill's delivery template and its `check.py` table. Format rows are safe to fix; judgement rows (duration, aspect) change content — ask. Mention WARNs, don't chase them. No destination named: skip this step and say so.
|
|
24
25
|
6. **Look.** Not finished until the reply names the contact sheet render.py wrote (`Look: PATH`) and says what it shows. Mechanical (check and report): text is where it was asked, cues appear at their times, nothing is cut off by the frame. Judgement (say what you see, the user decides): text over a face, a jump that lands badly. No image view: `Look: PATH (pixels not inspected)` — never claim you looked. No contact sheet (`look_error` in the result, e.g. an FFmpeg without `drawtext`): look at `still.py` frames instead and pass on the fix the error names.
|
|
25
26
|
|
|
@@ -29,6 +30,17 @@ MCP: `mcp/server.py` exposes the same tools (schemas from `scripts/_contract.py`
|
|
|
29
30
|
|
|
30
31
|
Everything in one go: `pipeline.py SOURCE --project ./motion --comp NAME [--captions F] [--platform P]` runs 2→4→5 with the same checks and stops at the first failed step.
|
|
31
32
|
|
|
33
|
+
## This skill or ffmpeg-skill alone?
|
|
34
|
+
|
|
35
|
+
ffmpeg-skill by itself already does silence cuts, burned-in (also pop / karaoke) captions, title and lower-third templates, joins and platform templates, without a browser render. For a request that fits those, ffmpeg-skill alone is a valid and faster answer. Choose this skill when the request needs something ffmpeg-skill does not draw:
|
|
36
|
+
|
|
37
|
+
- motion tied to measurements: punch-in zooms on jump cuts, pulses on peaks or beats, picture cuts on a beat grid, a highlight counter;
|
|
38
|
+
- a different shape **without losing picture**: ffmpeg-skill's Reels / TikTok / Shorts templates centre-crop a 16:9 source (`fit: crop`), so the sides are cut off; `--aspect 9:16 --fit blur` keeps the whole frame;
|
|
39
|
+
- the graphics as a separate transparent layer for an editor (`--overlay --keep-graphics`);
|
|
40
|
+
- a custom React composition, or the user asks for Remotion.
|
|
41
|
+
|
|
42
|
+
Whichever you choose, say which one and the trade-off that matters (for example "centre-cropped: the left and right edges are gone").
|
|
43
|
+
|
|
32
44
|
## Request → script / composition
|
|
33
45
|
|
|
34
46
|
| Request | Run |
|
|
@@ -44,6 +56,7 @@ Everything in one go: `pipeline.py SOURCE --project ./motion --comp NAME [--capt
|
|
|
44
56
|
| "vertical / 9:16 / square" | `render.py --aspect 9:16` (or `1:1`, `4:5`) |
|
|
45
57
|
| "Japanese captions" / a specific font | nothing extra for CJK (auto font); `--font-file` for a chosen font |
|
|
46
58
|
| "give me the graphics as a separate layer" | `render.py --overlay --keep-graphics` |
|
|
59
|
+
| captions on long footage (a talk, a lecture) | `render.py --comp Captioned --sparse` (or `Karaoke`): only the captioned stretches are drawn |
|
|
47
60
|
| "change colour / font / caption size / zoom" | an `--options` JSON (`references/timeline.md`), re-render |
|
|
48
61
|
| several clips ("intro + talk + outro") | `analyze.py A.mp4 B.mov C.mp4` (or `pipeline.py` with several inputs): ffmpeg-skill join.py normalises and joins them, then everything is measured on the joined file |
|
|
49
62
|
| "preview" / "show me a frame" | `still.py` |
|
|
@@ -62,6 +75,6 @@ Everything in one go: `pipeline.py SOURCE --project ./motion --comp NAME [--capt
|
|
|
62
75
|
- Remotion licence: free for individuals and for-profit organisations with up to 3 employees; larger companies need a Remotion company licence (https://www.remotion.dev/license). If the user is plainly a larger company, say so once.
|
|
63
76
|
- Keep the user's originals: sources are linked into `public/media/` of the project, never modified; outputs never overwrite an existing file without `--overwrite`.
|
|
64
77
|
- CJK captions: the auto font comes from ffmpeg-skill's font detection; when the report says no font was found, install one (Noto Sans CJK) or pass `--font-file` — tofu in the contact sheet is a failed job. Japanese lines break between phrases, not inside words.
|
|
65
|
-
- Speed (measured on a 2-core Linux machine, all cores — render.py's default): about 2.6× the clip length for 1080p30 (30 s took 80 s). Preview with `still.py` and `--fast` before a full render of long footage; tell the user the expected time before starting a long render. `--concurrency` above the core count is refused by Remotion.
|
|
78
|
+
- Speed (measured on a 2-core Linux machine, all cores — render.py's default): about 2.6× the clip length for 1080p30 (30 s took 80 s). Preview with `still.py` and `--fast` before a full render of long footage; tell the user the expected time before starting a long render. `--sparse` cuts that to the captioned share: 60 s with 7 s of captions went from 152 s to 46 s. `--concurrency` above the core count is refused by Remotion.
|
|
66
79
|
- Remotion packages in a project must all be the same version; the template pins them. Don't mix in a different `remotion` version.
|
|
67
80
|
- A render that fails verification is a failure: report the failed rows from `--json`, don't ship it.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remotion-ffmpeg-skill",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Agent Skill: ffmpeg-skill measures the footage, Remotion draws the motion graphics from those measurements, ffmpeg-skill checks and delivers the result. Timeline-driven captions, silence jump cuts and audio-peak motion with probe-first / verify-last rendering. Local, no API keys.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"remotion",
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
"references",
|
|
39
39
|
"mcp",
|
|
40
40
|
"LICENSE",
|
|
41
|
-
"README.md"
|
|
41
|
+
"README.md",
|
|
42
|
+
"!**/__pycache__"
|
|
42
43
|
],
|
|
43
44
|
"engines": {
|
|
44
45
|
"node": ">=18"
|
package/references/scripts.md
CHANGED
|
@@ -94,7 +94,7 @@ Render a composition from a timeline, verify it (frames, fps, size, audio) and w
|
|
|
94
94
|
- Role: execution — writes a new media artifact; inputs are never modified
|
|
95
95
|
- Writes: video file (+ contact sheet PNG)
|
|
96
96
|
- Verifies: exact frame count / fps / size / audio against the timeline; non-zero exit on mismatch
|
|
97
|
-
- ffmpeg-skill: probe, look, overlay (--overlay), _contract doctor (CJK font lookup)
|
|
97
|
+
- ffmpeg-skill: probe, look, overlay (--overlay; --place with --sparse), _contract doctor (CJK font lookup)
|
|
98
98
|
- `--dry-run`: plans without writing
|
|
99
99
|
|
|
100
100
|
| Argument | Type | Default | Meaning |
|
|
@@ -112,15 +112,17 @@ Render a composition from a timeline, verify it (frames, fps, size, audio) and w
|
|
|
112
112
|
| `--no-look` | boolean | | skip the contact sheet |
|
|
113
113
|
| `--overlay` | boolean | | draw the graphics only as a transparent ProRes 4444 layer and composite it over the untouched source with ffmpeg-skill overlay.py (Captioned / PeakPulse, source frame only); with --keep-graphics the layer is kept for an editing app (Premiere, Resolve, Final Cut) |
|
|
114
114
|
| `--keep-graphics` | boolean | | with --overlay: keep the transparent graphics .mov |
|
|
115
|
+
| `--sparse` | boolean | | overlay mode that draws only the frames where captions show (Captioned / Karaoke) and places each stretch at its time with ffmpeg-skill overlay.py --place: much faster on long footage with gaps between captions. Falls back to the full-length layer (and says why) when this ffmpeg-skill has no --place or the source does not start at 0 |
|
|
116
|
+
| `--merge-gap` | number | `2.0` | with --sparse: captions closer than this many seconds are drawn as one stretch (default 2) |
|
|
115
117
|
| `--aspect` | string: source / 16:9 / 9:16 / 1:1 / 4:5 / 4:3 | | output shape (default: the source's own). 9:16 for Reels/TikTok/Shorts, 1:1, 4:5, 16:9 |
|
|
116
118
|
| `--width` | integer | | output width in px (default: keep the source's short side) |
|
|
117
119
|
| `--fit` | string: blur / contain / cover | | how the source fills another shape: blur (default when the shape changes), contain (bars) or cover (crop) |
|
|
118
120
|
| `--font-file` | string | | caption font file (.ttf/.otf/.ttc/.woff2), staged into the project |
|
|
119
121
|
| `--no-auto-font` | boolean | | don't stage the CJK font ffmpeg-skill finds for Japanese/Chinese/Korean captions |
|
|
120
122
|
|
|
121
|
-
--json result (besides `status`, `dry_run`, `output`): `verified` (bool), `verification` (list[{check, status, value, expected}]), `commands` (list[str]), `look` (str|null (contact sheet PNG)), `look_error` (str|null), `summary` (str), `frame` (object|null), `font` (str|null), `mode` (full|overlay), `graphics` (str|null (kept ProRes 4444 layer)), `kind` (null|failed), `error` (null|str (which verification rows failed))
|
|
123
|
+
--json result (besides `status`, `dry_run`, `output`): `verified` (bool), `verification` (list[{check, status, value, expected}]), `commands` (list[str]), `look` (str|null (contact sheet PNG)), `look_error` (str|null), `summary` (str), `frame` (object|null), `font` (str|null), `mode` (full|overlay), `graphics` (str|null (kept ProRes 4444 layer)), `sparse` (null|{used, reason, stretches, drawn_frames, source_frames} (--sparse)), `kind` (null|failed), `error` (null|str (which verification rows failed))
|
|
122
124
|
|
|
123
|
-
--dry-run --json result (besides `status`, `dry_run`, `output`): `commands` (list[str]), `props` (str), `expected_frames` (int|null), `frame` (object|null), `font` (str|null)
|
|
125
|
+
--dry-run --json result (besides `status`, `dry_run`, `output`): `commands` (list[str]), `props` (str), `expected_frames` (int|null), `frame` (object|null), `font` (str|null), `sparse` (null|object (--sparse))
|
|
124
126
|
|
|
125
127
|
## deliver.py
|
|
126
128
|
|
package/scripts/_contract.py
CHANGED
|
@@ -62,7 +62,7 @@ TOOL_META: Dict[str, Dict[str, Any]] = {
|
|
|
62
62
|
"summary": "Render a composition from a timeline, verify it (frames, fps, size, audio) and write a contact sheet.",
|
|
63
63
|
"writes": "video file (+ contact sheet PNG)",
|
|
64
64
|
"verification": "exact frame count / fps / size / audio against the timeline; non-zero exit on mismatch",
|
|
65
|
-
"ffmpeg_skill": ["probe", "look", "overlay (--overlay)", "_contract doctor (CJK font lookup)"],
|
|
65
|
+
"ffmpeg_skill": ["probe", "look", "overlay (--overlay; --place with --sparse)", "_contract doctor (CJK font lookup)"],
|
|
66
66
|
"dry_run": True,
|
|
67
67
|
},
|
|
68
68
|
"deliver": {
|
|
@@ -114,10 +114,12 @@ OUTPUTS: Dict[str, Dict[str, Dict[str, str]]] = {
|
|
|
114
114
|
"result": {"verified": "bool", "verification": "list[{check, status, value, expected}]",
|
|
115
115
|
"commands": "list[str]", "look": "str|null (contact sheet PNG)", "look_error": "str|null",
|
|
116
116
|
"summary": "str", "frame": "object|null", "font": "str|null", "mode": "full|overlay",
|
|
117
|
-
"graphics": "str|null (kept ProRes 4444 layer)",
|
|
117
|
+
"graphics": "str|null (kept ProRes 4444 layer)",
|
|
118
|
+
"sparse": "null|{used, reason, stretches, drawn_frames, source_frames} (--sparse)",
|
|
119
|
+
"kind": "null|failed",
|
|
118
120
|
"error": "null|str (which verification rows failed)"},
|
|
119
121
|
"dry_run": {"commands": "list[str]", "props": "str", "expected_frames": "int|null", "frame": "object|null",
|
|
120
|
-
"font": "str|null"},
|
|
122
|
+
"font": "str|null", "sparse": "null|object (--sparse)"},
|
|
121
123
|
},
|
|
122
124
|
"deliver": {
|
|
123
125
|
"result": {"checked": "str", "platform": "str|null", "verified": "bool",
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Sparse overlay rendering: draw only the frames where captions show, then lay each drawn stretch
|
|
2
|
+
back at its own time with ffmpeg-skill `overlay.py --place`.
|
|
3
|
+
|
|
4
|
+
Remotion renders every frame in a browser, so a 30-minute talk with captions on a third of it spends
|
|
5
|
+
two thirds of the render on empty transparent frames. Here the caption cues are grouped into
|
|
6
|
+
stretches (cues closer than `merge_gap` seconds share one), the stretches are packed back to back
|
|
7
|
+
in a short timeline, Remotion draws that, and overlay.py places each stretch over the untouched
|
|
8
|
+
source. Frame numbers stay integers end to end, so the result matches the full-length overlay.
|
|
9
|
+
"""
|
|
10
|
+
import copy
|
|
11
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
12
|
+
|
|
13
|
+
from _common import sec_to_frames
|
|
14
|
+
|
|
15
|
+
SPARSE_COMPOSITIONS = ("Captioned", "Karaoke")
|
|
16
|
+
# One overlay filter per stretch: past this many, the filter chain costs more than it saves.
|
|
17
|
+
MAX_STRETCHES = 400
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def caption_stretches(timeline: Dict[str, Any], merge_gap: float) -> List[Tuple[int, int]]:
|
|
21
|
+
"""[(first_frame, end_frame)] of the frames that show a caption, cues closer than merge_gap merged."""
|
|
22
|
+
fps = float(timeline["source"]["fps"])
|
|
23
|
+
total = sec_to_frames(float(timeline["source"]["duration"]), fps)
|
|
24
|
+
gap = sec_to_frames(merge_gap, fps)
|
|
25
|
+
cues = sorted((sec_to_frames(c["start"], fps), sec_to_frames(c["end"], fps)) for c in timeline.get("captions") or [])
|
|
26
|
+
out: List[List[int]] = []
|
|
27
|
+
for s, e in cues:
|
|
28
|
+
# the same rule as the compositions: a cue lasts at least one frame, inside the source
|
|
29
|
+
s = max(0, min(s, total - 1))
|
|
30
|
+
e = min(total, max(e, s + 1))
|
|
31
|
+
if out and s <= out[-1][1] + gap:
|
|
32
|
+
out[-1][1] = max(out[-1][1], e)
|
|
33
|
+
else:
|
|
34
|
+
out.append([s, e])
|
|
35
|
+
return [(s, e) for s, e in out]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def pack(timeline: Dict[str, Any], stretches: List[Tuple[int, int]]) -> Tuple[Dict[str, Any], List[Tuple[int, int, int]]]:
|
|
39
|
+
"""A timeline with the stretches back to back (one blank frame between them) and, per stretch,
|
|
40
|
+
(packed_first_frame, length_frames, source_first_frame)."""
|
|
41
|
+
fps = float(timeline["source"]["fps"])
|
|
42
|
+
layout: List[Tuple[int, int, int]] = []
|
|
43
|
+
p = 0
|
|
44
|
+
for s, e in stretches:
|
|
45
|
+
layout.append((p, e - s, s))
|
|
46
|
+
p += (e - s) + 1
|
|
47
|
+
packed_frames = max(1, p - 1)
|
|
48
|
+
|
|
49
|
+
def offset(t: float) -> Optional[int]:
|
|
50
|
+
"""Whole frames to move a time by: its stretch's source start minus its packed start. Only
|
|
51
|
+
whole frames, so a word timed between two frames keeps exactly where it falls in its frame."""
|
|
52
|
+
f = sec_to_frames(t, fps)
|
|
53
|
+
for pp, n, s in layout:
|
|
54
|
+
if s <= f <= s + n:
|
|
55
|
+
return s - pp
|
|
56
|
+
return None
|
|
57
|
+
|
|
58
|
+
out = copy.deepcopy(timeline)
|
|
59
|
+
out["source"]["duration"] = packed_frames / fps
|
|
60
|
+
for key in ("captions", "words"):
|
|
61
|
+
moved = []
|
|
62
|
+
for c in timeline.get(key) or []:
|
|
63
|
+
# a word belongs where Karaoke puts it: by its midpoint
|
|
64
|
+
k = offset(c["start"] if key == "captions" else (c["start"] + c["end"]) / 2)
|
|
65
|
+
if k is not None:
|
|
66
|
+
moved.append({**c, "start": c["start"] - k / fps, "end": c["end"] - k / fps})
|
|
67
|
+
out[key] = moved
|
|
68
|
+
# Captioned and Karaoke draw nothing else; measurements on the source clock would only mislead.
|
|
69
|
+
for k in ("scenes", "silences", "speech", "peaks", "highlights", "clips"):
|
|
70
|
+
out[k] = []
|
|
71
|
+
out["beats"] = None
|
|
72
|
+
return out, layout
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def place_args(layout: List[Tuple[int, int, int]], fps: float) -> List[str]:
|
|
76
|
+
"""overlay.py --place arguments. Range edges sit half a frame inside the stretch, so the blank
|
|
77
|
+
frame between stretches is never picked up whatever the float rounding of a timestamp."""
|
|
78
|
+
args: List[str] = []
|
|
79
|
+
for pp, n, s in layout:
|
|
80
|
+
a = max(0.0, (pp - 0.5) / fps)
|
|
81
|
+
b = (pp + n - 0.5) / fps
|
|
82
|
+
args += ["--place", f"{a:.6f}-{b:.6f}@{s / fps:.6f}"]
|
|
83
|
+
return args
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def packed_frames(layout: List[Tuple[int, int, int]]) -> int:
|
|
87
|
+
return max(1, sum(n for _, n, _ in layout) + len(layout) - 1)
|
package/scripts/render.py
CHANGED
|
@@ -15,6 +15,7 @@ from pathlib import Path
|
|
|
15
15
|
from typing import Any, Dict, List, Optional, Tuple
|
|
16
16
|
|
|
17
17
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
18
|
+
import _sparse
|
|
18
19
|
from _common import (BUILTIN_COMPOSITIONS, STATE, add_common, add_frame_args, apply_common, die, emit, expected_frames,
|
|
19
20
|
ffskill, ffskill_cmd, frame_size, info, load_options, load_timeline, prepare_props, refuse_existing,
|
|
20
21
|
remotion_bin, require_ffmpeg_skill, require_project, remotion_error, run, shell_join)
|
|
@@ -43,6 +44,13 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
43
44
|
"untouched source with ffmpeg-skill overlay.py (Captioned / PeakPulse, source frame only); "
|
|
44
45
|
"with --keep-graphics the layer is kept for an editing app (Premiere, Resolve, Final Cut)")
|
|
45
46
|
p.add_argument("--keep-graphics", action="store_true", help="with --overlay: keep the transparent graphics .mov")
|
|
47
|
+
p.add_argument("--sparse", action="store_true",
|
|
48
|
+
help="overlay mode that draws only the frames where captions show (Captioned / Karaoke) and "
|
|
49
|
+
"places each stretch at its time with ffmpeg-skill overlay.py --place: much faster on long "
|
|
50
|
+
"footage with gaps between captions. Falls back to the full-length layer (and says why) "
|
|
51
|
+
"when this ffmpeg-skill has no --place or the source does not start at 0")
|
|
52
|
+
p.add_argument("--merge-gap", type=float, default=2.0,
|
|
53
|
+
help="with --sparse: captions closer than this many seconds are drawn as one stretch (default 2)")
|
|
46
54
|
add_frame_args(p)
|
|
47
55
|
add_common(p)
|
|
48
56
|
return p
|
|
@@ -126,6 +134,52 @@ def verify(out_probe: Dict[str, Any], timeline: Dict[str, Any], comp: str,
|
|
|
126
134
|
return all(r["status"] != "FAIL" for r in rows), rows
|
|
127
135
|
|
|
128
136
|
|
|
137
|
+
def ffskill_can_place() -> bool:
|
|
138
|
+
"""Whether this ffmpeg-skill's overlay.py has --place (ffmpeg-skill PR #353)."""
|
|
139
|
+
import subprocess
|
|
140
|
+
try:
|
|
141
|
+
proc = subprocess.run(ffskill_cmd("overlay", ["--help"]), capture_output=True, text=True, timeout=60)
|
|
142
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
143
|
+
return False
|
|
144
|
+
return "--place" in (proc.stdout or "")
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def sparse_plan(timeline: Dict[str, Any], a: argparse.Namespace) -> Dict[str, Any]:
|
|
148
|
+
"""What --sparse will draw, or why it falls back to the full-length layer."""
|
|
149
|
+
src = timeline["source"]
|
|
150
|
+
fps = float(src["fps"])
|
|
151
|
+
total = expected_frames(a.comp, timeline) or 1
|
|
152
|
+
plan: Dict[str, Any] = {"used": False, "reason": None, "stretches": 0, "drawn_frames": total,
|
|
153
|
+
"source_frames": total, "timeline": None, "place": []}
|
|
154
|
+
stretches = _sparse.caption_stretches(timeline, a.merge_gap)
|
|
155
|
+
start = None
|
|
156
|
+
if stretches and src.get("path") and not STATE.dry_run:
|
|
157
|
+
# the source as it is now (older timelines do not record where its first picture sits)
|
|
158
|
+
start = (ffskill("probe", [str(src["path"])], allow_fail=True).get("video") or {}).get("start_time")
|
|
159
|
+
if not stretches:
|
|
160
|
+
plan["reason"] = "no captions to draw"
|
|
161
|
+
elif len(stretches) > _sparse.MAX_STRETCHES:
|
|
162
|
+
plan["reason"] = (f"{len(stretches)} caption stretches (over {_sparse.MAX_STRETCHES}); raise --merge-gap")
|
|
163
|
+
elif isinstance(start, (int, float)) and abs(start) > 0.5 / fps:
|
|
164
|
+
plan["reason"] = (f"the source's first picture is at {start:.3f} s, not 0: placed stretches would be "
|
|
165
|
+
"shifted by that much")
|
|
166
|
+
elif not ffskill_can_place():
|
|
167
|
+
plan["reason"] = "this ffmpeg-skill's overlay.py has no --place yet (update ffmpeg-skill)"
|
|
168
|
+
else:
|
|
169
|
+
packed, layout = _sparse.pack(timeline, stretches)
|
|
170
|
+
drawn = _sparse.packed_frames(layout)
|
|
171
|
+
if drawn >= total:
|
|
172
|
+
plan["reason"] = "captions cover the whole source: nothing to skip"
|
|
173
|
+
else:
|
|
174
|
+
plan.update(used=True, stretches=len(layout), drawn_frames=drawn, timeline=packed,
|
|
175
|
+
place=_sparse.place_args(layout, fps))
|
|
176
|
+
if plan["reason"]:
|
|
177
|
+
info(f"--sparse: drawing the full length instead ({plan['reason']})")
|
|
178
|
+
else:
|
|
179
|
+
info(f"--sparse: drawing {plan['drawn_frames']} of {total} frames in {plan['stretches']} stretch(es)")
|
|
180
|
+
return plan
|
|
181
|
+
|
|
182
|
+
|
|
129
183
|
def main() -> None:
|
|
130
184
|
a = build_parser().parse_args()
|
|
131
185
|
apply_common(a)
|
|
@@ -147,6 +201,13 @@ def main() -> None:
|
|
|
147
201
|
output = output.resolve()
|
|
148
202
|
refuse_existing(output)
|
|
149
203
|
|
|
204
|
+
if a.sparse:
|
|
205
|
+
if a.comp not in _sparse.SPARSE_COMPOSITIONS:
|
|
206
|
+
die(f"--sparse draws caption stretches only: {a.comp} is not one of "
|
|
207
|
+
f"{', '.join(_sparse.SPARSE_COMPOSITIONS)} (use --overlay for the full-length layer)", "input")
|
|
208
|
+
if a.merge_gap < 0:
|
|
209
|
+
die("--merge-gap cannot be negative", "input")
|
|
210
|
+
a.overlay = True
|
|
150
211
|
if a.overlay:
|
|
151
212
|
if a.comp in ("Jumpcut", "Highlights", "BeatMontage"):
|
|
152
213
|
die(f"--overlay cannot do {a.comp}: its cuts move the picture itself (overlay works for "
|
|
@@ -158,18 +219,24 @@ def main() -> None:
|
|
|
158
219
|
if not timeline["source"].get("has_video"):
|
|
159
220
|
die("--overlay needs a video source to composite onto", "input")
|
|
160
221
|
|
|
161
|
-
|
|
222
|
+
sparse = sparse_plan(timeline, a) if a.sparse else None
|
|
223
|
+
drawn = sparse["timeline"] if sparse and sparse["used"] else timeline
|
|
224
|
+
props_path, frame, font_note = prepare_props(project, a.comp, drawn, options, a)
|
|
162
225
|
if font_note:
|
|
163
226
|
info(font_note)
|
|
164
227
|
graphics = output.with_name(output.stem + ".graphics.mov") if a.overlay else output
|
|
165
228
|
cmd = remotion_render_cmd(project, a.comp, graphics, props_path, a)
|
|
166
229
|
ov_args = [timeline["source"]["path"], "--video", str(graphics), "--position", "0,0", "--margin", "0",
|
|
167
230
|
"-o", str(output)] + (["--overwrite"] if STATE.overwrite else [])
|
|
231
|
+
if sparse and sparse["used"]:
|
|
232
|
+
ov_args += sparse["place"]
|
|
233
|
+
sparse_note = None if not sparse else {k: sparse[k] for k in ("used", "reason", "stretches", "drawn_frames",
|
|
234
|
+
"source_frames")}
|
|
168
235
|
if STATE.dry_run:
|
|
169
236
|
plan = [shell_join(cmd)] + ([shell_join(ffskill_cmd("overlay", ov_args))] if a.overlay else [])
|
|
170
237
|
emit({"output": str(output), "commands": plan, "props": str(props_path),
|
|
171
238
|
"expected_frames": (frames[1] - frames[0] + 1) if frames else expected_frames(a.comp, timeline),
|
|
172
|
-
"frame": frame, "font": font_note},
|
|
239
|
+
"frame": frame, "font": font_note, "sparse": sparse_note},
|
|
173
240
|
f"would render {a.comp} -> {output}")
|
|
174
241
|
return
|
|
175
242
|
|
|
@@ -182,6 +249,13 @@ def main() -> None:
|
|
|
182
249
|
tail = remotion_error((proc.stderr or "") + "\n" + (proc.stdout or ""))
|
|
183
250
|
die(f"Remotion render failed (exit {proc.returncode}):\n{tail}", "failed", command=shell_join(cmd))
|
|
184
251
|
commands = [shell_join(cmd)]
|
|
252
|
+
if sparse and sparse["used"]:
|
|
253
|
+
# the packed layer must hold exactly the frames the placements read
|
|
254
|
+
gp = ffskill("probe", [str(graphics)])
|
|
255
|
+
nb = (gp.get("video") or {}).get("nb_frames")
|
|
256
|
+
if isinstance(nb, int) and nb != sparse["drawn_frames"]:
|
|
257
|
+
die(f"--sparse: the drawn layer has {nb} frames, the placements expect {sparse['drawn_frames']}",
|
|
258
|
+
"failed", command=shell_join(cmd))
|
|
185
259
|
if a.overlay:
|
|
186
260
|
info(f"compositing the graphics over the source with ffmpeg-skill overlay.py -> {output}")
|
|
187
261
|
ov = ffskill("overlay", ov_args)
|
|
@@ -213,7 +287,7 @@ def main() -> None:
|
|
|
213
287
|
result = {"status": "completed" if ok else "failed", "output": str(output), "verified": ok,
|
|
214
288
|
"verification": rows, "commands": commands, "look": look, "summary": summary,
|
|
215
289
|
"frame": frame, "font": font_note, "mode": "overlay" if a.overlay else "full", "look_error": look_error,
|
|
216
|
-
"graphics": str(graphics) if a.overlay and a.keep_graphics else None,
|
|
290
|
+
"graphics": str(graphics) if a.overlay and a.keep_graphics else None, "sparse": sparse_note,
|
|
217
291
|
"kind": None if ok else "failed",
|
|
218
292
|
"error": None if ok else "verification failed: " + ", ".join(r["check"] for r in rows if r["status"] == "FAIL")}
|
|
219
293
|
table = "\n".join(f" {r['check']:<9} {r['status']:<4} {r['value']} (expected {r['expected']})" for r in rows)
|
|
@@ -48,7 +48,9 @@ const KaraokeCue: React.FC<{ cue: Caption; words: Caption[]; len: number; o: Opt
|
|
|
48
48
|
const fade = Math.min(6, Math.floor(len / 3));
|
|
49
49
|
const exit = fade > 0 ? interpolate(frame, [len - fade, len], [1, 0], { extrapolateLeft: "clamp", extrapolateRight: "clamp" }) : 1;
|
|
50
50
|
const size = Math.round(Math.min(width, height) * o.captionSize * 1.1);
|
|
51
|
-
|
|
51
|
+
// Source time at this frame. The microsecond nudge settles a word boundary that falls exactly on a
|
|
52
|
+
// frame (5.2 + 21/30 vs 5.9) the same way whatever float rounding produced the two numbers.
|
|
53
|
+
const now = cue.start + frame / fps + 1e-6;
|
|
52
54
|
const lang = /[-ヿ]/.test(cue.text) ? "ja" : /[가-]/.test(cue.text) ? "ko" : undefined;
|
|
53
55
|
return (
|
|
54
56
|
<AbsoluteFill style={{ justifyContent: "flex-end", alignItems: "center", paddingBottom: captionMarginPx(o, width, height) }}>
|