remotion-ffmpeg-skill 0.6.0 → 0.8.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 +3 -2
- package/SKILL.md +6 -6
- package/package.json +1 -1
- package/references/scripts.md +8 -5
- package/references/timeline.md +3 -1
- package/scripts/_captions.py +60 -1
- package/scripts/_common.py +5 -2
- package/scripts/_contract.py +3 -2
- package/scripts/_sparse.py +111 -36
- package/scripts/analyze.py +24 -3
- package/scripts/deliver.py +38 -3
- package/scripts/pipeline.py +9 -1
- package/scripts/render.py +16 -14
- package/templates/remotion-project/src/compositions/Titled.tsx +79 -4
- package/templates/remotion-project/src/timeline.ts +12 -0
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ npx remotion-ffmpeg-skill # this skill, next to it in ~/.claude/skills
|
|
|
46
46
|
- "Put animated captions from `talk.srt` on `talk.mp4` and make it a YouTube upload."
|
|
47
47
|
- "Cut the silences out of this recording, jump-cut style, and keep the subtitles in sync."
|
|
48
48
|
- "Make graphics that hit on the loud moments of `clip.mp4`, as a Reel."
|
|
49
|
+
- "Here are my chapters (`0:00 Intro` …): put them on screen and make it a YouTube upload." — a card at each chapter start, chapter markers in the file, and the description block to paste.
|
|
49
50
|
- "Japanese captions, vertical, for TikTok." — renders 9:16 with a blurred fill, stages a CJK font automatically, breaks lines between phrases.
|
|
50
51
|
|
|
51
52
|
## Under the hood
|
|
@@ -80,7 +81,7 @@ Tool names and input schemas come from the machine-readable contract (`npx remot
|
|
|
80
81
|
| `Captioned` | source duration | caption cards that spring in on each cue (text exactly as written) |
|
|
81
82
|
| `Jumpcut` | sum of measured speech ranges | silences removed, punch-in on every other cut, captions re-timed |
|
|
82
83
|
| `PeakPulse` | source duration | edge glow + zoom on measured audio peaks or beats, flash on scene cuts, progress bar |
|
|
83
|
-
| `Titled` | source duration | your lower thirds
|
|
84
|
+
| `Titled` | source duration | your lower thirds, a title card at each measured scene change, a card at each chapter start |
|
|
84
85
|
| `Highlights` | sum of ranked highlights | ffmpeg-skill's audio-energy highlights back to back, counter, title |
|
|
85
86
|
| `BeatMontage` | source duration | audio unbroken, picture cuts on the measured beat grid |
|
|
86
87
|
| `Karaoke` | source duration | words light up at the times a local speech engine measured |
|
|
@@ -116,7 +117,7 @@ This skill is MIT. **Remotion itself has its own licence**: free for individuals
|
|
|
116
117
|
|
|
117
118
|
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
119
|
|
|
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
|
+
**`--sparse`** (Captioned, Karaoke, Titled): only the frames that show a caption, lower third or scene title 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; 40 s with two scene titles and a lower third, 39 s instead of 104 s. Needs an ffmpeg-skill whose `overlay.py` has `--place`; otherwise it draws the full layer and says why.
|
|
120
121
|
|
|
121
122
|
## Agent evals
|
|
122
123
|
|
package/SKILL.md
CHANGED
|
@@ -20,7 +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
|
+
- **Long footage with gaps between captions:** `--sparse` (Captioned / Karaoke / Titled) draws only the frames where a caption, lower third or scene title 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`.
|
|
24
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.
|
|
25
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.
|
|
26
26
|
|
|
@@ -35,11 +35,10 @@ Everything in one go: `pipeline.py SOURCE --project ./motion --comp NAME [--capt
|
|
|
35
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
36
|
|
|
37
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
38
|
- the graphics as a separate transparent layer for an editor (`--overlay --keep-graphics`);
|
|
40
39
|
- a custom React composition, or the user asks for Remotion.
|
|
41
40
|
|
|
42
|
-
Whichever you choose, say which one and the trade-off that matters (for example "centre-cropped: the left and right edges are gone").
|
|
41
|
+
Changing the shape alone is not a reason: ffmpeg-skill's Reels / TikTok / Shorts templates centre-crop by default, but ffmpeg-skill can also keep the whole frame on a blurred fill. Whichever you choose, say which one and the trade-off that matters (for example "centre-cropped: the left and right edges are gone").
|
|
43
42
|
|
|
44
43
|
## Request → script / composition
|
|
45
44
|
|
|
@@ -49,14 +48,15 @@ Whichever you choose, say which one and the trade-off that matters (for example
|
|
|
49
48
|
| "cut the silences / jump cut / tighten this talk" (with motion) | `analyze.py` → `render.py --comp Jumpcut` (captions re-timed if given) |
|
|
50
49
|
| "graphics that react to the audio / hit on the beat / on cuts" | `analyze.py [--beats]` → `render.py --comp PeakPulse` (pulses on beats when the grid was measured) |
|
|
51
50
|
| "karaoke captions / words light up as they're spoken" | `analyze.py --words WORDS.json [--captions F.srt]` → `render.py --comp Karaoke` (word timings from a local speech engine, whisper JSON; without an SRT the cues are grouped from the words) |
|
|
52
|
-
| "lower thirds / name titles /
|
|
51
|
+
| "lower thirds / name titles / scene titles" | `render.py --comp Titled --options` with `lowerThirds` / `sceneTitles` — the text comes from the user; ask for it, never invent names |
|
|
52
|
+
| "chapters" / a YouTube chapter list (`0:00 Intro` per line) | `analyze.py --chapters chapters.txt` (or `--chapters source` for markers the file already has) → `render.py --comp Titled` (a card at each chapter start, `chapterSeconds`) → `deliver.py --platform youtube --chapters chapters.txt` (markers in the file + `<name>_description.txt` to paste). Titles as written; a line without one is refused. Not with Jumpcut / Highlights: their cuts move every chapter |
|
|
53
53
|
| "highlight reel / best moments" | `analyze.py --highlights N [--target S]` → `render.py --comp Highlights` (audio-energy ranking: candidates, say so) |
|
|
54
54
|
| "cut to the beat / music montage" | `analyze.py --beats [--highlights N]` → `render.py --comp BeatMontage` (audio unbroken, picture cuts every `beatsPerCut` measured beats; scene cuts if no confident grid) |
|
|
55
55
|
| "for YouTube / Reels / TikTok ..." | `pipeline.py --platform` (renders in the template's aspect, then delivers and checks), or `render.py --aspect` + `deliver.py --platform` |
|
|
56
56
|
| "vertical / 9:16 / square" | `render.py --aspect 9:16` (or `1:1`, `4:5`) |
|
|
57
57
|
| "Japanese captions" / a specific font | nothing extra for CJK (auto font); `--font-file` for a chosen font |
|
|
58
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
|
|
59
|
+
| captions or name titles on long footage (a talk, a lecture) | `render.py --comp Captioned --sparse` (or `Karaoke`, `Titled`): only the stretches where something shows are drawn |
|
|
60
60
|
| "change colour / font / caption size / zoom" | an `--options` JSON (`references/timeline.md`), re-render |
|
|
61
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 |
|
|
62
62
|
| "preview" / "show me a frame" | `still.py` |
|
|
@@ -75,6 +75,6 @@ Whichever you choose, say which one and the trade-off that matters (for example
|
|
|
75
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.
|
|
76
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`.
|
|
77
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.
|
|
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
|
|
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 share that shows graphics: 60 s with 7 s of captions went from 152 s to 46 s; 40 s with two scene titles and one lower third from 104 s to 39 s. `--concurrency` above the core count is refused by Remotion.
|
|
79
79
|
- Remotion packages in a project must all be the same version; the template pins them. Don't mix in a different `remotion` version.
|
|
80
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.8.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",
|
package/references/scripts.md
CHANGED
|
@@ -25,6 +25,7 @@ Measure a source with ffmpeg-skill and write timeline.json (+ captions from a fi
|
|
|
25
25
|
| `--output` | string | | timeline file (default: <name>.timeline.json) |
|
|
26
26
|
| `--captions` | string | | SRT, WebVTT or JSON cue list to carry into the timeline (text kept as written) |
|
|
27
27
|
| `--words` | string | | word timings from a speech engine (whisper JSON with word timestamps) for the Karaoke composition; without --captions the cues are grouped from these words |
|
|
28
|
+
| `--chapters` | string | | chapter list, one `TIME TITLE` per line (YouTube's format, the same file ffmpeg-skill metadata.py --chapters writes into the container), or `source` for the chapters already in the input file; titles are kept as written |
|
|
28
29
|
| `--beats` | boolean | | also measure the beat grid (scenes.py --beats) |
|
|
29
30
|
| `--highlights` | integer | | also rank N highlight ranges (scenes.py --highlights; audio energy) for the Highlights composition |
|
|
30
31
|
| `--target` | number | | with --highlights: total length the picks add up to |
|
|
@@ -35,7 +36,7 @@ Measure a source with ffmpeg-skill and write timeline.json (+ captions from a fi
|
|
|
35
36
|
| `--margin` | number | | seconds of silence kept around speech (default 0.15) |
|
|
36
37
|
| `--scene-threshold` | number | | scenes.py --threshold (default 8) |
|
|
37
38
|
|
|
38
|
-
--json result (besides `status`, `dry_run`, `output`): `commands` (list[str]), `verified` (bool), `summary` (object: duration, fps, size, scenes, silences, speech_seconds, peaks, captions, beats, tempo_bpm, highlights, clips, words), `warnings` (list[str])
|
|
39
|
+
--json result (besides `status`, `dry_run`, `output`): `commands` (list[str]), `verified` (bool), `summary` (object: duration, fps, size, scenes, silences, speech_seconds, peaks, captions, chapters, beats, tempo_bpm, highlights, clips, words), `warnings` (list[str])
|
|
39
40
|
|
|
40
41
|
--dry-run --json result (besides `status`, `dry_run`, `output`): `commands` (list[str])
|
|
41
42
|
|
|
@@ -112,8 +113,8 @@ Render a composition from a timeline, verify it (frames, fps, size, audio) and w
|
|
|
112
113
|
| `--no-look` | boolean | | skip the contact sheet |
|
|
113
114
|
| `--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
115
|
| `--keep-graphics` | boolean | | with --overlay: keep the transparent graphics .mov |
|
|
115
|
-
| `--sparse` | boolean | | overlay mode that draws only the frames where
|
|
116
|
-
| `--merge-gap` | number | `2.0` | with --sparse:
|
|
116
|
+
| `--sparse` | boolean | | overlay mode that draws only the frames where something shows (Captioned / Karaoke / Titled) 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 |
|
|
117
|
+
| `--merge-gap` | number | `2.0` | with --sparse: graphics closer than this many seconds are drawn as one stretch (default 2) |
|
|
117
118
|
| `--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 |
|
|
118
119
|
| `--width` | integer | | output width in px (default: keep the source's short side) |
|
|
119
120
|
| `--fit` | string: blur / contain / cover | | how the source fills another shape: blur (default when the shape changes), contain (bars) or cover (crop) |
|
|
@@ -131,7 +132,7 @@ Run an ffmpeg-skill delivery template (YouTube, Reels, ...) and its compliance c
|
|
|
131
132
|
- Role: execution — writes a new media artifact; inputs are never modified
|
|
132
133
|
- Writes: deliverable video
|
|
133
134
|
- Verifies: ffmpeg-skill check.py table; non-zero exit on any FAIL row
|
|
134
|
-
- ffmpeg-skill: render --template, check
|
|
135
|
+
- ffmpeg-skill: render --template, metadata (--chapters), check
|
|
135
136
|
- `--dry-run`: plans without writing
|
|
136
137
|
|
|
137
138
|
| Argument | Type | Default | Meaning |
|
|
@@ -140,8 +141,9 @@ Run an ffmpeg-skill delivery template (YouTube, Reels, ...) and its compliance c
|
|
|
140
141
|
| `--platform` | string: youtube / youtube-shorts / shorts / reels / tiktok / x / facebook / linkedin / podcast / audiogram | | ffmpeg-skill delivery template to run |
|
|
141
142
|
| `--output` | string | | deliverable path (default: <name>_<platform>.mp4) |
|
|
142
143
|
| `--check-only` | boolean | | run check.py only, write nothing |
|
|
144
|
+
| `--chapters` | string | | also write these chapters (`TIME TITLE` per line) into the deliverable with ffmpeg-skill metadata.py, plus the YouTube description block next to it (<name>_description.txt) |
|
|
143
145
|
|
|
144
|
-
--json result (besides `status`, `dry_run`, `output`): `checked` (str), `platform` (str|null), `verified` (bool), `checks` (list[{check, status, value, expected, ...}] (ffmpeg-skill check.py rows)), `failed` (list[str]), `warnings` (list[str]), `commands` (list[str]), `kind` (null|failed), `error` (null|str)
|
|
146
|
+
--json result (besides `status`, `dry_run`, `output`): `checked` (str), `platform` (str|null), `verified` (bool), `description` (str|null (YouTube description block with the chapters, --chapters)), `checks` (list[{check, status, value, expected, ...}] (ffmpeg-skill check.py rows)), `failed` (list[str]), `warnings` (list[str]), `commands` (list[str]), `kind` (null|failed), `error` (null|str)
|
|
145
147
|
|
|
146
148
|
--dry-run --json result (besides `status`, `dry_run`, `output`): `commands` (list[str])
|
|
147
149
|
|
|
@@ -161,6 +163,7 @@ analyze -> render -> deliver in one call, stopping at the first failed step.
|
|
|
161
163
|
| `--project (required)` | string | | Remotion project folder made by init.py |
|
|
162
164
|
| `--comp (required)` | string | | composition id (Captioned, Jumpcut, PeakPulse, Titled, Highlights, BeatMontage, Karaoke, or yours) |
|
|
163
165
|
| `--captions` | string | | SRT / WebVTT / JSON cues for the timeline |
|
|
166
|
+
| `--chapters` | string | | chapters (`TIME TITLE` per line, or `source`): cards in Titled and, with --platform, chapter markers in the deliverable |
|
|
164
167
|
| `--options` | string | | JSON options file passed to the composition |
|
|
165
168
|
| `--platform` | string: youtube / youtube-shorts / shorts / reels / tiktok / x / facebook / linkedin / podcast / audiogram | | deliver with this ffmpeg-skill template and check it |
|
|
166
169
|
| `--out-dir` | string | | where the timeline, render and deliverable go (default: next to the input) |
|
package/references/timeline.md
CHANGED
|
@@ -25,6 +25,7 @@ props (`{ "timeline": ..., "options": ..., "frame": ..., "font": ..., "overlay":
|
|
|
25
25
|
| `highlights` | `[{start, end}]` | scenes.py `--highlights` | ranked by audio energy, stored in source order (analyze.py `--highlights N [--target S]`) |
|
|
26
26
|
| `clips` | `[{name, path, start, end}]` | analyze.py with several inputs | where each input sits after ffmpeg-skill join.py joined them (empty for one input) |
|
|
27
27
|
| `captions` | `[{start, end, text}]` | your SRT / VTT / JSON, or grouped from `words` | text exactly as written, timed on the (joined) source |
|
|
28
|
+
| `chapters` | `[{start, end, title}]` | `--chapters FILE` (`TIME TITLE` per line, YouTube's format) or `--chapters source` (the file's own markers) | titles as written; each ends where the next starts. YouTube's rules (first at 0:00, at least three, each ≥ 10 s) become warnings |
|
|
28
29
|
| `words` | `[{start, end, text}]` | `--words` (whisper JSON with word timestamps, `{"words": [...]}` or a list) | per-word timings with the engine's own spacing; Karaoke lights them up |
|
|
29
30
|
| `warnings` | `[string]` | analyze.py | VFR, HDR, rotation, odd frame rate |
|
|
30
31
|
|
|
@@ -39,7 +40,7 @@ composition exactly.
|
|
|
39
40
|
| `Captioned` | source duration | source + caption cards that spring in on each cue and fade out |
|
|
40
41
|
| `Jumpcut` | sum of `speech` ranges | speech ranges back to back, punch-in zoom on every other cut, captions re-timed (parts inside removed silences dropped) |
|
|
41
42
|
| `PeakPulse` | source duration | source + edge glow and slight zoom on each audio peak (scaled by its rms) or on each measured beat (`driver`), flash on scene cuts, progress bar with cut ticks |
|
|
42
|
-
| `Titled` | source duration | source + the user's lower thirds (`lowerThirds`) + a title card at the start of each measured scene (`sceneTitles`, in order) |
|
|
43
|
+
| `Titled` | source duration | source + the user's lower thirds (`lowerThirds`) + a title card at the start of each measured scene (`sceneTitles`, in order) + a chapter card at each chapter start (`chapters`, numbered n / total) |
|
|
43
44
|
| `Highlights` | sum of `highlights` (whole file if none) | ranked ranges back to back in source order, flash on cuts, "2 / 5" counter, `title` over the first |
|
|
44
45
|
| `Karaoke` | source duration | caption cues whose words light up at their measured times (current word accent + lift, spoken white, upcoming dimmed); cues without timed words show plain |
|
|
45
46
|
| `BeatMontage` | source duration | audio unbroken; the picture cuts every `beatsPerCut` measured beats, cycling through highlights (or scenes); no usable grid → cuts on scene changes |
|
|
@@ -63,6 +64,7 @@ Every key is optional.
|
|
|
63
64
|
| `sceneTitles` | `[]` | Titled: one title per measured scene, in order |
|
|
64
65
|
| `title` | `null` | Highlights: title over the first highlight |
|
|
65
66
|
| `beatsPerCut` | `4` | BeatMontage: measured beats per shot |
|
|
67
|
+
| `chapterSeconds` | `4` | Titled: how long a chapter card stays up (cut short by the next chapter; 0 = none) |
|
|
66
68
|
|
|
67
69
|
Unknown keys and wrong types are refused by render.py / still.py before anything renders.
|
|
68
70
|
|
package/scripts/_captions.py
CHANGED
|
@@ -7,7 +7,7 @@ shortens or paraphrases caption words -- the same rule as ffmpeg-skill.
|
|
|
7
7
|
import json
|
|
8
8
|
import re
|
|
9
9
|
from pathlib import Path
|
|
10
|
-
from typing import Dict, List
|
|
10
|
+
from typing import Any, Dict, List
|
|
11
11
|
|
|
12
12
|
_TS = re.compile(r"(?:(\d+):)?(\d{1,2}):(\d{2})[.,](\d{1,3})")
|
|
13
13
|
_ARROW = re.compile(r"^\s*(\S+)\s+-->\s+(\S+)")
|
|
@@ -139,3 +139,62 @@ def cues_from_words(words: List[Dict], max_chars: int = 32, max_gap: float = 0.7
|
|
|
139
139
|
|
|
140
140
|
def _cue(ws: List[Dict]) -> Dict:
|
|
141
141
|
return {"start": ws[0]["start"], "end": ws[-1]["end"], "text": "".join(w["text"] for w in ws).strip()}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# ---------------------------------------------------------------- chapters
|
|
145
|
+
|
|
146
|
+
def _chapter_time(tok: str) -> float:
|
|
147
|
+
"""seconds, mm:ss or hh:mm:ss (with optional .ms) -- the syntax of ffmpeg-skill's chapters.txt."""
|
|
148
|
+
parts = tok.split(":")
|
|
149
|
+
if not 1 <= len(parts) <= 3 or not all(p.replace(".", "", 1).isdigit() for p in parts):
|
|
150
|
+
raise CaptionError(f"not a time: {tok!r} (use 0:00, 2:15 or 1:03:00)")
|
|
151
|
+
if any("." in p for p in parts[:-1]):
|
|
152
|
+
raise CaptionError(f"not a time: {tok!r}")
|
|
153
|
+
v = 0.0
|
|
154
|
+
for p in parts:
|
|
155
|
+
v = v * 60 + float(p)
|
|
156
|
+
return v
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def parse_chapters(text: str, duration: float) -> List[Dict[str, Any]]:
|
|
160
|
+
"""`TIME TITLE` per line (YouTube's description format, ffmpeg-skill metadata.py's chapters.txt)
|
|
161
|
+
-> [{start, end, title}]. Titles are the user's text: a line without one is an error, never
|
|
162
|
+
a made-up "Chapter 2"."""
|
|
163
|
+
out: List[Dict[str, Any]] = []
|
|
164
|
+
for n, raw in enumerate(text.splitlines(), start=1):
|
|
165
|
+
line = raw.strip()
|
|
166
|
+
if not line or line.startswith("#"):
|
|
167
|
+
continue
|
|
168
|
+
parts = line.split(None, 1)
|
|
169
|
+
start = _chapter_time(parts[0])
|
|
170
|
+
title = parts[1].strip() if len(parts) > 1 else ""
|
|
171
|
+
# "0:00 - Intro" / "0:00 – Intro": the separator is not part of the title
|
|
172
|
+
for sep in ("- ", "– ", "— ", ": "):
|
|
173
|
+
if title.startswith(sep):
|
|
174
|
+
title = title[len(sep):].strip()
|
|
175
|
+
if not title:
|
|
176
|
+
raise CaptionError(f"line {n}: chapter at {parts[0]} has no title")
|
|
177
|
+
if out and start <= out[-1]["start"]:
|
|
178
|
+
raise CaptionError(f"line {n}: chapter at {parts[0]} does not come after the previous one")
|
|
179
|
+
if duration and start >= duration:
|
|
180
|
+
raise CaptionError(f"line {n}: chapter at {parts[0]} starts at or after the end ({duration:.3f} s)")
|
|
181
|
+
out.append({"start": start, "title": title})
|
|
182
|
+
if not out:
|
|
183
|
+
raise CaptionError("no chapters found (one per line: `0:00 Intro`)")
|
|
184
|
+
for i, c in enumerate(out):
|
|
185
|
+
c["end"] = out[i + 1]["start"] if i + 1 < len(out) else duration
|
|
186
|
+
return out
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def youtube_chapter_warnings(chapters: List[Dict[str, Any]]) -> List[str]:
|
|
190
|
+
"""YouTube only turns a description list into chapters when the first is at 0:00, there are at
|
|
191
|
+
least three, and each lasts at least 10 seconds."""
|
|
192
|
+
w = []
|
|
193
|
+
if chapters and chapters[0]["start"] != 0:
|
|
194
|
+
w.append("chapters: the first does not start at 0:00, so YouTube will not show them as chapters")
|
|
195
|
+
if len(chapters) < 3:
|
|
196
|
+
w.append("chapters: fewer than three, so YouTube will not show them as chapters")
|
|
197
|
+
short = [c["title"] for c in chapters if c["end"] - c["start"] < 10]
|
|
198
|
+
if short:
|
|
199
|
+
w.append("chapters shorter than 10 s (YouTube ignores the list): " + ", ".join(short))
|
|
200
|
+
return w
|
package/scripts/_common.py
CHANGED
|
@@ -221,7 +221,7 @@ def validate_timeline(t: Any) -> List[str]:
|
|
|
221
221
|
v = src.get(k)
|
|
222
222
|
if not isinstance(v, (int, float)) or v <= 0:
|
|
223
223
|
p.append(f"source.{k} must be a positive number")
|
|
224
|
-
for k in ("scenes", "silences", "speech", "peaks", "captions", "highlights", "words"):
|
|
224
|
+
for k in ("scenes", "silences", "speech", "peaks", "captions", "highlights", "words", "chapters"):
|
|
225
225
|
if not isinstance(t.get(k, []), list):
|
|
226
226
|
p.append(f"{k} must be a list")
|
|
227
227
|
for i, c in enumerate(t.get("captions", []) or []):
|
|
@@ -510,7 +510,7 @@ _OPTION_TYPES: Dict[str, Any] = {
|
|
|
510
510
|
"accent": str, "textColor": str, "fontFamily": str, "captionSize": (int, float),
|
|
511
511
|
"captionMargin": (int, float, type(None)), "punchIn": (int, float), "pulse": (int, float),
|
|
512
512
|
"progressBar": bool, "driver": str, "lowerThirds": list, "sceneTitles": list,
|
|
513
|
-
"title": (str, type(None)), "beatsPerCut": int,
|
|
513
|
+
"title": (str, type(None)), "beatsPerCut": int, "chapterSeconds": (int, float),
|
|
514
514
|
}
|
|
515
515
|
|
|
516
516
|
|
|
@@ -533,6 +533,9 @@ def validate_options(o: Dict[str, Any]) -> List[str]:
|
|
|
533
533
|
and isinstance(lt.get("start"), (int, float)) and isinstance(lt.get("end"), (int, float))
|
|
534
534
|
and lt["end"] > lt["start"] and isinstance(lt.get("sub", ""), str)):
|
|
535
535
|
p.append(f"lowerThirds[{i}] needs text, start < end (seconds) and an optional sub")
|
|
536
|
+
if isinstance(o.get("chapterSeconds"), (int, float)) and not isinstance(o["chapterSeconds"], bool) \
|
|
537
|
+
and o["chapterSeconds"] < 0:
|
|
538
|
+
p.append("chapterSeconds cannot be negative")
|
|
536
539
|
if any(not isinstance(s, str) for s in (o.get("sceneTitles") or [])):
|
|
537
540
|
p.append("sceneTitles must be a list of strings")
|
|
538
541
|
return p
|
package/scripts/_contract.py
CHANGED
|
@@ -70,7 +70,7 @@ TOOL_META: Dict[str, Dict[str, Any]] = {
|
|
|
70
70
|
"summary": "Run an ffmpeg-skill delivery template (YouTube, Reels, ...) and its compliance check.",
|
|
71
71
|
"writes": "deliverable video",
|
|
72
72
|
"verification": "ffmpeg-skill check.py table; non-zero exit on any FAIL row",
|
|
73
|
-
"ffmpeg_skill": ["render --template", "check"],
|
|
73
|
+
"ffmpeg_skill": ["render --template", "metadata (--chapters)", "check"],
|
|
74
74
|
"dry_run": True,
|
|
75
75
|
},
|
|
76
76
|
"pipeline": {
|
|
@@ -97,7 +97,7 @@ TOOL_META: Dict[str, Dict[str, Any]] = {
|
|
|
97
97
|
OUTPUTS: Dict[str, Dict[str, Dict[str, str]]] = {
|
|
98
98
|
"analyze": {
|
|
99
99
|
"result": {"commands": "list[str]", "verified": "bool", "summary": "object: duration, fps, size, scenes, "
|
|
100
|
-
"silences, speech_seconds, peaks, captions, beats, tempo_bpm, highlights, clips, words",
|
|
100
|
+
"silences, speech_seconds, peaks, captions, chapters, beats, tempo_bpm, highlights, clips, words",
|
|
101
101
|
"warnings": "list[str]"},
|
|
102
102
|
"dry_run": {"commands": "list[str]"},
|
|
103
103
|
},
|
|
@@ -123,6 +123,7 @@ OUTPUTS: Dict[str, Dict[str, Dict[str, str]]] = {
|
|
|
123
123
|
},
|
|
124
124
|
"deliver": {
|
|
125
125
|
"result": {"checked": "str", "platform": "str|null", "verified": "bool",
|
|
126
|
+
"description": "str|null (YouTube description block with the chapters, --chapters)",
|
|
126
127
|
"checks": "list[{check, status, value, expected, ...}] (ffmpeg-skill check.py rows)",
|
|
127
128
|
"failed": "list[str]", "warnings": "list[str]", "commands": "list[str]",
|
|
128
129
|
"kind": "null|failed", "error": "null|str"},
|
package/scripts/_sparse.py
CHANGED
|
@@ -1,50 +1,97 @@
|
|
|
1
|
-
"""Sparse overlay rendering: draw only the frames where
|
|
1
|
+
"""Sparse overlay rendering: draw only the frames where something shows, then lay each drawn stretch
|
|
2
2
|
back at its own time with ffmpeg-skill `overlay.py --place`.
|
|
3
3
|
|
|
4
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
|
|
6
|
-
|
|
7
|
-
in a short timeline, Remotion draws that,
|
|
8
|
-
|
|
5
|
+
two thirds of the render on empty transparent frames. Here the shown intervals (caption cues, or
|
|
6
|
+
Titled's lower thirds and scene cards) are grouped into stretches (intervals closer than `merge_gap`
|
|
7
|
+
seconds share one), the stretches are packed back to back in a short timeline, Remotion draws that,
|
|
8
|
+
and overlay.py places each stretch over the untouched source. Everything moves by whole frames, so
|
|
9
|
+
the result matches the full-length overlay frame for frame.
|
|
9
10
|
"""
|
|
10
11
|
import copy
|
|
11
12
|
from typing import Any, Dict, List, Optional, Tuple
|
|
12
13
|
|
|
13
14
|
from _common import sec_to_frames
|
|
14
15
|
|
|
15
|
-
SPARSE_COMPOSITIONS = ("Captioned", "Karaoke")
|
|
16
|
+
SPARSE_COMPOSITIONS = ("Captioned", "Karaoke", "Titled")
|
|
16
17
|
# One overlay filter per stretch: past this many, the filter chain costs more than it saves.
|
|
17
18
|
MAX_STRETCHES = 400
|
|
19
|
+
# Titled.tsx: a scene card lasts until the scene ends, at most this long.
|
|
20
|
+
SCENE_CARD_SECONDS = 2.5
|
|
21
|
+
# timeline.ts DEFAULT_OPTIONS.chapterSeconds
|
|
22
|
+
CHAPTER_SECONDS = 4.0
|
|
18
23
|
|
|
24
|
+
Layout = List[Tuple[int, int, int]] # (packed_first_frame, length_frames, source_first_frame)
|
|
19
25
|
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
|
|
27
|
+
def _scene_card(sc: Dict[str, Any], fps: float) -> Tuple[int, int]:
|
|
28
|
+
"""[from, end) frames of a scene card, as Titled.tsx computes them."""
|
|
29
|
+
s = sec_to_frames(sc["start"], fps)
|
|
30
|
+
return s, s + max(1, min(sec_to_frames(sc["end"], fps), s + sec_to_frames(SCENE_CARD_SECONDS, fps)) - s)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _chapter_card(ch: Dict[str, Any], fps: float, seconds: float) -> Tuple[int, int]:
|
|
34
|
+
"""[from, end) frames of a chapter card, as chapterCardFrames() in timeline.ts."""
|
|
35
|
+
s = sec_to_frames(ch["start"], fps)
|
|
36
|
+
return s, s + max(1, min(sec_to_frames(ch["end"], fps), s + sec_to_frames(seconds, fps)) - s)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def drawn_intervals(comp: str, timeline: Dict[str, Any], options: Optional[Dict[str, Any]] = None) -> List[Tuple[int, int]]:
|
|
40
|
+
"""[from, end) frames in which the composition draws anything (its Sequences)."""
|
|
22
41
|
fps = float(timeline["source"]["fps"])
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
42
|
+
o = options or {}
|
|
43
|
+
out: List[Tuple[int, int]] = []
|
|
44
|
+
if comp in ("Captioned", "Karaoke"):
|
|
45
|
+
for c in timeline.get("captions") or []:
|
|
46
|
+
s = sec_to_frames(c["start"], fps)
|
|
47
|
+
out.append((s, s + max(1, sec_to_frames(c["end"], fps) - s)))
|
|
48
|
+
elif comp == "Titled":
|
|
49
|
+
titles = o.get("sceneTitles") or []
|
|
50
|
+
for i, sc in enumerate(timeline.get("scenes") or []):
|
|
51
|
+
if i < len(titles) and titles[i]:
|
|
52
|
+
out.append(_scene_card(sc, fps))
|
|
53
|
+
for lt in o.get("lowerThirds") or []:
|
|
54
|
+
s = sec_to_frames(lt["start"], fps)
|
|
55
|
+
out.append((s, s + max(1, sec_to_frames(lt["end"], fps) - s)))
|
|
56
|
+
seconds = float(o.get("chapterSeconds", CHAPTER_SECONDS))
|
|
57
|
+
if seconds > 0:
|
|
58
|
+
out += [_chapter_card(ch, fps, seconds) for ch in timeline.get("chapters") or []]
|
|
59
|
+
return out
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def stretches(intervals: List[Tuple[int, int]], total: int, merge_gap_frames: int) -> List[Tuple[int, int]]:
|
|
63
|
+
"""Sorted, merged [from, end) stretches inside [0, total); intervals closer than the gap merge."""
|
|
26
64
|
out: List[List[int]] = []
|
|
27
|
-
for s, e in
|
|
28
|
-
# the same rule as the compositions: a cue lasts at least one frame, inside the source
|
|
65
|
+
for s, e in sorted(intervals):
|
|
29
66
|
s = max(0, min(s, total - 1))
|
|
30
67
|
e = min(total, max(e, s + 1))
|
|
31
|
-
if out and s <= out[-1][1] +
|
|
68
|
+
if out and s <= out[-1][1] + merge_gap_frames:
|
|
32
69
|
out[-1][1] = max(out[-1][1], e)
|
|
33
70
|
else:
|
|
34
71
|
out.append([s, e])
|
|
35
72
|
return [(s, e) for s, e in out]
|
|
36
73
|
|
|
37
74
|
|
|
38
|
-
def
|
|
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)."""
|
|
75
|
+
def plan_stretches(comp: str, timeline: Dict[str, Any], options: Optional[Dict[str, Any]], merge_gap: float) -> List[Tuple[int, int]]:
|
|
41
76
|
fps = float(timeline["source"]["fps"])
|
|
42
|
-
|
|
77
|
+
total = sec_to_frames(float(timeline["source"]["duration"]), fps)
|
|
78
|
+
return stretches(drawn_intervals(comp, timeline, options), total, sec_to_frames(merge_gap, fps))
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def caption_stretches(timeline: Dict[str, Any], merge_gap: float) -> List[Tuple[int, int]]:
|
|
82
|
+
return plan_stretches("Captioned", timeline, None, merge_gap)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def pack(timeline: Dict[str, Any], spans: List[Tuple[int, int]],
|
|
86
|
+
options: Optional[Dict[str, Any]] = None) -> Tuple[Dict[str, Any], Dict[str, Any], Layout]:
|
|
87
|
+
"""The timeline and options with the stretches back to back (one blank frame between them), and
|
|
88
|
+
the layout that puts each stretch back."""
|
|
89
|
+
fps = float(timeline["source"]["fps"])
|
|
90
|
+
layout: Layout = []
|
|
43
91
|
p = 0
|
|
44
|
-
for s, e in
|
|
92
|
+
for s, e in spans:
|
|
45
93
|
layout.append((p, e - s, s))
|
|
46
94
|
p += (e - s) + 1
|
|
47
|
-
packed_frames = max(1, p - 1)
|
|
48
95
|
|
|
49
96
|
def offset(t: float) -> Optional[int]:
|
|
50
97
|
"""Whole frames to move a time by: its stretch's source start minus its packed start. Only
|
|
@@ -55,24 +102,52 @@ def pack(timeline: Dict[str, Any], stretches: List[Tuple[int, int]]) -> Tuple[Di
|
|
|
55
102
|
return s - pp
|
|
56
103
|
return None
|
|
57
104
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
105
|
+
def moved(items: List[Dict[str, Any]], anchor) -> List[Dict[str, Any]]:
|
|
106
|
+
out = []
|
|
107
|
+
for c in items:
|
|
108
|
+
k = offset(anchor(c))
|
|
109
|
+
if k is not None:
|
|
110
|
+
out.append({**c, "start": c["start"] - k / fps, "end": c["end"] - k / fps})
|
|
111
|
+
return out
|
|
112
|
+
|
|
113
|
+
tl = copy.deepcopy(timeline)
|
|
114
|
+
tl["source"]["duration"] = packed_frames(layout) / fps
|
|
115
|
+
tl["captions"] = moved(timeline.get("captions") or [], lambda c: c["start"])
|
|
116
|
+
# a word belongs where Karaoke puts it: by its midpoint
|
|
117
|
+
tl["words"] = moved(timeline.get("words") or [], lambda w: (w["start"] + w["end"]) / 2)
|
|
118
|
+
opts = copy.deepcopy(options or {})
|
|
119
|
+
if opts.get("lowerThirds"):
|
|
120
|
+
opts["lowerThirds"] = moved(opts["lowerThirds"], lambda lt: lt["start"])
|
|
121
|
+
# Scene cards are matched to sceneTitles by index, so every scene keeps its place in the list:
|
|
122
|
+
# a titled one moves with its stretch and keeps its card length; the rest draw nothing anyway.
|
|
123
|
+
titles = opts.get("sceneTitles") or []
|
|
124
|
+
scenes = []
|
|
125
|
+
for i, sc in enumerate(timeline.get("scenes") or []):
|
|
126
|
+
if i < len(titles) and titles[i]:
|
|
127
|
+
s, e = _scene_card(sc, fps)
|
|
128
|
+
k = offset(sc["start"])
|
|
65
129
|
if k is not None:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
130
|
+
scenes.append({"start": (s - k) / fps, "end": (e - k) / fps})
|
|
131
|
+
continue
|
|
132
|
+
scenes.append({"start": 0.0, "end": 1.0 / fps})
|
|
133
|
+
tl["scenes"] = scenes if any(titles) else []
|
|
134
|
+
# a chapter keeps its card length (its end moves to the card's end) and its place in "n / of"
|
|
135
|
+
seconds = float(opts.get("chapterSeconds", CHAPTER_SECONDS))
|
|
136
|
+
chapters = []
|
|
137
|
+
for ch in timeline.get("chapters") or []:
|
|
138
|
+
s, e = _chapter_card(ch, fps, seconds) if seconds > 0 else (0, 1)
|
|
139
|
+
k = offset(ch["start"]) if seconds > 0 else None
|
|
140
|
+
chapters.append({**ch, "start": (s - k) / fps, "end": (e - k) / fps} if k is not None
|
|
141
|
+
else {**ch, "start": 0.0, "end": 1.0 / fps})
|
|
142
|
+
tl["chapters"] = chapters if seconds > 0 else []
|
|
143
|
+
# nothing else is drawn; measurements on the source clock would only mislead
|
|
144
|
+
for key in ("silences", "speech", "peaks", "highlights", "clips"):
|
|
145
|
+
tl[key] = []
|
|
146
|
+
tl["beats"] = None
|
|
147
|
+
return tl, opts, layout
|
|
73
148
|
|
|
74
149
|
|
|
75
|
-
def place_args(layout:
|
|
150
|
+
def place_args(layout: Layout, fps: float) -> List[str]:
|
|
76
151
|
"""overlay.py --place arguments. Range edges sit half a frame inside the stretch, so the blank
|
|
77
152
|
frame between stretches is never picked up whatever the float rounding of a timestamp."""
|
|
78
153
|
args: List[str] = []
|
|
@@ -83,5 +158,5 @@ def place_args(layout: List[Tuple[int, int, int]], fps: float) -> List[str]:
|
|
|
83
158
|
return args
|
|
84
159
|
|
|
85
160
|
|
|
86
|
-
def packed_frames(layout:
|
|
161
|
+
def packed_frames(layout: Layout) -> int:
|
|
87
162
|
return max(1, sum(n for _, n, _ in layout) + len(layout) - 1)
|
package/scripts/analyze.py
CHANGED
|
@@ -24,7 +24,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
|
24
24
|
from _common import (STATE, TIMELINE_SCHEMA, SKILL_ID, add_common, apply_common, default_output, die,
|
|
25
25
|
emit, ffmpeg_skill_version, ffskill, ffskill_cmd, info, refuse_existing,
|
|
26
26
|
require_ffmpeg_skill, shell_join, version)
|
|
27
|
-
from _captions import CaptionError, cues_from_words, read_captions, read_words
|
|
27
|
+
from _captions import CaptionError, cues_from_words, parse_chapters, read_captions, read_words, youtube_chapter_warnings
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
def build_parser() -> argparse.ArgumentParser:
|
|
@@ -39,6 +39,10 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
39
39
|
p.add_argument("--captions", help="SRT, WebVTT or JSON cue list to carry into the timeline (text kept as written)")
|
|
40
40
|
p.add_argument("--words", help="word timings from a speech engine (whisper JSON with word timestamps) for the "
|
|
41
41
|
"Karaoke composition; without --captions the cues are grouped from these words")
|
|
42
|
+
p.add_argument("--chapters", metavar="FILE|source",
|
|
43
|
+
help="chapter list, one `TIME TITLE` per line (YouTube's format, the same file ffmpeg-skill "
|
|
44
|
+
"metadata.py --chapters writes into the container), or `source` for the chapters already "
|
|
45
|
+
"in the input file; titles are kept as written")
|
|
42
46
|
p.add_argument("--beats", action="store_true", help="also measure the beat grid (scenes.py --beats)")
|
|
43
47
|
p.add_argument("--highlights", type=int, metavar="N",
|
|
44
48
|
help="also rank N highlight ranges (scenes.py --highlights; audio energy) for the Highlights composition")
|
|
@@ -202,6 +206,22 @@ def main() -> None:
|
|
|
202
206
|
keep = [[round(float(s), 3), round(float(e), 3)] for s, e in si.get("keep", []) if float(e) > float(s)]
|
|
203
207
|
speech = keep or speech
|
|
204
208
|
|
|
209
|
+
chapters: List[Dict[str, Any]] = []
|
|
210
|
+
if a.chapters == "source":
|
|
211
|
+
chapters = [{"start": round(float(c["start"] or 0), 3), "end": round(float(c["end"] or duration), 3),
|
|
212
|
+
"title": str(c["title"]).strip()}
|
|
213
|
+
for c in probe.get("chapters") or [] if str(c.get("title") or "").strip()]
|
|
214
|
+
if not chapters:
|
|
215
|
+
die(f"{src} has no titled chapters of its own (give a chapters file instead)", "input")
|
|
216
|
+
elif a.chapters:
|
|
217
|
+
chpath = Path(a.chapters).expanduser()
|
|
218
|
+
if not chpath.is_file():
|
|
219
|
+
die(f"chapters file not found: {chpath}", "input")
|
|
220
|
+
try:
|
|
221
|
+
chapters = parse_chapters(chpath.read_text(encoding="utf-8-sig"), duration)
|
|
222
|
+
except CaptionError as e:
|
|
223
|
+
die(f"{chpath}: {e}", "input")
|
|
224
|
+
|
|
205
225
|
v = video or {}
|
|
206
226
|
timeline: Dict[str, Any] = {
|
|
207
227
|
"schema": TIMELINE_SCHEMA,
|
|
@@ -226,7 +246,8 @@ def main() -> None:
|
|
|
226
246
|
"clips": clips,
|
|
227
247
|
"captions": captions,
|
|
228
248
|
"words": words,
|
|
229
|
-
"
|
|
249
|
+
"chapters": chapters,
|
|
250
|
+
"warnings": warnings_for(probe) + youtube_chapter_warnings(chapters) if chapters else warnings_for(probe),
|
|
230
251
|
}
|
|
231
252
|
if not video:
|
|
232
253
|
timeline["warnings"].append("audio-only source: width/height/fps default to 1920x1080 at 30 fps; "
|
|
@@ -243,7 +264,7 @@ def main() -> None:
|
|
|
243
264
|
"size": f"{timeline['source']['width']}x{timeline['source']['height']}",
|
|
244
265
|
"scenes": len(scenes), "silences": len(silences),
|
|
245
266
|
"speech_seconds": round(speech_total, 3), "peaks": len(peaks),
|
|
246
|
-
"captions": len(captions), "beats": bool(beats and beats.get("usable")),
|
|
267
|
+
"captions": len(captions), "chapters": len(chapters), "beats": bool(beats and beats.get("usable")),
|
|
247
268
|
"tempo_bpm": (beats or {}).get("tempo_bpm"), "highlights": len(highlights),
|
|
248
269
|
"clips": len(clips) or 1, "words": len(words)},
|
|
249
270
|
"warnings": timeline["warnings"]},
|
package/scripts/deliver.py
CHANGED
|
@@ -7,19 +7,33 @@ Examples:
|
|
|
7
7
|
python3 deliver.py captioned.mp4 --platform youtube # -> captioned_youtube.mp4 + check
|
|
8
8
|
python3 deliver.py jumpcut.mp4 --platform reels -o reel.mp4
|
|
9
9
|
python3 deliver.py master.mov --check-only --platform x # measure, change nothing
|
|
10
|
+
python3 deliver.py titled.mp4 --platform youtube --chapters chapters.txt # + chapter markers
|
|
10
11
|
"""
|
|
11
12
|
import argparse
|
|
12
13
|
import sys
|
|
13
14
|
from pathlib import Path
|
|
14
15
|
|
|
15
16
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
16
|
-
from
|
|
17
|
+
from _captions import parse_chapters
|
|
18
|
+
from _common import (STATE, add_common, apply_common, default_output, die, emit, ffskill, ffskill_cmd, info,
|
|
17
19
|
refuse_existing, require_ffmpeg_skill, shell_join)
|
|
18
20
|
|
|
19
21
|
# ffmpeg-skill's templates/*.json names (render.py --list-templates).
|
|
20
22
|
PLATFORMS = ["youtube", "youtube-shorts", "shorts", "reels", "tiktok", "x", "facebook", "linkedin", "podcast", "audiogram"]
|
|
21
23
|
|
|
22
24
|
|
|
25
|
+
def youtube_description(chapters_file: Path) -> str:
|
|
26
|
+
"""The chapter list as YouTube reads it from a description: `00:00 Title` per line."""
|
|
27
|
+
chapters = parse_chapters(chapters_file.read_text(encoding="utf-8-sig"), 0)
|
|
28
|
+
long = chapters[-1]["start"] >= 3600
|
|
29
|
+
|
|
30
|
+
def fmt(t: float) -> str:
|
|
31
|
+
t = int(t)
|
|
32
|
+
h, m, sec = t // 3600, t % 3600 // 60, t % 60
|
|
33
|
+
return f"{h}:{m:02d}:{sec:02d}" if long else f"{m:02d}:{sec:02d}"
|
|
34
|
+
return "\n".join(f"{fmt(c['start'])} {c['title']}" for c in chapters) + "\n"
|
|
35
|
+
|
|
36
|
+
|
|
23
37
|
def build_parser() -> argparse.ArgumentParser:
|
|
24
38
|
p = argparse.ArgumentParser(description=__doc__.split("\n\n")[0],
|
|
25
39
|
formatter_class=argparse.RawDescriptionHelpFormatter, epilog=__doc__)
|
|
@@ -27,6 +41,9 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
27
41
|
p.add_argument("--platform", choices=PLATFORMS, help="ffmpeg-skill delivery template to run")
|
|
28
42
|
p.add_argument("-o", "--output", help="deliverable path (default: <name>_<platform>.mp4)")
|
|
29
43
|
p.add_argument("--check-only", action="store_true", help="run check.py only, write nothing")
|
|
44
|
+
p.add_argument("--chapters", metavar="FILE",
|
|
45
|
+
help="also write these chapters (`TIME TITLE` per line) into the deliverable with ffmpeg-skill "
|
|
46
|
+
"metadata.py, plus the YouTube description block next to it (<name>_description.txt)")
|
|
30
47
|
add_common(p)
|
|
31
48
|
return p
|
|
32
49
|
|
|
@@ -40,20 +57,37 @@ def main() -> None:
|
|
|
40
57
|
require_ffmpeg_skill()
|
|
41
58
|
commands = []
|
|
42
59
|
|
|
60
|
+
if a.chapters:
|
|
61
|
+
if a.check_only or not a.platform:
|
|
62
|
+
die("--chapters writes into the deliverable: it needs --platform and no --check-only", "input")
|
|
63
|
+
if not Path(a.chapters).expanduser().is_file():
|
|
64
|
+
die(f"chapters file not found: {a.chapters}", "input")
|
|
43
65
|
target = src
|
|
44
66
|
if a.platform and not a.check_only:
|
|
45
67
|
out = Path(a.output).expanduser() if a.output else default_output(src, f"_{a.platform}", ".mp4")
|
|
46
68
|
refuse_existing(out)
|
|
47
|
-
|
|
48
|
-
|
|
69
|
+
templated = out.with_name(out.stem + ".nochapters" + out.suffix) if a.chapters else out
|
|
70
|
+
args = ["--template", a.platform, str(src), "-o", str(templated)]
|
|
71
|
+
if STATE.overwrite or a.chapters:
|
|
49
72
|
args.append("--overwrite")
|
|
73
|
+
description = out.with_name(out.stem + "_description.txt")
|
|
74
|
+
meta_args = [str(templated), "--chapters", str(Path(a.chapters).expanduser()), "-o", str(out)] + (
|
|
75
|
+
["--overwrite"] if STATE.overwrite else [])
|
|
50
76
|
if STATE.dry_run:
|
|
51
77
|
commands.append(shell_join(ffskill_cmd("render", args)))
|
|
78
|
+
if a.chapters:
|
|
79
|
+
commands.append(shell_join(ffskill_cmd("metadata", meta_args)))
|
|
52
80
|
commands.append(shell_join(ffskill_cmd("check", [str(out), "--platform", a.platform])))
|
|
53
81
|
emit({"output": str(out), "commands": commands}, f"would deliver {out}")
|
|
54
82
|
return
|
|
55
83
|
r = ffskill("render", args)
|
|
56
84
|
commands.append(r["_command"])
|
|
85
|
+
if a.chapters:
|
|
86
|
+
m = ffskill("metadata", meta_args)
|
|
87
|
+
commands.append(m["_command"])
|
|
88
|
+
templated.unlink(missing_ok=True)
|
|
89
|
+
description.write_text(youtube_description(Path(a.chapters).expanduser()), encoding="utf-8")
|
|
90
|
+
info(f"wrote {description} (paste into the YouTube description)")
|
|
57
91
|
target = out
|
|
58
92
|
|
|
59
93
|
check_args = [str(target)] + (["--platform", a.platform] if a.platform else [])
|
|
@@ -68,6 +102,7 @@ def main() -> None:
|
|
|
68
102
|
ok = bool(checks) and not failed
|
|
69
103
|
lines = [f"{c['status']:4} {c['check']}: {c.get('value')} (expected {c.get('expected')})" for c in checks]
|
|
70
104
|
emit({"status": "completed" if ok else "failed", "output": str(target) if target != src else None,
|
|
105
|
+
"description": str(target.with_name(target.stem + "_description.txt")) if a.chapters else None,
|
|
71
106
|
"checked": str(target), "platform": a.platform, "verified": ok, "checks": checks,
|
|
72
107
|
"failed": [c["check"] for c in failed], "warnings": [c["check"] for c in warns], "commands": commands,
|
|
73
108
|
"kind": None if ok else "failed",
|
package/scripts/pipeline.py
CHANGED
|
@@ -28,6 +28,9 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
28
28
|
p.add_argument("--project", required=True, help="Remotion project folder made by init.py")
|
|
29
29
|
p.add_argument("--comp", required=True, help=f"composition id ({', '.join(BUILTIN_COMPOSITIONS)}, or yours)")
|
|
30
30
|
p.add_argument("--captions", help="SRT / WebVTT / JSON cues for the timeline")
|
|
31
|
+
p.add_argument("--chapters", metavar="FILE|source",
|
|
32
|
+
help="chapters (`TIME TITLE` per line, or `source`): cards in Titled and, with --platform, chapter "
|
|
33
|
+
"markers in the deliverable")
|
|
31
34
|
p.add_argument("--options", help="JSON options file passed to the composition")
|
|
32
35
|
p.add_argument("--platform", choices=PLATFORMS, help="deliver with this ffmpeg-skill template and check it")
|
|
33
36
|
p.add_argument("--out-dir", help="where the timeline, render and deliverable go (default: next to the input)")
|
|
@@ -80,6 +83,7 @@ def main() -> None:
|
|
|
80
83
|
|
|
81
84
|
an_args = [*map(str, inputs), "-o", str(tl)] + (["--joined", str(out_dir / f"{stem}.mp4")] if len(inputs) > 1 else [])
|
|
82
85
|
an_args += (["--captions", a.captions] if a.captions else []) + (["--beats"] if a.beats else [])
|
|
86
|
+
an_args += ["--chapters", a.chapters] if a.chapters else []
|
|
83
87
|
analysis = step("measure", "analyze", an_args, steps)
|
|
84
88
|
if STATE.dry_run and not tl.exists():
|
|
85
89
|
emit({"output": None, "steps": steps,
|
|
@@ -104,7 +108,11 @@ def main() -> None:
|
|
|
104
108
|
|
|
105
109
|
delivered = None
|
|
106
110
|
if a.platform:
|
|
107
|
-
|
|
111
|
+
de_args = [str(render_out), "--platform", a.platform]
|
|
112
|
+
# chapter markers only when the picture keeps the source's clock (cuts would move every chapter)
|
|
113
|
+
if a.chapters and a.chapters != "source" and a.comp not in ("Jumpcut", "Highlights"):
|
|
114
|
+
de_args += ["--chapters", a.chapters]
|
|
115
|
+
delivered = step("deliver", "deliver", de_args, steps)
|
|
108
116
|
|
|
109
117
|
final = (delivered or {}).get("output") or rendered.get("output")
|
|
110
118
|
look = rendered.get("look")
|
package/scripts/render.py
CHANGED
|
@@ -45,12 +45,13 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
45
45
|
"with --keep-graphics the layer is kept for an editing app (Premiere, Resolve, Final Cut)")
|
|
46
46
|
p.add_argument("--keep-graphics", action="store_true", help="with --overlay: keep the transparent graphics .mov")
|
|
47
47
|
p.add_argument("--sparse", action="store_true",
|
|
48
|
-
help="overlay mode that draws only the frames where
|
|
48
|
+
help="overlay mode that draws only the frames where something shows (Captioned / Karaoke / "
|
|
49
|
+
"Titled) and "
|
|
49
50
|
"places each stretch at its time with ffmpeg-skill overlay.py --place: much faster on long "
|
|
50
51
|
"footage with gaps between captions. Falls back to the full-length layer (and says why) "
|
|
51
52
|
"when this ffmpeg-skill has no --place or the source does not start at 0")
|
|
52
53
|
p.add_argument("--merge-gap", type=float, default=2.0,
|
|
53
|
-
help="with --sparse:
|
|
54
|
+
help="with --sparse: graphics closer than this many seconds are drawn as one stretch (default 2)")
|
|
54
55
|
add_frame_args(p)
|
|
55
56
|
add_common(p)
|
|
56
57
|
return p
|
|
@@ -144,34 +145,34 @@ def ffskill_can_place() -> bool:
|
|
|
144
145
|
return "--place" in (proc.stdout or "")
|
|
145
146
|
|
|
146
147
|
|
|
147
|
-
def sparse_plan(timeline: Dict[str, Any], a: argparse.Namespace) -> Dict[str, Any]:
|
|
148
|
+
def sparse_plan(timeline: Dict[str, Any], options: Dict[str, Any], a: argparse.Namespace) -> Dict[str, Any]:
|
|
148
149
|
"""What --sparse will draw, or why it falls back to the full-length layer."""
|
|
149
150
|
src = timeline["source"]
|
|
150
151
|
fps = float(src["fps"])
|
|
151
152
|
total = expected_frames(a.comp, timeline) or 1
|
|
152
153
|
plan: Dict[str, Any] = {"used": False, "reason": None, "stretches": 0, "drawn_frames": total,
|
|
153
|
-
"source_frames": total, "timeline": None, "place": []}
|
|
154
|
-
stretches = _sparse.
|
|
154
|
+
"source_frames": total, "timeline": None, "options": None, "place": []}
|
|
155
|
+
stretches = _sparse.plan_stretches(a.comp, timeline, options, a.merge_gap)
|
|
155
156
|
start = None
|
|
156
157
|
if stretches and src.get("path") and not STATE.dry_run:
|
|
157
158
|
# the source as it is now (older timelines do not record where its first picture sits)
|
|
158
159
|
start = (ffskill("probe", [str(src["path"])], allow_fail=True).get("video") or {}).get("start_time")
|
|
159
160
|
if not stretches:
|
|
160
|
-
plan["reason"] = "no captions
|
|
161
|
+
plan["reason"] = "nothing to draw (no captions, lower thirds or scene titles)"
|
|
161
162
|
elif len(stretches) > _sparse.MAX_STRETCHES:
|
|
162
|
-
plan["reason"] = (f"{len(stretches)}
|
|
163
|
+
plan["reason"] = (f"{len(stretches)} stretches (over {_sparse.MAX_STRETCHES}); raise --merge-gap")
|
|
163
164
|
elif isinstance(start, (int, float)) and abs(start) > 0.5 / fps:
|
|
164
165
|
plan["reason"] = (f"the source's first picture is at {start:.3f} s, not 0: placed stretches would be "
|
|
165
166
|
"shifted by that much")
|
|
166
167
|
elif not ffskill_can_place():
|
|
167
168
|
plan["reason"] = "this ffmpeg-skill's overlay.py has no --place yet (update ffmpeg-skill)"
|
|
168
169
|
else:
|
|
169
|
-
packed, layout = _sparse.pack(timeline, stretches)
|
|
170
|
+
packed, packed_options, layout = _sparse.pack(timeline, stretches, options)
|
|
170
171
|
drawn = _sparse.packed_frames(layout)
|
|
171
172
|
if drawn >= total:
|
|
172
|
-
plan["reason"] = "
|
|
173
|
+
plan["reason"] = "the graphics cover the whole source: nothing to skip"
|
|
173
174
|
else:
|
|
174
|
-
plan.update(used=True, stretches=len(layout), drawn_frames=drawn, timeline=packed,
|
|
175
|
+
plan.update(used=True, stretches=len(layout), drawn_frames=drawn, timeline=packed, options=packed_options,
|
|
175
176
|
place=_sparse.place_args(layout, fps))
|
|
176
177
|
if plan["reason"]:
|
|
177
178
|
info(f"--sparse: drawing the full length instead ({plan['reason']})")
|
|
@@ -203,7 +204,7 @@ def main() -> None:
|
|
|
203
204
|
|
|
204
205
|
if a.sparse:
|
|
205
206
|
if a.comp not in _sparse.SPARSE_COMPOSITIONS:
|
|
206
|
-
die(f"--sparse draws
|
|
207
|
+
die(f"--sparse draws only the stretches where graphics show: {a.comp} is not one of "
|
|
207
208
|
f"{', '.join(_sparse.SPARSE_COMPOSITIONS)} (use --overlay for the full-length layer)", "input")
|
|
208
209
|
if a.merge_gap < 0:
|
|
209
210
|
die("--merge-gap cannot be negative", "input")
|
|
@@ -219,9 +220,10 @@ def main() -> None:
|
|
|
219
220
|
if not timeline["source"].get("has_video"):
|
|
220
221
|
die("--overlay needs a video source to composite onto", "input")
|
|
221
222
|
|
|
222
|
-
sparse = sparse_plan(timeline, a) if a.sparse else None
|
|
223
|
-
|
|
224
|
-
props_path, frame, font_note = prepare_props(project, a.comp,
|
|
223
|
+
sparse = sparse_plan(timeline, options, a) if a.sparse else None
|
|
224
|
+
used = bool(sparse and sparse["used"])
|
|
225
|
+
props_path, frame, font_note = prepare_props(project, a.comp, sparse["timeline"] if used else timeline,
|
|
226
|
+
sparse["options"] if used else options, a)
|
|
225
227
|
if font_note:
|
|
226
228
|
info(font_note)
|
|
227
229
|
graphics = output.with_name(output.stem + ".graphics.mov") if a.overlay else output
|
|
@@ -2,12 +2,13 @@ import React from "react";
|
|
|
2
2
|
import { AbsoluteFill, Sequence, interpolate, spring, useCurrentFrame, useVideoConfig } from "remotion";
|
|
3
3
|
import { SourceVideo } from "../lib/SourceVideo";
|
|
4
4
|
import { useStagedFont } from "../lib/useStagedFont";
|
|
5
|
-
import { Props, fontStack, outputFrame, resolveOptions, secToFrames, type Options } from "../timeline";
|
|
5
|
+
import { Props, chapterCardFrames, fontStack, outputFrame, resolveOptions, secToFrames, type Options } from "../timeline";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Titled: the source, full length, with lower thirds the user wrote (options.lowerThirds)
|
|
9
|
-
* title card at the start of each measured scene (options.sceneTitles, in scene order)
|
|
10
|
-
*
|
|
8
|
+
* Titled: the source, full length, with lower thirds the user wrote (options.lowerThirds), a
|
|
9
|
+
* title card at the start of each measured scene (options.sceneTitles, in scene order) and a
|
|
10
|
+
* chapter card at the start of each chapter (timeline.chapters, from analyze.py --chapters). The
|
|
11
|
+
* skill places text where the measurements say; it never writes the text.
|
|
11
12
|
*/
|
|
12
13
|
export const Titled: React.FC<Props> = (props) => {
|
|
13
14
|
const { timeline, options, font, overlay } = props;
|
|
@@ -30,6 +31,16 @@ export const Titled: React.FC<Props> = (props) => {
|
|
|
30
31
|
</Sequence>
|
|
31
32
|
);
|
|
32
33
|
})}
|
|
34
|
+
{o.chapterSeconds > 0
|
|
35
|
+
? (timeline.chapters ?? []).map((ch, i, all) => {
|
|
36
|
+
const [from, dur] = chapterCardFrames(ch, fps, o.chapterSeconds);
|
|
37
|
+
return (
|
|
38
|
+
<Sequence key={`c${i}`} from={from} durationInFrames={dur} name={`chapter ${i + 1}`} layout="none">
|
|
39
|
+
<ChapterCard title={ch.title} n={i + 1} of={all.length} len={dur} o={o} fontFamily={family} />
|
|
40
|
+
</Sequence>
|
|
41
|
+
);
|
|
42
|
+
})
|
|
43
|
+
: null}
|
|
33
44
|
{o.lowerThirds.map((lt, i) => {
|
|
34
45
|
const from = secToFrames(lt.start, fps);
|
|
35
46
|
const dur = Math.max(1, secToFrames(lt.end, fps) - from);
|
|
@@ -109,6 +120,70 @@ const LowerThirdCard: React.FC<{ text: string; sub?: string; len: number; o: Opt
|
|
|
109
120
|
);
|
|
110
121
|
};
|
|
111
122
|
|
|
123
|
+
/** Top-left chip: the chapter's place in the list and its title, as written. */
|
|
124
|
+
const ChapterCard: React.FC<{ title: string; n: number; of: number; len: number; o: Options; fontFamily: string }> = ({
|
|
125
|
+
title,
|
|
126
|
+
n,
|
|
127
|
+
of,
|
|
128
|
+
len,
|
|
129
|
+
o,
|
|
130
|
+
fontFamily,
|
|
131
|
+
}) => {
|
|
132
|
+
const { width, height } = useVideoConfig();
|
|
133
|
+
const { enter, exit } = useInOut(len);
|
|
134
|
+
const short = Math.min(width, height);
|
|
135
|
+
const size = Math.round(short * 0.042);
|
|
136
|
+
const portrait = height > width;
|
|
137
|
+
return (
|
|
138
|
+
<AbsoluteFill
|
|
139
|
+
style={{
|
|
140
|
+
justifyContent: "flex-start",
|
|
141
|
+
alignItems: "flex-start",
|
|
142
|
+
padding: `${height * (portrait ? 0.1 : 0.06)}px 0 0 ${width * 0.05}px`,
|
|
143
|
+
}}
|
|
144
|
+
>
|
|
145
|
+
<div
|
|
146
|
+
style={{
|
|
147
|
+
display: "flex",
|
|
148
|
+
alignItems: "stretch",
|
|
149
|
+
maxWidth: width * 0.8,
|
|
150
|
+
fontFamily,
|
|
151
|
+
opacity: exit,
|
|
152
|
+
transform: `translateX(${(1 - enter) * -width * 0.06}px)`,
|
|
153
|
+
}}
|
|
154
|
+
>
|
|
155
|
+
<div
|
|
156
|
+
style={{
|
|
157
|
+
background: o.accent,
|
|
158
|
+
color: "#111",
|
|
159
|
+
fontWeight: 800,
|
|
160
|
+
fontSize: Math.round(size * 0.7),
|
|
161
|
+
padding: `${size * 0.3}px ${size * 0.4}px`,
|
|
162
|
+
display: "flex",
|
|
163
|
+
alignItems: "center",
|
|
164
|
+
fontVariantNumeric: "tabular-nums",
|
|
165
|
+
}}
|
|
166
|
+
>
|
|
167
|
+
{n}/{of}
|
|
168
|
+
</div>
|
|
169
|
+
<div
|
|
170
|
+
style={{
|
|
171
|
+
background: "rgba(0,0,0,0.68)",
|
|
172
|
+
color: o.textColor,
|
|
173
|
+
fontWeight: 700,
|
|
174
|
+
fontSize: size,
|
|
175
|
+
padding: `${size * 0.22}px ${size * 0.55}px`,
|
|
176
|
+
whiteSpace: "pre-wrap",
|
|
177
|
+
textWrap: "balance",
|
|
178
|
+
}}
|
|
179
|
+
>
|
|
180
|
+
{title}
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
</AbsoluteFill>
|
|
184
|
+
);
|
|
185
|
+
};
|
|
186
|
+
|
|
112
187
|
const SceneCard: React.FC<{ text: string; len: number; o: Options; fontFamily: string }> = ({ text, len, o, fontFamily }) => {
|
|
113
188
|
const { width, height } = useVideoConfig();
|
|
114
189
|
const { enter, exit } = useInOut(len);
|
|
@@ -18,6 +18,7 @@ export type Source = {
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
export type Caption = { start: number; end: number; text: string };
|
|
21
|
+
export type Chapter = { start: number; end: number; title: string };
|
|
21
22
|
export type Beats = { times: number[]; tempo_bpm: number | null; confidence: number | null; usable: boolean };
|
|
22
23
|
export type Highlight = { start: number; end: number };
|
|
23
24
|
/** A lower third: text from the user (options), timing in source seconds. */
|
|
@@ -39,6 +40,8 @@ export type Timeline = {
|
|
|
39
40
|
captions: Caption[];
|
|
40
41
|
/** Word timings from a speech engine (analyze.py --words), text with the engine's own spacing. */
|
|
41
42
|
words?: Caption[];
|
|
43
|
+
/** Chapters from the user's list or the source's own markers (analyze.py --chapters); titles as written. */
|
|
44
|
+
chapters?: Chapter[];
|
|
42
45
|
warnings?: string[];
|
|
43
46
|
};
|
|
44
47
|
|
|
@@ -67,6 +70,8 @@ export type Options = {
|
|
|
67
70
|
title: string | null;
|
|
68
71
|
/** BeatMontage: cut the picture every N measured beats. */
|
|
69
72
|
beatsPerCut: number;
|
|
73
|
+
/** Titled: seconds a chapter card stays up at the start of each chapter (0 = no chapter cards). */
|
|
74
|
+
chapterSeconds: number;
|
|
70
75
|
};
|
|
71
76
|
|
|
72
77
|
export const DEFAULT_OPTIONS: Options = {
|
|
@@ -83,6 +88,13 @@ export const DEFAULT_OPTIONS: Options = {
|
|
|
83
88
|
sceneTitles: [],
|
|
84
89
|
title: null,
|
|
85
90
|
beatsPerCut: 4,
|
|
91
|
+
chapterSeconds: 4,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** [from, durationInFrames] of the card at the start of a chapter (Titled). render.py mirrors this. */
|
|
95
|
+
export const chapterCardFrames = (c: Chapter, fps: number, seconds: number): [number, number] => {
|
|
96
|
+
const from = secToFrames(c.start, fps);
|
|
97
|
+
return [from, Math.max(1, Math.min(secToFrames(c.end, fps), from + Math.round(fps * seconds)) - from)];
|
|
86
98
|
};
|
|
87
99
|
|
|
88
100
|
/**
|