remotion-ffmpeg-skill 0.8.1 → 0.10.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 -0
- package/SKILL.md +2 -0
- package/package.json +1 -1
- package/references/scripts.md +11 -3
- package/references/timeline.md +6 -0
- package/scripts/_common.py +90 -2
- package/scripts/analyze.py +44 -2
- package/scripts/deliver.py +26 -2
- package/scripts/init.py +2 -2
- package/scripts/pipeline.py +3 -2
- package/scripts/render.py +4 -4
- package/scripts/still.py +2 -2
- package/templates/remotion-project/src/Root.tsx +2 -0
- package/templates/remotion-project/src/compositions/Pip.tsx +65 -0
- package/templates/remotion-project/src/timeline.ts +35 -0
package/README.md
CHANGED
|
@@ -85,6 +85,7 @@ Tool names and input schemas come from the machine-readable contract (`npx remot
|
|
|
85
85
|
| `Highlights` | sum of ranked highlights | ffmpeg-skill's audio-energy highlights back to back, counter, title |
|
|
86
86
|
| `BeatMontage` | source duration | audio unbroken, picture cuts on the measured beat grid |
|
|
87
87
|
| `Karaoke` | source duration | words light up at the times a local speech engine measured |
|
|
88
|
+
| `Pip` | source duration | a second recording (camera) in a corner, synced by the offset measured between the two audio tracks; captions on top |
|
|
88
89
|
|
|
89
90
|
**Any shape:** `--aspect 9:16 | 1:1 | 4:5 | 16:9` with `--fit blur | contain | cover`; `pipeline.py --platform reels` picks 9:16 from ffmpeg-skill's own template so nothing gets cropped on delivery.
|
|
90
91
|
|
|
@@ -94,6 +95,8 @@ Tool names and input schemas come from the machine-readable contract (`npx remot
|
|
|
94
95
|
|
|
95
96
|
**A layer for your editor:** `--overlay --keep-graphics` renders the graphics alone as transparent ProRes 4444 and composites it over the untouched source with ffmpeg-skill — keep the `.mov` for Premiere, Resolve or Final Cut.
|
|
96
97
|
|
|
98
|
+
**One brand file for both skills:** `--brand brand.json` reads ffmpeg-skill's own brand file — colours, caption colour, font, font file — and on delivery the template places its logo, so graphics drawn here match what ffmpeg-skill draws.
|
|
99
|
+
|
|
97
100
|
Colours, font, caption size, zoom and pulse strength are options (`--options look.json`); the timeline format and every option are in [`references/timeline.md`](references/timeline.md). Add your own composition to the generated project and render it with `--comp YourId`.
|
|
98
101
|
|
|
99
102
|
### What render.py verifies
|
package/SKILL.md
CHANGED
|
@@ -56,8 +56,10 @@ Changing the shape alone is not a reason: ffmpeg-skill's Reels / TikTok / Shorts
|
|
|
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
|
+
| "put my camera in the corner" / picture-in-picture (screen recording + camera) | `analyze.py screen.mp4 --pip camera.mp4 [--captions F]` (the offset is measured from both audio tracks by ffmpeg-skill sync.py; a camera without usable audio: `--pip-offset SECONDS`) → `render.py --comp Pip` (`pipCorner`, `pipSize`, `pipShape`, `pipAudio`). Low confidence is a warning: check a still before rendering |
|
|
59
60
|
| 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
61
|
| "change colour / font / caption size / zoom" | an `--options` JSON (`references/timeline.md`), re-render |
|
|
62
|
+
| "use our brand" / a `brand.json` (ffmpeg-skill's format) | `--brand brand.json` on render / still / pipeline: its colours, caption colour, font and font file set the look (an `--options` file wins key by key); `deliver.py` / `pipeline.py --brand` places its logo with the template |
|
|
61
63
|
| 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
64
|
| "preview" / "show me a frame" | `still.py` |
|
|
63
65
|
| a new kind of graphic | add a composition to `src/` of the project that reads `Props` from `src/timeline.ts`; render with `--comp YourId` (render.py then reports measured numbers without a built-in expectation) |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remotion-ffmpeg-skill",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.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
|
@@ -26,6 +26,9 @@ Measure a source with ffmpeg-skill and write timeline.json (+ captions from a fi
|
|
|
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
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 |
|
|
29
|
+
| `--pip` | string | | a second recording (camera) for the Pip composition: picture-in-picture over the source. The offset between the two is measured from their audio with ffmpeg-skill sync.py |
|
|
30
|
+
| `--pip-offset` | number | | with --pip: the camera starts this many seconds after the source (negative: before), instead of measuring it -- for a camera without usable audio |
|
|
31
|
+
| `--pip-max-offset` | number | `30.0` | with --pip: largest offset sync.py searches, in seconds (default 30) |
|
|
29
32
|
| `--beats` | boolean | | also measure the beat grid (scenes.py --beats) |
|
|
30
33
|
| `--highlights` | integer | | also rank N highlight ranges (scenes.py --highlights; audio energy) for the Highlights composition |
|
|
31
34
|
| `--target` | number | | with --highlights: total length the picks add up to |
|
|
@@ -72,7 +75,7 @@ Render single frames as PNG to check the look before a full render.
|
|
|
72
75
|
| Argument | Type | Default | Meaning |
|
|
73
76
|
|---|---|---|---|
|
|
74
77
|
| `--project (required)` | string | | Remotion project folder made by init.py |
|
|
75
|
-
| `--comp (required)` | string | | composition id (Captioned, Jumpcut, PeakPulse, Titled, Highlights, BeatMontage, Karaoke, or yours) |
|
|
78
|
+
| `--comp (required)` | string | | composition id (Captioned, Jumpcut, PeakPulse, Titled, Highlights, BeatMontage, Karaoke, Pip, or yours) |
|
|
76
79
|
| `--timeline (required)` | string | | timeline.json written by analyze.py |
|
|
77
80
|
| `--options` | string | | JSON object of look-and-feel options |
|
|
78
81
|
| `--at` | number, repeatable | | time in seconds (repeatable) |
|
|
@@ -82,6 +85,7 @@ Render single frames as PNG to check the look before a full render.
|
|
|
82
85
|
| `--width` | integer | | output width in px (default: keep the source's short side) |
|
|
83
86
|
| `--fit` | string: blur / contain / cover | | how the source fills another shape: blur (default when the shape changes), contain (bars) or cover (crop) |
|
|
84
87
|
| `--font-file` | string | | caption font file (.ttf/.otf/.ttc/.woff2), staged into the project |
|
|
88
|
+
| `--brand` | string | | ffmpeg-skill brand.json: its colours, caption colour, font and font file set the look (an --options file still wins key by key) |
|
|
85
89
|
| `--no-auto-font` | boolean | | don't stage the CJK font ffmpeg-skill finds for Japanese/Chinese/Korean captions |
|
|
86
90
|
|
|
87
91
|
--json result (besides `status`, `dry_run`, `output`): `outputs` (list[str] (PNG paths)), `frames` (list[int]), `commands` (list[str]), `verified` (bool), `frame` (object|null {width, height, fit}), `font` (str|null)
|
|
@@ -101,7 +105,7 @@ Render a composition from a timeline, verify it (frames, fps, size, audio) and w
|
|
|
101
105
|
| Argument | Type | Default | Meaning |
|
|
102
106
|
|---|---|---|---|
|
|
103
107
|
| `--project (required)` | string | | Remotion project folder made by init.py |
|
|
104
|
-
| `--comp (required)` | string | | composition id (Captioned, Jumpcut, PeakPulse, Titled, Highlights, BeatMontage, Karaoke, or one you added) |
|
|
108
|
+
| `--comp (required)` | string | | composition id (Captioned, Jumpcut, PeakPulse, Titled, Highlights, BeatMontage, Karaoke, Pip, or one you added) |
|
|
105
109
|
| `--timeline (required)` | string | | timeline.json written by analyze.py |
|
|
106
110
|
| `--options` | string | | JSON object of look-and-feel options (see references/timeline.md) |
|
|
107
111
|
| `--output` | string | | output file (default: <source>_<comp>.mp4, .mov for prores) |
|
|
@@ -119,6 +123,7 @@ Render a composition from a timeline, verify it (frames, fps, size, audio) and w
|
|
|
119
123
|
| `--width` | integer | | output width in px (default: keep the source's short side) |
|
|
120
124
|
| `--fit` | string: blur / contain / cover | | how the source fills another shape: blur (default when the shape changes), contain (bars) or cover (crop) |
|
|
121
125
|
| `--font-file` | string | | caption font file (.ttf/.otf/.ttc/.woff2), staged into the project |
|
|
126
|
+
| `--brand` | string | | ffmpeg-skill brand.json: its colours, caption colour, font and font file set the look (an --options file still wins key by key) |
|
|
122
127
|
| `--no-auto-font` | boolean | | don't stage the CJK font ffmpeg-skill finds for Japanese/Chinese/Korean captions |
|
|
123
128
|
|
|
124
129
|
--json result (besides `status`, `dry_run`, `output`): `verified` (bool), `verification` (list[{check, status, value, expected}]), `commands` (list[str]), `look` (str|null (contact sheet PNG)), `look_error` (str|null), `summary` (str), `frame` (object|null), `font` (str|null), `mode` (full|overlay), `graphics` (str|null (kept ProRes 4444 layer)), `sparse` (null|{used, reason, stretches, drawn_frames, source_frames} (--sparse)), `kind` (null|failed), `error` (null|str (which verification rows failed))
|
|
@@ -141,6 +146,8 @@ Run an ffmpeg-skill delivery template (YouTube, Reels, ...) and its compliance c
|
|
|
141
146
|
| `--platform` | string: youtube / youtube-shorts / shorts / reels / tiktok / x / facebook / linkedin / podcast / audiogram | | ffmpeg-skill delivery template to run |
|
|
142
147
|
| `--output` | string | | deliverable path (default: <name>_<platform>.mp4) |
|
|
143
148
|
| `--check-only` | boolean | | run check.py only, write nothing |
|
|
149
|
+
| `--brand` | string | | ffmpeg-skill brand.json for the template (its logo, safe margins, loudness) |
|
|
150
|
+
| `--logo` | string | | logo image the template places (default: the brand file's logo) |
|
|
144
151
|
| `--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) |
|
|
145
152
|
|
|
146
153
|
--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)
|
|
@@ -161,10 +168,11 @@ analyze -> render -> deliver in one call, stopping at the first failed step.
|
|
|
161
168
|
|---|---|---|---|
|
|
162
169
|
| `input` | string, repeatable | | source video; several are joined in order (ffmpeg-skill join.py) first |
|
|
163
170
|
| `--project (required)` | string | | Remotion project folder made by init.py |
|
|
164
|
-
| `--comp (required)` | string | | composition id (Captioned, Jumpcut, PeakPulse, Titled, Highlights, BeatMontage, Karaoke, or yours) |
|
|
171
|
+
| `--comp (required)` | string | | composition id (Captioned, Jumpcut, PeakPulse, Titled, Highlights, BeatMontage, Karaoke, Pip, or yours) |
|
|
165
172
|
| `--captions` | string | | SRT / WebVTT / JSON cues for the timeline |
|
|
166
173
|
| `--chapters` | string | | chapters (`TIME TITLE` per line, or `source`): cards in Titled and, with --platform, chapter markers in the deliverable |
|
|
167
174
|
| `--options` | string | | JSON options file passed to the composition |
|
|
175
|
+
| `--brand` | string | | ffmpeg-skill brand.json: the look of the graphics and, on delivery, the logo |
|
|
168
176
|
| `--platform` | string: youtube / youtube-shorts / shorts / reels / tiktok / x / facebook / linkedin / podcast / audiogram | | deliver with this ffmpeg-skill template and check it |
|
|
169
177
|
| `--out-dir` | string | | where the timeline, render and deliverable go (default: next to the input) |
|
|
170
178
|
| `--beats` | boolean | | measure the beat grid too |
|
package/references/timeline.md
CHANGED
|
@@ -26,6 +26,7 @@ props (`{ "timeline": ..., "options": ..., "frame": ..., "font": ..., "overlay":
|
|
|
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
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 |
|
|
29
|
+
| `pip` | `{path, name, duration, width, height, fps, offset, confidence, measured}` or null | `--pip CAMERA` (offset from ffmpeg-skill sync.py over both audio tracks) or `--pip-offset` | offset = seconds after the source's start at which the camera's first frame belongs (negative: the camera started first) |
|
|
29
30
|
| `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 |
|
|
30
31
|
| `warnings` | `[string]` | analyze.py | VFR, HDR, rotation, odd frame rate |
|
|
31
32
|
|
|
@@ -43,6 +44,7 @@ composition exactly.
|
|
|
43
44
|
| `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) |
|
|
44
45
|
| `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 |
|
|
45
46
|
| `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 |
|
|
47
|
+
| `Pip` | source duration | the source with `pip` (a camera) in a corner while the camera has pictures, synced by `pip.offset`; captions on top as in Captioned |
|
|
46
48
|
| `BeatMontage` | source duration | audio unbroken; the picture cuts every `beatsPerCut` measured beats, cycling through highlights (or scenes); no usable grid → cuts on scene changes |
|
|
47
49
|
|
|
48
50
|
## Options (`--options look.json`)
|
|
@@ -64,6 +66,10 @@ Every key is optional.
|
|
|
64
66
|
| `sceneTitles` | `[]` | Titled: one title per measured scene, in order |
|
|
65
67
|
| `title` | `null` | Highlights: title over the first highlight |
|
|
66
68
|
| `beatsPerCut` | `4` | BeatMontage: measured beats per shot |
|
|
69
|
+
| `pipCorner` | `"bottom-right"` | Pip: `top-left`, `top-right`, `bottom-left`, `bottom-right` |
|
|
70
|
+
| `pipSize` | `0.28` | Pip: camera width as a fraction of the frame width (circle: of the short side), 0.05–0.6 |
|
|
71
|
+
| `pipShape` | `"rounded"` | Pip: `rounded` or `circle` |
|
|
72
|
+
| `pipAudio` | `false` | Pip: also play the camera's own audio |
|
|
67
73
|
| `chapterSeconds` | `4` | Titled: how long a chapter card stays up (cut short by the next chapter; 0 = none) |
|
|
68
74
|
|
|
69
75
|
Unknown keys and wrong types are refused by render.py / still.py before anything renders.
|
package/scripts/_common.py
CHANGED
|
@@ -18,6 +18,7 @@ import hashlib
|
|
|
18
18
|
import json
|
|
19
19
|
import math
|
|
20
20
|
import os
|
|
21
|
+
import re
|
|
21
22
|
import shutil
|
|
22
23
|
import subprocess
|
|
23
24
|
import sys
|
|
@@ -221,6 +222,9 @@ def validate_timeline(t: Any) -> List[str]:
|
|
|
221
222
|
v = src.get(k)
|
|
222
223
|
if not isinstance(v, (int, float)) or v <= 0:
|
|
223
224
|
p.append(f"source.{k} must be a positive number")
|
|
225
|
+
if t.get("pip") is not None and not (isinstance(t["pip"], dict) and isinstance(t["pip"].get("offset"), (int, float))
|
|
226
|
+
and t["pip"].get("path")):
|
|
227
|
+
p.append("pip must be {path, offset, duration, ...} (analyze.py --pip)")
|
|
224
228
|
for k in ("scenes", "silences", "speech", "peaks", "captions", "highlights", "words", "chapters"):
|
|
225
229
|
if not isinstance(t.get(k, []), list):
|
|
226
230
|
p.append(f"{k} must be a list")
|
|
@@ -250,7 +254,7 @@ def expected_frames(comp: str, t: Dict[str, Any]) -> Optional[int]:
|
|
|
250
254
|
and render.py then only reports the measured numbers.
|
|
251
255
|
"""
|
|
252
256
|
fps = float(t["source"]["fps"])
|
|
253
|
-
if comp in ("Captioned", "PeakPulse", "Titled", "BeatMontage", "Karaoke"):
|
|
257
|
+
if comp in ("Captioned", "PeakPulse", "Titled", "BeatMontage", "Karaoke", "Pip"):
|
|
254
258
|
return max(1, sec_to_frames(float(t["source"]["duration"]), fps))
|
|
255
259
|
if comp in ("Jumpcut", "Highlights"):
|
|
256
260
|
if comp == "Jumpcut":
|
|
@@ -264,7 +268,7 @@ def expected_frames(comp: str, t: Dict[str, Any]) -> Optional[int]:
|
|
|
264
268
|
|
|
265
269
|
# ---------------------------------------------------------------- Remotion project
|
|
266
270
|
|
|
267
|
-
BUILTIN_COMPOSITIONS = ("Captioned", "Jumpcut", "PeakPulse", "Titled", "Highlights", "BeatMontage", "Karaoke")
|
|
271
|
+
BUILTIN_COMPOSITIONS = ("Captioned", "Jumpcut", "PeakPulse", "Titled", "Highlights", "BeatMontage", "Karaoke", "Pip")
|
|
268
272
|
|
|
269
273
|
|
|
270
274
|
def remotion_bin(project: Path) -> Path:
|
|
@@ -453,6 +457,8 @@ def write_props(project: Path, comp: str, timeline: Dict[str, Any], options: Dic
|
|
|
453
457
|
src = t["source"].get("path")
|
|
454
458
|
has_media = t["source"].get("has_video", True) or t["source"].get("has_audio", False)
|
|
455
459
|
t["source"]["src"] = stage_source(project, src) if src and has_media and not overlay else None
|
|
460
|
+
if t.get("pip") and comp == "Pip":
|
|
461
|
+
t["pip"]["src"] = stage_source(project, t["pip"]["path"])
|
|
456
462
|
props = {"timeline": t, "options": options, "frame": frame, "font": font, "overlay": overlay}
|
|
457
463
|
# Named by content: two renders running at once (different sources, shapes or options) never
|
|
458
464
|
# overwrite each other's props, and identical props share one file harmlessly.
|
|
@@ -472,6 +478,8 @@ def add_frame_args(p: argparse.ArgumentParser) -> None:
|
|
|
472
478
|
g.add_argument("--fit", choices=FITS, help="how the source fills another shape: blur (default when the shape "
|
|
473
479
|
"changes), contain (bars) or cover (crop)")
|
|
474
480
|
g.add_argument("--font-file", help="caption font file (.ttf/.otf/.ttc/.woff2), staged into the project")
|
|
481
|
+
g.add_argument("--brand", help="ffmpeg-skill brand.json: its colours, caption colour, font and font file set "
|
|
482
|
+
"the look (an --options file still wins key by key)")
|
|
475
483
|
g.add_argument("--no-auto-font", action="store_true",
|
|
476
484
|
help="don't stage the CJK font ffmpeg-skill finds for Japanese/Chinese/Korean captions")
|
|
477
485
|
|
|
@@ -487,6 +495,78 @@ def prepare_props(project: Path, comp: str, timeline: Dict[str, Any], options: D
|
|
|
487
495
|
return props_path, frame, note
|
|
488
496
|
|
|
489
497
|
|
|
498
|
+
# Mirrors DEFAULT_OPTIONS.fontFamily in src/timeline.ts: a brand font goes in front of it, so CJK
|
|
499
|
+
# and other scripts still fall back to a font that has them.
|
|
500
|
+
DEFAULT_FONT_STACK = ("'Noto Sans JP', 'Hiragino Sans', 'Yu Gothic', 'Noto Sans', 'Helvetica Neue', Arial, "
|
|
501
|
+
"sans-serif")
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
def _hex_colour(v: Any, where: str) -> str:
|
|
505
|
+
s = str(v).strip()
|
|
506
|
+
for prefix in ("#", "0x", "0X", "&H"):
|
|
507
|
+
if s.startswith(prefix):
|
|
508
|
+
s = s[len(prefix):]
|
|
509
|
+
if not re.fullmatch(r"[0-9a-fA-F]{6}", s):
|
|
510
|
+
die(f"{where}: {v!r} is not a colour (use RRGGBB, as ffmpeg-skill's brand.json does)", "input")
|
|
511
|
+
return "#" + s.upper()
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
def brand_look(path: str) -> Tuple[Dict[str, Any], Optional[str], List[str]]:
|
|
515
|
+
"""ffmpeg-skill brand.json -> (options, font file, notes). Only what the file itself states is
|
|
516
|
+
used: ffmpeg-skill fills in defaults for the rest, and those are not the user's choice."""
|
|
517
|
+
bp = Path(path).expanduser()
|
|
518
|
+
if not bp.is_file():
|
|
519
|
+
die(f"brand file not found: {bp}", "input")
|
|
520
|
+
try:
|
|
521
|
+
data = json.loads(bp.read_text(encoding="utf-8"))
|
|
522
|
+
except ValueError as e:
|
|
523
|
+
die(f"{bp} is not valid JSON: {e}", "input")
|
|
524
|
+
if not isinstance(data, dict):
|
|
525
|
+
die(f"{bp} must hold a JSON object", "input")
|
|
526
|
+
opts: Dict[str, Any] = {}
|
|
527
|
+
colours = data.get("colors") or data.get("colours") or {}
|
|
528
|
+
if colours.get("primary"):
|
|
529
|
+
opts["accent"] = _hex_colour(colours["primary"], f"{bp.name} colors.primary")
|
|
530
|
+
if colours.get("text"):
|
|
531
|
+
opts["textColor"] = _hex_colour(colours["text"], f"{bp.name} colors.text")
|
|
532
|
+
# the caption block, with styles.caption winning (ffmpeg-skill's brand_caption_style)
|
|
533
|
+
style = dict(data.get("caption") or {})
|
|
534
|
+
style.update((data.get("styles") or {}).get("caption") or {})
|
|
535
|
+
colour = style.get("color", style.get("colour"))
|
|
536
|
+
if colour:
|
|
537
|
+
opts["textColor"] = _hex_colour(colour, f"{bp.name} caption colour")
|
|
538
|
+
font = style.get("font") or data.get("font")
|
|
539
|
+
if font:
|
|
540
|
+
opts["fontFamily"] = f"'{str(font).strip()}', {DEFAULT_FONT_STACK}"
|
|
541
|
+
font_file = data.get("font_file")
|
|
542
|
+
if font_file:
|
|
543
|
+
ff = Path(font_file).expanduser()
|
|
544
|
+
font_file = str(ff if ff.is_absolute() else (bp.resolve().parent / ff))
|
|
545
|
+
if not Path(font_file).is_file():
|
|
546
|
+
die(f"{bp.name} font_file not found: {font_file}", "input")
|
|
547
|
+
notes = []
|
|
548
|
+
if data.get("logo"):
|
|
549
|
+
notes.append("brand logo: placed on delivery (deliver.py / pipeline.py --brand), not in the composition")
|
|
550
|
+
unused = [k for k in ("size", "position", "animate", "box", "outline") if k in style]
|
|
551
|
+
if unused:
|
|
552
|
+
notes.append("brand caption " + ", ".join(unused) + ": ffmpeg-skill caption settings, not used by the "
|
|
553
|
+
"compositions (captionSize / captionMargin in --options set those)")
|
|
554
|
+
return opts, font_file, notes
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
def load_look(a: argparse.Namespace) -> Dict[str, Any]:
|
|
558
|
+
"""Options for render.py / still.py: the brand file's look, then --options over it."""
|
|
559
|
+
options = load_options(a.options)
|
|
560
|
+
if not getattr(a, "brand", None):
|
|
561
|
+
return options
|
|
562
|
+
b, font_file, notes = brand_look(a.brand)
|
|
563
|
+
for n in notes:
|
|
564
|
+
info(n)
|
|
565
|
+
if font_file and not a.font_file:
|
|
566
|
+
a.font_file = font_file
|
|
567
|
+
return {**b, **options}
|
|
568
|
+
|
|
569
|
+
|
|
490
570
|
def load_options(path: Optional[str]) -> Dict[str, Any]:
|
|
491
571
|
if not path:
|
|
492
572
|
return {}
|
|
@@ -511,6 +591,7 @@ _OPTION_TYPES: Dict[str, Any] = {
|
|
|
511
591
|
"captionMargin": (int, float, type(None)), "punchIn": (int, float), "pulse": (int, float),
|
|
512
592
|
"progressBar": bool, "driver": str, "lowerThirds": list, "sceneTitles": list,
|
|
513
593
|
"title": (str, type(None)), "beatsPerCut": int, "chapterSeconds": (int, float),
|
|
594
|
+
"pipCorner": str, "pipSize": (int, float), "pipShape": str, "pipAudio": bool,
|
|
514
595
|
}
|
|
515
596
|
|
|
516
597
|
|
|
@@ -536,6 +617,13 @@ def validate_options(o: Dict[str, Any]) -> List[str]:
|
|
|
536
617
|
if isinstance(o.get("chapterSeconds"), (int, float)) and not isinstance(o["chapterSeconds"], bool) \
|
|
537
618
|
and o["chapterSeconds"] < 0:
|
|
538
619
|
p.append("chapterSeconds cannot be negative")
|
|
620
|
+
if "pipCorner" in o and o["pipCorner"] not in ("top-left", "top-right", "bottom-left", "bottom-right"):
|
|
621
|
+
p.append("pipCorner must be top-left, top-right, bottom-left or bottom-right")
|
|
622
|
+
if "pipShape" in o and o["pipShape"] not in ("rounded", "circle"):
|
|
623
|
+
p.append("pipShape must be rounded or circle")
|
|
624
|
+
if isinstance(o.get("pipSize"), (int, float)) and not isinstance(o["pipSize"], bool) \
|
|
625
|
+
and not 0.05 <= o["pipSize"] <= 0.6:
|
|
626
|
+
p.append("pipSize must be between 0.05 and 0.6 (a fraction of the frame width)")
|
|
539
627
|
if any(not isinstance(s, str) for s in (o.get("sceneTitles") or [])):
|
|
540
628
|
p.append("sceneTitles must be a list of strings")
|
|
541
629
|
return p
|
package/scripts/analyze.py
CHANGED
|
@@ -18,7 +18,7 @@ Examples:
|
|
|
18
18
|
import argparse
|
|
19
19
|
import sys
|
|
20
20
|
from pathlib import Path
|
|
21
|
-
from typing import Any, Dict, List
|
|
21
|
+
from typing import Any, Dict, List, Optional
|
|
22
22
|
|
|
23
23
|
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,
|
|
@@ -43,6 +43,14 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
43
43
|
help="chapter list, one `TIME TITLE` per line (YouTube's format, the same file ffmpeg-skill "
|
|
44
44
|
"metadata.py --chapters writes into the container), or `source` for the chapters already "
|
|
45
45
|
"in the input file; titles are kept as written")
|
|
46
|
+
p.add_argument("--pip", metavar="CAMERA",
|
|
47
|
+
help="a second recording (camera) for the Pip composition: picture-in-picture over the source. "
|
|
48
|
+
"The offset between the two is measured from their audio with ffmpeg-skill sync.py")
|
|
49
|
+
p.add_argument("--pip-offset", type=float, metavar="SECONDS",
|
|
50
|
+
help="with --pip: the camera starts this many seconds after the source (negative: before), "
|
|
51
|
+
"instead of measuring it -- for a camera without usable audio")
|
|
52
|
+
p.add_argument("--pip-max-offset", type=float, default=30.0,
|
|
53
|
+
help="with --pip: largest offset sync.py searches, in seconds (default 30)")
|
|
46
54
|
p.add_argument("--beats", action="store_true", help="also measure the beat grid (scenes.py --beats)")
|
|
47
55
|
p.add_argument("--highlights", type=int, metavar="N",
|
|
48
56
|
help="also rank N highlight ranges (scenes.py --highlights; audio energy) for the Highlights composition")
|
|
@@ -222,6 +230,35 @@ def main() -> None:
|
|
|
222
230
|
except CaptionError as e:
|
|
223
231
|
die(f"{chpath}: {e}", "input")
|
|
224
232
|
|
|
233
|
+
pip: Optional[Dict[str, Any]] = None
|
|
234
|
+
if a.pip_offset is not None and not a.pip:
|
|
235
|
+
die("--pip-offset needs --pip", "input")
|
|
236
|
+
if a.pip:
|
|
237
|
+
cam = Path(a.pip).expanduser()
|
|
238
|
+
if not cam.is_file():
|
|
239
|
+
die(f"--pip file not found: {cam}", "input")
|
|
240
|
+
cp = ffskill("probe", [str(cam)])
|
|
241
|
+
commands.append(cp["_command"])
|
|
242
|
+
cv = cp.get("video") or {}
|
|
243
|
+
if not cv:
|
|
244
|
+
die(f"--pip {cam} has no video stream", "input")
|
|
245
|
+
pip = {"path": str(cam.resolve()), "name": cam.name,
|
|
246
|
+
"duration": round(float(cv.get("duration") or cp.get("duration") or 0), 3),
|
|
247
|
+
"width": int(cv.get("width") or 0), "height": int(cv.get("height") or 0),
|
|
248
|
+
"fps": float(cv.get("fps") or 0), "offset": 0.0, "confidence": None, "measured": False}
|
|
249
|
+
if a.pip_offset is not None:
|
|
250
|
+
pip["offset"] = round(float(a.pip_offset), 4)
|
|
251
|
+
elif not (audio and cp.get("audio")):
|
|
252
|
+
die("--pip: both recordings need audio to measure their offset; give --pip-offset SECONDS instead",
|
|
253
|
+
"input")
|
|
254
|
+
else:
|
|
255
|
+
sy = ffskill("sync", [str(src), str(cam), "--max-offset", str(a.pip_max_offset)])
|
|
256
|
+
commands.append(sy["_command"])
|
|
257
|
+
pip.update(offset=round(float(sy.get("offset_seconds") or 0), 4),
|
|
258
|
+
confidence=sy.get("confidence"), measured=True)
|
|
259
|
+
if pip["offset"] >= duration or pip["offset"] + pip["duration"] <= 0:
|
|
260
|
+
die(f"--pip: with an offset of {pip['offset']:g} s the camera never overlaps the source", "input")
|
|
261
|
+
|
|
225
262
|
v = video or {}
|
|
226
263
|
timeline: Dict[str, Any] = {
|
|
227
264
|
"schema": TIMELINE_SCHEMA,
|
|
@@ -247,8 +284,12 @@ def main() -> None:
|
|
|
247
284
|
"captions": captions,
|
|
248
285
|
"words": words,
|
|
249
286
|
"chapters": chapters,
|
|
287
|
+
"pip": pip,
|
|
250
288
|
"warnings": warnings_for(probe) + youtube_chapter_warnings(chapters) if chapters else warnings_for(probe),
|
|
251
289
|
}
|
|
290
|
+
if pip and pip["measured"] and (pip["confidence"] or 0) < 0.3:
|
|
291
|
+
timeline["warnings"].append(f"pip: the measured offset ({pip['offset']:g} s) has low confidence "
|
|
292
|
+
f"({pip['confidence']}); check a still, or set it with --pip-offset")
|
|
252
293
|
if not video:
|
|
253
294
|
timeline["warnings"].append("audio-only source: width/height/fps default to 1920x1080 at 30 fps; "
|
|
254
295
|
"render with --aspect / --width to choose the frame.")
|
|
@@ -264,7 +305,8 @@ def main() -> None:
|
|
|
264
305
|
"size": f"{timeline['source']['width']}x{timeline['source']['height']}",
|
|
265
306
|
"scenes": len(scenes), "silences": len(silences),
|
|
266
307
|
"speech_seconds": round(speech_total, 3), "peaks": len(peaks),
|
|
267
|
-
"captions": len(captions), "chapters": len(chapters),
|
|
308
|
+
"captions": len(captions), "chapters": len(chapters),
|
|
309
|
+
"pip_offset": pip["offset"] if pip else None, "beats": bool(beats and beats.get("usable")),
|
|
268
310
|
"tempo_bpm": (beats or {}).get("tempo_bpm"), "highlights": len(highlights),
|
|
269
311
|
"clips": len(clips) or 1, "words": len(words)},
|
|
270
312
|
"warnings": timeline["warnings"]},
|
package/scripts/deliver.py
CHANGED
|
@@ -10,8 +10,10 @@ Examples:
|
|
|
10
10
|
python3 deliver.py titled.mp4 --platform youtube --chapters chapters.txt # + chapter markers
|
|
11
11
|
"""
|
|
12
12
|
import argparse
|
|
13
|
+
import json
|
|
13
14
|
import sys
|
|
14
15
|
from pathlib import Path
|
|
16
|
+
from typing import Optional
|
|
15
17
|
|
|
16
18
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
17
19
|
from _captions import parse_chapters
|
|
@@ -22,6 +24,21 @@ from _common import (STATE, add_common, apply_common, default_output, die, emit,
|
|
|
22
24
|
PLATFORMS = ["youtube", "youtube-shorts", "shorts", "reels", "tiktok", "x", "facebook", "linkedin", "podcast", "audiogram"]
|
|
23
25
|
|
|
24
26
|
|
|
27
|
+
def brand_logo(brand: Optional[str]) -> Optional[Path]:
|
|
28
|
+
"""The brand file's logo, relative to the brand file as ffmpeg-skill reads it."""
|
|
29
|
+
if not brand:
|
|
30
|
+
return None
|
|
31
|
+
bp = Path(brand).expanduser()
|
|
32
|
+
try:
|
|
33
|
+
logo = json.loads(bp.read_text(encoding="utf-8")).get("logo")
|
|
34
|
+
except (OSError, ValueError, AttributeError):
|
|
35
|
+
return None
|
|
36
|
+
if not logo:
|
|
37
|
+
return None
|
|
38
|
+
lp = Path(logo).expanduser()
|
|
39
|
+
return lp if lp.is_absolute() else bp.resolve().parent / lp
|
|
40
|
+
|
|
41
|
+
|
|
25
42
|
def youtube_description(chapters_file: Path) -> str:
|
|
26
43
|
"""The chapter list as YouTube reads it from a description: `00:00 Title` per line."""
|
|
27
44
|
chapters = parse_chapters(chapters_file.read_text(encoding="utf-8-sig"), 0)
|
|
@@ -42,6 +59,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
42
59
|
p.add_argument("-o", "--output", help="deliverable path (default: <name>_<platform>.mp4)")
|
|
43
60
|
p.add_argument("--check-only", action="store_true", help="run check.py only, write nothing")
|
|
44
61
|
p.add_argument("--brand", help="ffmpeg-skill brand.json for the template (its logo, safe margins, loudness)")
|
|
62
|
+
p.add_argument("--logo", help="logo image the template places (default: the brand file's logo)")
|
|
45
63
|
p.add_argument("--chapters", metavar="FILE",
|
|
46
64
|
help="also write these chapters (`TIME TITLE` per line) into the deliverable with ffmpeg-skill "
|
|
47
65
|
"metadata.py, plus the YouTube description block next to it (<name>_description.txt)")
|
|
@@ -70,9 +88,15 @@ def main() -> None:
|
|
|
70
88
|
templated = out.with_name(out.stem + ".nochapters" + out.suffix) if a.chapters else out
|
|
71
89
|
args = ["--template", a.platform, str(src), "-o", str(templated)]
|
|
72
90
|
if a.brand:
|
|
73
|
-
|
|
91
|
+
bp = Path(a.brand).expanduser().resolve()
|
|
92
|
+
if not bp.is_file():
|
|
74
93
|
die(f"brand file not found: {a.brand}", "input")
|
|
75
|
-
args += ["--brand", str(
|
|
94
|
+
args += ["--brand", str(bp)]
|
|
95
|
+
logo = Path(a.logo).expanduser() if a.logo else brand_logo(a.brand)
|
|
96
|
+
if logo:
|
|
97
|
+
if not logo.is_file():
|
|
98
|
+
die(f"logo not found: {logo}", "input")
|
|
99
|
+
args += ["--logo", str(logo.resolve())]
|
|
76
100
|
if STATE.overwrite or a.chapters:
|
|
77
101
|
args.append("--overwrite")
|
|
78
102
|
description = out.with_name(out.stem + "_description.txt")
|
package/scripts/init.py
CHANGED
|
@@ -12,7 +12,7 @@ import sys
|
|
|
12
12
|
from pathlib import Path
|
|
13
13
|
|
|
14
14
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
15
|
-
from _common import ROOT, STATE, add_common, apply_common, die, emit, info, run, shell_join
|
|
15
|
+
from _common import BUILTIN_COMPOSITIONS, ROOT, STATE, add_common, apply_common, die, emit, info, run, shell_join
|
|
16
16
|
|
|
17
17
|
TEMPLATE = ROOT / "templates" / "remotion-project"
|
|
18
18
|
|
|
@@ -54,7 +54,7 @@ def main() -> None:
|
|
|
54
54
|
die("npm install failed:\n" + "\n".join((proc.stderr or "").strip().splitlines()[-20:]), "failed")
|
|
55
55
|
installed = True
|
|
56
56
|
emit({"output": str(dst), "commands": commands, "installed": installed, "entry": "src/index.ts",
|
|
57
|
-
"compositions":
|
|
57
|
+
"compositions": list(BUILTIN_COMPOSITIONS)},
|
|
58
58
|
f"created {dst}" + ("" if installed else f"\nnext: cd {dst} && npm install"))
|
|
59
59
|
|
|
60
60
|
|
package/scripts/pipeline.py
CHANGED
|
@@ -32,6 +32,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
32
32
|
help="chapters (`TIME TITLE` per line, or `source`): cards in Titled and, with --platform, chapter "
|
|
33
33
|
"markers in the deliverable")
|
|
34
34
|
p.add_argument("--options", help="JSON options file passed to the composition")
|
|
35
|
+
p.add_argument("--brand", help="ffmpeg-skill brand.json: the look of the graphics and, on delivery, the logo")
|
|
35
36
|
p.add_argument("--platform", choices=PLATFORMS, help="deliver with this ffmpeg-skill template and check it")
|
|
36
37
|
p.add_argument("--out-dir", help="where the timeline, render and deliverable go (default: next to the input)")
|
|
37
38
|
p.add_argument("--beats", action="store_true", help="measure the beat grid too")
|
|
@@ -101,14 +102,14 @@ def main() -> None:
|
|
|
101
102
|
aspect = a.aspect or platform_aspect(a.platform)
|
|
102
103
|
if aspect:
|
|
103
104
|
r_args += ["--aspect", aspect]
|
|
104
|
-
for flag, val in (("--width", a.width), ("--fit", a.fit), ("--font-file", a.font_file)):
|
|
105
|
+
for flag, val in (("--width", a.width), ("--fit", a.fit), ("--font-file", a.font_file), ("--brand", a.brand)):
|
|
105
106
|
if val is not None:
|
|
106
107
|
r_args += [flag, str(val)]
|
|
107
108
|
rendered = step("draw", "render", r_args, steps)
|
|
108
109
|
|
|
109
110
|
delivered = None
|
|
110
111
|
if a.platform:
|
|
111
|
-
de_args = [str(render_out), "--platform", a.platform]
|
|
112
|
+
de_args = [str(render_out), "--platform", a.platform] + (["--brand", a.brand] if a.brand else [])
|
|
112
113
|
# chapter markers only when the picture keeps the source's clock (cuts would move every chapter)
|
|
113
114
|
if a.chapters and a.chapters != "source" and a.comp not in ("Jumpcut", "Highlights"):
|
|
114
115
|
de_args += ["--chapters", a.chapters]
|
package/scripts/render.py
CHANGED
|
@@ -17,7 +17,7 @@ from typing import Any, Dict, List, Optional, Tuple
|
|
|
17
17
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
18
18
|
import _sparse
|
|
19
19
|
from _common import (BUILTIN_COMPOSITIONS, STATE, add_common, add_frame_args, apply_common, die, emit, expected_frames,
|
|
20
|
-
ffskill, ffskill_cmd, frame_size, info,
|
|
20
|
+
ffskill, ffskill_cmd, frame_size, info, load_look, load_timeline, prepare_props, refuse_existing,
|
|
21
21
|
remotion_bin, require_ffmpeg_skill, require_project, remotion_error, run, shell_join)
|
|
22
22
|
|
|
23
23
|
|
|
@@ -187,7 +187,7 @@ def main() -> None:
|
|
|
187
187
|
timeline_path = Path(a.timeline).expanduser()
|
|
188
188
|
timeline = load_timeline(timeline_path)
|
|
189
189
|
project = require_project(Path(a.project).expanduser(), need_install=not STATE.dry_run)
|
|
190
|
-
options =
|
|
190
|
+
options = load_look(a)
|
|
191
191
|
frames = parse_frames(a.frames)
|
|
192
192
|
require_ffmpeg_skill()
|
|
193
193
|
|
|
@@ -210,8 +210,8 @@ def main() -> None:
|
|
|
210
210
|
die("--merge-gap cannot be negative", "input")
|
|
211
211
|
a.overlay = True
|
|
212
212
|
if a.overlay:
|
|
213
|
-
if a.comp in ("Jumpcut", "Highlights", "BeatMontage"):
|
|
214
|
-
die(f"--overlay cannot do {a.comp}:
|
|
213
|
+
if a.comp in ("Jumpcut", "Highlights", "BeatMontage", "Pip"):
|
|
214
|
+
die(f"--overlay cannot do {a.comp}: it changes the picture itself (overlay works for "
|
|
215
215
|
"Captioned, PeakPulse, Titled, Karaoke)", "input")
|
|
216
216
|
if a.aspect not in (None, "source") or a.width is not None or a.fit not in (None, "contain"):
|
|
217
217
|
die("--overlay draws on the source's own frame: drop --aspect / --width / --fit", "input")
|
package/scripts/still.py
CHANGED
|
@@ -14,7 +14,7 @@ from typing import List
|
|
|
14
14
|
|
|
15
15
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
16
16
|
from _common import (BUILTIN_COMPOSITIONS, STATE, add_common, add_frame_args, apply_common, die, emit,
|
|
17
|
-
expected_frames, info,
|
|
17
|
+
expected_frames, info, load_look, load_timeline, prepare_props, refuse_existing, remotion_bin,
|
|
18
18
|
require_project, remotion_error, run, sec_to_frames, shell_join)
|
|
19
19
|
|
|
20
20
|
|
|
@@ -39,7 +39,7 @@ def main() -> None:
|
|
|
39
39
|
tl_path = Path(a.timeline).expanduser()
|
|
40
40
|
timeline = load_timeline(tl_path)
|
|
41
41
|
project = require_project(Path(a.project).expanduser(), need_install=not STATE.dry_run)
|
|
42
|
-
options =
|
|
42
|
+
options = load_look(a)
|
|
43
43
|
fps = float(timeline["source"]["fps"])
|
|
44
44
|
|
|
45
45
|
frames: List[int] = list(a.frame) + [sec_to_frames(t, fps) for t in a.at]
|
|
@@ -7,6 +7,7 @@ import { Titled } from "./compositions/Titled";
|
|
|
7
7
|
import { Highlights } from "./compositions/Highlights";
|
|
8
8
|
import { BeatMontage } from "./compositions/BeatMontage";
|
|
9
9
|
import { Karaoke } from "./compositions/Karaoke";
|
|
10
|
+
import { Pip } from "./compositions/Pip";
|
|
10
11
|
import { SAMPLE_TIMELINE, fullLengthFrames, highlightFrames, jumpcutFrames, outputFrame, type Props, type Timeline } from "./timeline";
|
|
11
12
|
|
|
12
13
|
// Length and fps come from the measured timeline, never from constants; the frame is the
|
|
@@ -30,5 +31,6 @@ export const RemotionRoot: React.FC = () => (
|
|
|
30
31
|
<Composition id="Highlights" component={Highlights} {...base} calculateMetadata={metadataFrom(highlightFrames)} />
|
|
31
32
|
<Composition id="BeatMontage" component={BeatMontage} {...base} calculateMetadata={metadataFrom(fullLengthFrames)} />
|
|
32
33
|
<Composition id="Karaoke" component={Karaoke} {...base} calculateMetadata={metadataFrom(fullLengthFrames)} />
|
|
34
|
+
<Composition id="Pip" component={Pip} {...base} calculateMetadata={metadataFrom(fullLengthFrames)} />
|
|
33
35
|
</>
|
|
34
36
|
);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { AbsoluteFill, OffthreadVideo, Sequence, staticFile, useVideoConfig } from "remotion";
|
|
3
|
+
import { SourceVideo } from "../lib/SourceVideo";
|
|
4
|
+
import { useStagedFont } from "../lib/useStagedFont";
|
|
5
|
+
import { Props, fontStack, outputFrame, pipFrames, resolveOptions, secToFrames } from "../timeline";
|
|
6
|
+
import { CaptionCard } from "./Captioned";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Pip: the source (a screen recording, slides) with a second recording (a camera) in a corner,
|
|
10
|
+
* kept in sync by the offset ffmpeg-skill measured between their audio tracks. The camera only
|
|
11
|
+
* shows while it has pictures; captions from the timeline are drawn on top, as in Captioned.
|
|
12
|
+
*/
|
|
13
|
+
export const Pip: React.FC<Props> = (props) => {
|
|
14
|
+
const { timeline, options, font } = props;
|
|
15
|
+
useStagedFont(font);
|
|
16
|
+
const o = resolveOptions(options);
|
|
17
|
+
const family = fontStack(o, font);
|
|
18
|
+
const { fps, width, height, durationInFrames } = useVideoConfig();
|
|
19
|
+
const pip = timeline.pip;
|
|
20
|
+
const short = Math.min(width, height);
|
|
21
|
+
const circle = o.pipShape === "circle";
|
|
22
|
+
const w = Math.round(circle ? short * o.pipSize : width * o.pipSize);
|
|
23
|
+
const h = circle ? w : Math.round((w * (pip?.height || 9)) / (pip?.width || 16));
|
|
24
|
+
const margin = Math.round(short * 0.04);
|
|
25
|
+
const [vert, horiz] = o.pipCorner.split("-") as ["top" | "bottom", "left" | "right"];
|
|
26
|
+
const box: React.CSSProperties = {
|
|
27
|
+
position: "absolute",
|
|
28
|
+
width: w,
|
|
29
|
+
height: h,
|
|
30
|
+
[vert]: margin,
|
|
31
|
+
[horiz]: margin,
|
|
32
|
+
overflow: "hidden",
|
|
33
|
+
borderRadius: circle ? "50%" : Math.round(short * 0.018),
|
|
34
|
+
border: `${Math.max(2, Math.round(short * 0.004))}px solid ${o.accent}`,
|
|
35
|
+
boxShadow: "0 8px 30px rgba(0,0,0,0.45)",
|
|
36
|
+
background: "#000",
|
|
37
|
+
};
|
|
38
|
+
const [from, dur, trimBefore] = pip ? pipFrames(pip, fps, durationInFrames) : [0, 1, 0];
|
|
39
|
+
return (
|
|
40
|
+
<AbsoluteFill style={{ backgroundColor: "black" }}>
|
|
41
|
+
<SourceVideo source={timeline.source} fit={outputFrame(props).fit} />
|
|
42
|
+
{pip && pip.src ? (
|
|
43
|
+
<Sequence from={from} durationInFrames={dur} name="camera" layout="none">
|
|
44
|
+
<div style={box}>
|
|
45
|
+
<OffthreadVideo
|
|
46
|
+
src={staticFile(pip.src)}
|
|
47
|
+
trimBefore={trimBefore}
|
|
48
|
+
muted={!o.pipAudio}
|
|
49
|
+
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
|
50
|
+
/>
|
|
51
|
+
</div>
|
|
52
|
+
</Sequence>
|
|
53
|
+
) : null}
|
|
54
|
+
{timeline.captions.map((c, i) => {
|
|
55
|
+
const start = secToFrames(c.start, fps);
|
|
56
|
+
const len = Math.max(1, secToFrames(c.end, fps) - start);
|
|
57
|
+
return (
|
|
58
|
+
<Sequence key={i} from={start} durationInFrames={len} name={`cue ${i + 1}`} layout="none">
|
|
59
|
+
<CaptionCard text={c.text} durationInFrames={len} o={o} fontFamily={family} />
|
|
60
|
+
</Sequence>
|
|
61
|
+
);
|
|
62
|
+
})}
|
|
63
|
+
</AbsoluteFill>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
@@ -19,6 +19,20 @@ export type Source = {
|
|
|
19
19
|
|
|
20
20
|
export type Caption = { start: number; end: number; text: string };
|
|
21
21
|
export type Chapter = { start: number; end: number; title: string };
|
|
22
|
+
/** A second recording shown picture-in-picture (analyze.py --pip). offset: seconds after the source's
|
|
23
|
+
* start at which the camera's first frame belongs (measured from both audio tracks, or given). */
|
|
24
|
+
export type Pip = {
|
|
25
|
+
path: string;
|
|
26
|
+
name: string;
|
|
27
|
+
src?: string | null;
|
|
28
|
+
duration: number;
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
fps: number;
|
|
32
|
+
offset: number;
|
|
33
|
+
confidence: number | null;
|
|
34
|
+
measured: boolean;
|
|
35
|
+
};
|
|
22
36
|
export type Beats = { times: number[]; tempo_bpm: number | null; confidence: number | null; usable: boolean };
|
|
23
37
|
export type Highlight = { start: number; end: number };
|
|
24
38
|
/** A lower third: text from the user (options), timing in source seconds. */
|
|
@@ -42,6 +56,7 @@ export type Timeline = {
|
|
|
42
56
|
words?: Caption[];
|
|
43
57
|
/** Chapters from the user's list or the source's own markers (analyze.py --chapters); titles as written. */
|
|
44
58
|
chapters?: Chapter[];
|
|
59
|
+
pip?: Pip | null;
|
|
45
60
|
warnings?: string[];
|
|
46
61
|
};
|
|
47
62
|
|
|
@@ -72,6 +87,14 @@ export type Options = {
|
|
|
72
87
|
beatsPerCut: number;
|
|
73
88
|
/** Titled: seconds a chapter card stays up at the start of each chapter (0 = no chapter cards). */
|
|
74
89
|
chapterSeconds: number;
|
|
90
|
+
/** Pip: which corner the camera sits in. */
|
|
91
|
+
pipCorner: "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
92
|
+
/** Pip: camera width as a fraction of the frame width (circle: of the short side). */
|
|
93
|
+
pipSize: number;
|
|
94
|
+
/** Pip: rounded rectangle or circle. */
|
|
95
|
+
pipShape: "rounded" | "circle";
|
|
96
|
+
/** Pip: play the camera's own audio too (off: the source's audio only). */
|
|
97
|
+
pipAudio: boolean;
|
|
75
98
|
};
|
|
76
99
|
|
|
77
100
|
export const DEFAULT_OPTIONS: Options = {
|
|
@@ -89,6 +112,18 @@ export const DEFAULT_OPTIONS: Options = {
|
|
|
89
112
|
title: null,
|
|
90
113
|
beatsPerCut: 4,
|
|
91
114
|
chapterSeconds: 4,
|
|
115
|
+
pipCorner: "bottom-right",
|
|
116
|
+
pipSize: 0.28,
|
|
117
|
+
pipShape: "rounded",
|
|
118
|
+
pipAudio: false,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** Where the camera plays on the source timeline: [from, durationInFrames, trimBefore] in frames. */
|
|
122
|
+
export const pipFrames = (p: Pip, fps: number, total: number): [number, number, number] => {
|
|
123
|
+
const from = Math.max(0, secToFrames(p.offset, fps));
|
|
124
|
+
const trimBefore = Math.max(0, secToFrames(-p.offset, fps));
|
|
125
|
+
const end = Math.min(total, secToFrames(p.offset + p.duration, fps));
|
|
126
|
+
return [from, Math.max(1, end - from), trimBefore];
|
|
92
127
|
};
|
|
93
128
|
|
|
94
129
|
/** [from, durationInFrames] of the card at the start of a chapter (Titled). render.py mirrors this. */
|