remotion-ffmpeg-skill 0.9.0 → 0.10.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 +27 -6
- package/SKILL.md +1 -0
- package/package.json +3 -3
- package/references/scripts.md +6 -3
- package/references/timeline.md +6 -0
- package/scripts/_common.py +15 -2
- package/scripts/analyze.py +44 -2
- package/scripts/init.py +2 -2
- package/scripts/render.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/{bin → cli}/remotion-ffmpeg-skill.js +0 -0
package/README.md
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center"><img src="https://raw.githubusercontent.com/kajisho5/remotion-ffmpeg-skill/media/brand/png/icon-512.png" width="128" alt="remotion-ffmpeg-skill icon"></p>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<picture>
|
|
5
|
+
<source media="(prefers-color-scheme: dark)" srcset="brand/logo/wordmark-white.svg">
|
|
6
|
+
<img src="brand/logo/wordmark-black.svg" height="40" alt="remotion-ffmpeg-skill">
|
|
7
|
+
</picture>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
<a href="https://github.com/sponsors/kajisho5"><img src="https://img.shields.io/badge/sponsor-%E2%9D%A4-ea4aaa?logo=githubsponsors" alt="Sponsor"></a>
|
|
12
|
+
</p>
|
|
2
13
|
|
|
3
14
|
**ffmpeg-skill measures the footage. Remotion draws from those measurements. ffmpeg-skill checks and delivers the result.**
|
|
4
15
|
|
|
@@ -6,14 +17,14 @@ An [Agent Skill](https://docs.claude.com/en/docs/agents-and-tools/agent-skills/o
|
|
|
6
17
|
|
|
7
18
|
Built on [**ffmpeg-skill**](https://github.com/kajisho5/ffmpeg-skill). Unofficial — not affiliated with Remotion.
|
|
8
19
|
|
|
9
|
-

|
|
20
|
+

|
|
10
21
|
|
|
11
22
|
<sub>Fictional demo footage. ffmpeg-skill measured two silences and a scene cut; Remotion played only the speech ranges with punch-in zooms and re-timed captions; render.py verified 201 of 201 frames.</sub>
|
|
12
23
|
|
|
13
24
|
<table>
|
|
14
25
|
<tr>
|
|
15
|
-
<td width="62%"><img src="assets/demo-karaoke.gif" alt="Karaoke: each word lights up at the time a speech engine measured"><br><sub><b>Karaoke</b> — words light up at their measured times (250 / 250 frames verified)</sub></td>
|
|
16
|
-
<td width="38%"><img src="assets/demo-portrait-ja.gif" alt="9:16 jump cut with Japanese captions on a blurred fill"><br><sub><b>9:16 + Japanese</b> — silences cut, CJK font staged automatically, phrase-based line breaks</sub></td>
|
|
26
|
+
<td width="62%"><img src="https://raw.githubusercontent.com/kajisho5/remotion-ffmpeg-skill/media/assets/demo-karaoke.gif" alt="Karaoke: each word lights up at the time a speech engine measured"><br><sub><b>Karaoke</b> — words light up at their measured times (250 / 250 frames verified)</sub></td>
|
|
27
|
+
<td width="38%"><img src="https://raw.githubusercontent.com/kajisho5/remotion-ffmpeg-skill/media/assets/demo-portrait-ja.gif" alt="9:16 jump cut with Japanese captions on a blurred fill"><br><sub><b>9:16 + Japanese</b> — silences cut, CJK font staged automatically, phrase-based line breaks</sub></td>
|
|
17
28
|
</tr>
|
|
18
29
|
</table>
|
|
19
30
|
|
|
@@ -85,10 +96,11 @@ Tool names and input schemas come from the machine-readable contract (`npx remot
|
|
|
85
96
|
| `Highlights` | sum of ranked highlights | ffmpeg-skill's audio-energy highlights back to back, counter, title |
|
|
86
97
|
| `BeatMontage` | source duration | audio unbroken, picture cuts on the measured beat grid |
|
|
87
98
|
| `Karaoke` | source duration | words light up at the times a local speech engine measured |
|
|
99
|
+
| `Pip` | source duration | a second recording (camera) in a corner, synced by the offset measured between the two audio tracks; captions on top |
|
|
88
100
|
|
|
89
101
|
**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
102
|
|
|
91
|
-
<img src="assets/portrait-ja-still.png" width="270" alt="9:16 still with a Japanese caption, blurred fill behind the 16:9 source">
|
|
103
|
+
<img src="https://raw.githubusercontent.com/kajisho5/remotion-ffmpeg-skill/media/assets/portrait-ja-still.png" width="270" alt="9:16 still with a Japanese caption, blurred fill behind the 16:9 source">
|
|
92
104
|
|
|
93
105
|
**Fonts:** Japanese / Chinese / Korean captions get the CJK font ffmpeg-skill finds on the machine, loaded before the first frame — no tofu. `--font-file` for your own.
|
|
94
106
|
|
|
@@ -119,7 +131,16 @@ This skill is MIT. **Remotion itself has its own licence**: free for individuals
|
|
|
119
131
|
|
|
120
132
|
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.
|
|
121
133
|
|
|
122
|
-
**`--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)
|
|
134
|
+
**`--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). How much it saves depends on how much of the footage shows graphics — measured on the same 2-core Linux machine, 1280×720, 30 fps:
|
|
135
|
+
|
|
136
|
+
| Footage | Frames drawn | Full layer | `--sparse` |
|
|
137
|
+
|---|---|---|---|
|
|
138
|
+
| 60 s, captions on 7 s | 211 / 1800 (12 %) | 152 s | 46 s |
|
|
139
|
+
| 40 s, two scene titles + one lower third | 272 / 1200 (23 %) | 104 s | 39 s |
|
|
140
|
+
| 60 s, captions on half of it | 909 / 1800 (50 %) | 155 s | 100 s |
|
|
141
|
+
| captions on all of it | — | — | nothing to skip: draws the full layer and says so |
|
|
142
|
+
|
|
143
|
+
Browser start-up and the final composite cost the same either way, so the gain is smaller than the share of frames skipped. Needs an ffmpeg-skill whose `overlay.py` has `--place`; otherwise it draws the full layer and says why.
|
|
123
144
|
|
|
124
145
|
## Agent evals
|
|
125
146
|
|
package/SKILL.md
CHANGED
|
@@ -56,6 +56,7 @@ 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 |
|
|
61
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 |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remotion-ffmpeg-skill",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.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",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"url": "https://github.com/kajisho5/remotion-ffmpeg-skill/issues"
|
|
29
29
|
},
|
|
30
30
|
"bin": {
|
|
31
|
-
"remotion-ffmpeg-skill": "
|
|
31
|
+
"remotion-ffmpeg-skill": "cli/remotion-ffmpeg-skill.js"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
34
|
-
"
|
|
34
|
+
"cli",
|
|
35
35
|
"SKILL.md",
|
|
36
36
|
"scripts",
|
|
37
37
|
"templates",
|
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) |
|
|
@@ -102,7 +105,7 @@ Render a composition from a timeline, verify it (frames, fps, size, audio) and w
|
|
|
102
105
|
| Argument | Type | Default | Meaning |
|
|
103
106
|
|---|---|---|---|
|
|
104
107
|
| `--project (required)` | string | | Remotion project folder made by init.py |
|
|
105
|
-
| `--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) |
|
|
106
109
|
| `--timeline (required)` | string | | timeline.json written by analyze.py |
|
|
107
110
|
| `--options` | string | | JSON object of look-and-feel options (see references/timeline.md) |
|
|
108
111
|
| `--output` | string | | output file (default: <source>_<comp>.mp4, .mov for prores) |
|
|
@@ -165,7 +168,7 @@ analyze -> render -> deliver in one call, stopping at the first failed step.
|
|
|
165
168
|
|---|---|---|---|
|
|
166
169
|
| `input` | string, repeatable | | source video; several are joined in order (ffmpeg-skill join.py) first |
|
|
167
170
|
| `--project (required)` | string | | Remotion project folder made by init.py |
|
|
168
|
-
| `--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) |
|
|
169
172
|
| `--captions` | string | | SRT / WebVTT / JSON cues for the timeline |
|
|
170
173
|
| `--chapters` | string | | chapters (`TIME TITLE` per line, or `source`): cards in Titled and, with --platform, chapter markers in the deliverable |
|
|
171
174
|
| `--options` | string | | JSON options file passed to the composition |
|
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
|
@@ -222,6 +222,9 @@ def validate_timeline(t: Any) -> List[str]:
|
|
|
222
222
|
v = src.get(k)
|
|
223
223
|
if not isinstance(v, (int, float)) or v <= 0:
|
|
224
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)")
|
|
225
228
|
for k in ("scenes", "silences", "speech", "peaks", "captions", "highlights", "words", "chapters"):
|
|
226
229
|
if not isinstance(t.get(k, []), list):
|
|
227
230
|
p.append(f"{k} must be a list")
|
|
@@ -251,7 +254,7 @@ def expected_frames(comp: str, t: Dict[str, Any]) -> Optional[int]:
|
|
|
251
254
|
and render.py then only reports the measured numbers.
|
|
252
255
|
"""
|
|
253
256
|
fps = float(t["source"]["fps"])
|
|
254
|
-
if comp in ("Captioned", "PeakPulse", "Titled", "BeatMontage", "Karaoke"):
|
|
257
|
+
if comp in ("Captioned", "PeakPulse", "Titled", "BeatMontage", "Karaoke", "Pip"):
|
|
255
258
|
return max(1, sec_to_frames(float(t["source"]["duration"]), fps))
|
|
256
259
|
if comp in ("Jumpcut", "Highlights"):
|
|
257
260
|
if comp == "Jumpcut":
|
|
@@ -265,7 +268,7 @@ def expected_frames(comp: str, t: Dict[str, Any]) -> Optional[int]:
|
|
|
265
268
|
|
|
266
269
|
# ---------------------------------------------------------------- Remotion project
|
|
267
270
|
|
|
268
|
-
BUILTIN_COMPOSITIONS = ("Captioned", "Jumpcut", "PeakPulse", "Titled", "Highlights", "BeatMontage", "Karaoke")
|
|
271
|
+
BUILTIN_COMPOSITIONS = ("Captioned", "Jumpcut", "PeakPulse", "Titled", "Highlights", "BeatMontage", "Karaoke", "Pip")
|
|
269
272
|
|
|
270
273
|
|
|
271
274
|
def remotion_bin(project: Path) -> Path:
|
|
@@ -454,6 +457,8 @@ def write_props(project: Path, comp: str, timeline: Dict[str, Any], options: Dic
|
|
|
454
457
|
src = t["source"].get("path")
|
|
455
458
|
has_media = t["source"].get("has_video", True) or t["source"].get("has_audio", False)
|
|
456
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"])
|
|
457
462
|
props = {"timeline": t, "options": options, "frame": frame, "font": font, "overlay": overlay}
|
|
458
463
|
# Named by content: two renders running at once (different sources, shapes or options) never
|
|
459
464
|
# overwrite each other's props, and identical props share one file harmlessly.
|
|
@@ -586,6 +591,7 @@ _OPTION_TYPES: Dict[str, Any] = {
|
|
|
586
591
|
"captionMargin": (int, float, type(None)), "punchIn": (int, float), "pulse": (int, float),
|
|
587
592
|
"progressBar": bool, "driver": str, "lowerThirds": list, "sceneTitles": list,
|
|
588
593
|
"title": (str, type(None)), "beatsPerCut": int, "chapterSeconds": (int, float),
|
|
594
|
+
"pipCorner": str, "pipSize": (int, float), "pipShape": str, "pipAudio": bool,
|
|
589
595
|
}
|
|
590
596
|
|
|
591
597
|
|
|
@@ -611,6 +617,13 @@ def validate_options(o: Dict[str, Any]) -> List[str]:
|
|
|
611
617
|
if isinstance(o.get("chapterSeconds"), (int, float)) and not isinstance(o["chapterSeconds"], bool) \
|
|
612
618
|
and o["chapterSeconds"] < 0:
|
|
613
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)")
|
|
614
627
|
if any(not isinstance(s, str) for s in (o.get("sceneTitles") or [])):
|
|
615
628
|
p.append("sceneTitles must be a list of strings")
|
|
616
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/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/render.py
CHANGED
|
@@ -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")
|
|
@@ -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. */
|
|
File without changes
|