remotion-ffmpeg-skill 0.7.0 → 0.8.1
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 +2 -1
- package/SKILL.md +2 -1
- package/package.json +1 -1
- package/references/scripts.md +6 -3
- 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 +20 -0
- package/scripts/analyze.py +24 -3
- package/scripts/deliver.py +43 -3
- package/scripts/pipeline.py +9 -1
- 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 |
|
package/SKILL.md
CHANGED
|
@@ -48,7 +48,8 @@ Changing the shape alone is not a reason: ffmpeg-skill's Reels / TikTok / Shorts
|
|
|
48
48
|
| "cut the silences / jump cut / tighten this talk" (with motion) | `analyze.py` → `render.py --comp Jumpcut` (captions re-timed if given) |
|
|
49
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) |
|
|
50
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) |
|
|
51
|
-
| "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 |
|
|
52
53
|
| "highlight reel / best moments" | `analyze.py --highlights N [--target S]` → `render.py --comp Highlights` (audio-energy ranking: candidates, say so) |
|
|
53
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) |
|
|
54
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` |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remotion-ffmpeg-skill",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
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
|
|
|
@@ -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
|
@@ -18,6 +18,8 @@ SPARSE_COMPOSITIONS = ("Captioned", "Karaoke", "Titled")
|
|
|
18
18
|
MAX_STRETCHES = 400
|
|
19
19
|
# Titled.tsx: a scene card lasts until the scene ends, at most this long.
|
|
20
20
|
SCENE_CARD_SECONDS = 2.5
|
|
21
|
+
# timeline.ts DEFAULT_OPTIONS.chapterSeconds
|
|
22
|
+
CHAPTER_SECONDS = 4.0
|
|
21
23
|
|
|
22
24
|
Layout = List[Tuple[int, int, int]] # (packed_first_frame, length_frames, source_first_frame)
|
|
23
25
|
|
|
@@ -28,6 +30,12 @@ def _scene_card(sc: Dict[str, Any], fps: float) -> Tuple[int, int]:
|
|
|
28
30
|
return s, s + max(1, min(sec_to_frames(sc["end"], fps), s + sec_to_frames(SCENE_CARD_SECONDS, fps)) - s)
|
|
29
31
|
|
|
30
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
|
+
|
|
31
39
|
def drawn_intervals(comp: str, timeline: Dict[str, Any], options: Optional[Dict[str, Any]] = None) -> List[Tuple[int, int]]:
|
|
32
40
|
"""[from, end) frames in which the composition draws anything (its Sequences)."""
|
|
33
41
|
fps = float(timeline["source"]["fps"])
|
|
@@ -45,6 +53,9 @@ def drawn_intervals(comp: str, timeline: Dict[str, Any], options: Optional[Dict[
|
|
|
45
53
|
for lt in o.get("lowerThirds") or []:
|
|
46
54
|
s = sec_to_frames(lt["start"], fps)
|
|
47
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 []]
|
|
48
59
|
return out
|
|
49
60
|
|
|
50
61
|
|
|
@@ -120,6 +131,15 @@ def pack(timeline: Dict[str, Any], spans: List[Tuple[int, int]],
|
|
|
120
131
|
continue
|
|
121
132
|
scenes.append({"start": 0.0, "end": 1.0 / fps})
|
|
122
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 []
|
|
123
143
|
# nothing else is drawn; measurements on the source clock would only mislead
|
|
124
144
|
for key in ("silences", "speech", "peaks", "highlights", "clips"):
|
|
125
145
|
tl[key] = []
|
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,10 @@ 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("--brand", help="ffmpeg-skill brand.json for the template (its logo, safe margins, loudness)")
|
|
45
|
+
p.add_argument("--chapters", metavar="FILE",
|
|
46
|
+
help="also write these chapters (`TIME TITLE` per line) into the deliverable with ffmpeg-skill "
|
|
47
|
+
"metadata.py, plus the YouTube description block next to it (<name>_description.txt)")
|
|
30
48
|
add_common(p)
|
|
31
49
|
return p
|
|
32
50
|
|
|
@@ -40,20 +58,41 @@ def main() -> None:
|
|
|
40
58
|
require_ffmpeg_skill()
|
|
41
59
|
commands = []
|
|
42
60
|
|
|
61
|
+
if a.chapters:
|
|
62
|
+
if a.check_only or not a.platform:
|
|
63
|
+
die("--chapters writes into the deliverable: it needs --platform and no --check-only", "input")
|
|
64
|
+
if not Path(a.chapters).expanduser().is_file():
|
|
65
|
+
die(f"chapters file not found: {a.chapters}", "input")
|
|
43
66
|
target = src
|
|
44
67
|
if a.platform and not a.check_only:
|
|
45
68
|
out = Path(a.output).expanduser() if a.output else default_output(src, f"_{a.platform}", ".mp4")
|
|
46
69
|
refuse_existing(out)
|
|
47
|
-
|
|
48
|
-
|
|
70
|
+
templated = out.with_name(out.stem + ".nochapters" + out.suffix) if a.chapters else out
|
|
71
|
+
args = ["--template", a.platform, str(src), "-o", str(templated)]
|
|
72
|
+
if a.brand:
|
|
73
|
+
if not Path(a.brand).expanduser().is_file():
|
|
74
|
+
die(f"brand file not found: {a.brand}", "input")
|
|
75
|
+
args += ["--brand", str(Path(a.brand).expanduser().resolve())]
|
|
76
|
+
if STATE.overwrite or a.chapters:
|
|
49
77
|
args.append("--overwrite")
|
|
78
|
+
description = out.with_name(out.stem + "_description.txt")
|
|
79
|
+
meta_args = ([str(templated), "--chapters", str(Path(a.chapters).expanduser()), "-o", str(out)]
|
|
80
|
+
+ (["--overwrite"] if STATE.overwrite else [])) if a.chapters else []
|
|
50
81
|
if STATE.dry_run:
|
|
51
82
|
commands.append(shell_join(ffskill_cmd("render", args)))
|
|
83
|
+
if a.chapters:
|
|
84
|
+
commands.append(shell_join(ffskill_cmd("metadata", meta_args)))
|
|
52
85
|
commands.append(shell_join(ffskill_cmd("check", [str(out), "--platform", a.platform])))
|
|
53
86
|
emit({"output": str(out), "commands": commands}, f"would deliver {out}")
|
|
54
87
|
return
|
|
55
88
|
r = ffskill("render", args)
|
|
56
89
|
commands.append(r["_command"])
|
|
90
|
+
if a.chapters:
|
|
91
|
+
m = ffskill("metadata", meta_args)
|
|
92
|
+
commands.append(m["_command"])
|
|
93
|
+
templated.unlink(missing_ok=True)
|
|
94
|
+
description.write_text(youtube_description(Path(a.chapters).expanduser()), encoding="utf-8")
|
|
95
|
+
info(f"wrote {description} (paste into the YouTube description)")
|
|
57
96
|
target = out
|
|
58
97
|
|
|
59
98
|
check_args = [str(target)] + (["--platform", a.platform] if a.platform else [])
|
|
@@ -68,6 +107,7 @@ def main() -> None:
|
|
|
68
107
|
ok = bool(checks) and not failed
|
|
69
108
|
lines = [f"{c['status']:4} {c['check']}: {c.get('value')} (expected {c.get('expected')})" for c in checks]
|
|
70
109
|
emit({"status": "completed" if ok else "failed", "output": str(target) if target != src else None,
|
|
110
|
+
"description": str(target.with_name(target.stem + "_description.txt")) if a.chapters else None,
|
|
71
111
|
"checked": str(target), "platform": a.platform, "verified": ok, "checks": checks,
|
|
72
112
|
"failed": [c["check"] for c in failed], "warnings": [c["check"] for c in warns], "commands": commands,
|
|
73
113
|
"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")
|
|
@@ -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
|
/**
|