remotion-ffmpeg-skill 0.0.0-stage → 0.2.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.
Files changed (32) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +112 -2
  3. package/SKILL.md +66 -0
  4. package/bin/remotion-ffmpeg-skill.js +100 -0
  5. package/mcp/server.py +150 -0
  6. package/package.json +12 -4
  7. package/references/timeline.md +93 -0
  8. package/scripts/_captions.py +79 -0
  9. package/scripts/_common.py +538 -0
  10. package/scripts/_contract.py +202 -0
  11. package/scripts/analyze.py +240 -0
  12. package/scripts/deliver.py +79 -0
  13. package/scripts/doctor.py +83 -0
  14. package/scripts/init.py +62 -0
  15. package/scripts/pipeline.py +122 -0
  16. package/scripts/render.py +215 -0
  17. package/scripts/still.py +84 -0
  18. package/templates/remotion-project/package.json +20 -0
  19. package/templates/remotion-project/public/.gitkeep +0 -0
  20. package/templates/remotion-project/remotion.config.ts +6 -0
  21. package/templates/remotion-project/src/Root.tsx +32 -0
  22. package/templates/remotion-project/src/compositions/BeatMontage.tsx +60 -0
  23. package/templates/remotion-project/src/compositions/Captioned.tsx +95 -0
  24. package/templates/remotion-project/src/compositions/Highlights.tsx +98 -0
  25. package/templates/remotion-project/src/compositions/Jumpcut.tsx +52 -0
  26. package/templates/remotion-project/src/compositions/PeakPulse.tsx +73 -0
  27. package/templates/remotion-project/src/compositions/Titled.tsx +138 -0
  28. package/templates/remotion-project/src/index.ts +4 -0
  29. package/templates/remotion-project/src/lib/SourceVideo.tsx +84 -0
  30. package/templates/remotion-project/src/lib/useStagedFont.ts +25 -0
  31. package/templates/remotion-project/src/timeline.ts +214 -0
  32. package/templates/remotion-project/tsconfig.json +15 -0
@@ -0,0 +1,214 @@
1
+ // The timeline.json contract written by analyze.py (schema remotion-ffmpeg-skill/timeline@1).
2
+ // Every number here was measured by ffmpeg-skill; compositions only read it.
3
+
4
+ export type Range = [number, number];
5
+
6
+ export type Source = {
7
+ /** Path the skill measured. Not used by the browser. */
8
+ path?: string;
9
+ /** staticFile() path inside public/, set by render.py / still.py. null = no picture (placeholder). */
10
+ src: string | null;
11
+ name: string;
12
+ duration: number;
13
+ fps: number;
14
+ width: number;
15
+ height: number;
16
+ has_video: boolean;
17
+ has_audio: boolean;
18
+ };
19
+
20
+ export type Caption = { start: number; end: number; text: string };
21
+ export type Beats = { times: number[]; tempo_bpm: number | null; confidence: number | null; usable: boolean };
22
+ export type Highlight = { start: number; end: number };
23
+ /** A lower third: text from the user (options), timing in source seconds. */
24
+ export type LowerThird = { text: string; sub?: string; start: number; end: number };
25
+ export type Peak = { time: number; rms: number };
26
+ export type Scene = { start: number; end: number };
27
+
28
+ export type Timeline = {
29
+ schema: string;
30
+ source: Source;
31
+ scenes: Scene[];
32
+ silences: Range[];
33
+ speech: Range[];
34
+ peaks: Peak[];
35
+ beats?: Beats | null;
36
+ highlights?: Highlight[];
37
+ /** Several inputs joined by ffmpeg-skill: where each clip sits on the joined timeline. */
38
+ clips?: { name: string; start: number; end: number }[];
39
+ captions: Caption[];
40
+ warnings?: string[];
41
+ };
42
+
43
+ /** Look-and-feel knobs. Every field is optional in the props; defaults below. */
44
+ export type Options = {
45
+ accent: string;
46
+ textColor: string;
47
+ fontFamily: string;
48
+ /** Caption font size as a fraction of the frame's short side. */
49
+ captionSize: number;
50
+ /** Caption block bottom margin as a fraction of the frame height; null = 0.08 landscape, 0.2 portrait (clear of Reels/TikTok UI). */
51
+ captionMargin: number | null;
52
+ /** Jumpcut: zoom applied to every other cut (1 = off). */
53
+ punchIn: number;
54
+ /** PeakPulse: strength of the pulse, 0..1. */
55
+ pulse: number;
56
+ /** PeakPulse: show the progress bar along the bottom edge. */
57
+ progressBar: boolean;
58
+ /** PeakPulse: what drives the pulse -- measured audio peaks, the measured beat grid, or beats when usable. */
59
+ driver: "auto" | "peaks" | "beats";
60
+ /** Titled: lower thirds (text from the user, never invented). */
61
+ lowerThirds: LowerThird[];
62
+ /** Titled: one title per measured scene, in order; a scene without an entry gets none. */
63
+ sceneTitles: string[];
64
+ /** Highlights: title shown over the first highlight (optional). */
65
+ title: string | null;
66
+ /** BeatMontage: cut the picture every N measured beats. */
67
+ beatsPerCut: number;
68
+ };
69
+
70
+ export const DEFAULT_OPTIONS: Options = {
71
+ accent: "#ffcc00",
72
+ textColor: "#ffffff",
73
+ fontFamily: "'Noto Sans JP', 'Hiragino Sans', 'Yu Gothic', 'Noto Sans', 'Helvetica Neue', Arial, sans-serif",
74
+ captionSize: 0.055,
75
+ captionMargin: null,
76
+ punchIn: 1.12,
77
+ pulse: 0.6,
78
+ progressBar: true,
79
+ driver: "auto",
80
+ lowerThirds: [],
81
+ sceneTitles: [],
82
+ title: null,
83
+ beatsPerCut: 4,
84
+ };
85
+
86
+ /**
87
+ * Output frame, chosen at render time (render.py --aspect / --width / --fit); not a measurement.
88
+ * Absent = the source's own size. fit: how the source fills a frame of another shape --
89
+ * contain (bars), cover (crop) or blur (contained over a blurred, cropped copy).
90
+ */
91
+ export type Fit = "contain" | "cover" | "blur";
92
+ export type Frame = { width: number; height: number; fit: Fit };
93
+
94
+ /** A font file staged into public/ by render.py (--font-file, or a CJK font found by ffmpeg-skill). */
95
+ export type FontAsset = { src: string; family: string };
96
+
97
+ export type Props = {
98
+ timeline: Timeline;
99
+ options?: Partial<Options>;
100
+ frame?: Frame | null;
101
+ font?: FontAsset | null;
102
+ /**
103
+ * Graphics only, on a transparent background (render.py --overlay): the source is not drawn and
104
+ * ffmpeg-skill composites the result over it afterwards -- much faster on long footage.
105
+ */
106
+ overlay?: boolean;
107
+ };
108
+
109
+ export const resolveOptions = (o?: Partial<Options>): Options => ({ ...DEFAULT_OPTIONS, ...(o ?? {}) });
110
+
111
+ export const outputFrame = (p: Props): Frame =>
112
+ p.frame ?? { width: p.timeline.source.width, height: p.timeline.source.height, fit: "contain" };
113
+
114
+ /** Font stack with the staged font (if any) first. */
115
+ export const fontStack = (o: Options, font?: FontAsset | null): string =>
116
+ font ? `'${font.family}', ${o.fontFamily}` : o.fontFamily;
117
+
118
+ export const secToFrames = (seconds: number, fps: number): number => Math.round(seconds * fps);
119
+
120
+ /** Speech ranges, or the whole source when analyze.py found no silence. */
121
+ export const speechRanges = (t: Timeline): Range[] =>
122
+ t.speech && t.speech.length > 0 ? t.speech : [[0, t.source.duration]];
123
+
124
+ // Durations: must match expected_frames() in scripts/_common.py (render.py verifies the output against it).
125
+ export const fullLengthFrames = (t: Timeline): number =>
126
+ Math.max(1, secToFrames(t.source.duration, t.source.fps));
127
+
128
+ export const jumpcutFrames = (t: Timeline): number => {
129
+ const fps = t.source.fps;
130
+ const total = speechRanges(t).reduce(
131
+ (sum, [s, e]) => sum + Math.max(1, secToFrames(e, fps) - secToFrames(s, fps)),
132
+ 0,
133
+ );
134
+ return Math.max(1, total);
135
+ };
136
+
137
+ export type TimedCue = { from: number; durationInFrames: number; text: string };
138
+
139
+ /**
140
+ * Map caption cues from source time onto the Jumpcut timeline (speech ranges played back to back).
141
+ * Each piece of a cue that overlaps a kept range becomes its own cue; pieces inside removed
142
+ * silences disappear. Neighbouring pieces of the same cue that end up adjacent are merged.
143
+ */
144
+ export const retimeCaptions = (t: Timeline): TimedCue[] => {
145
+ const fps = t.source.fps;
146
+ const out: TimedCue[] = [];
147
+ let offset = 0;
148
+ for (const [s, e] of speechRanges(t)) {
149
+ const a = secToFrames(s, fps);
150
+ const b = a + Math.max(1, secToFrames(e, fps) - a);
151
+ for (const c of t.captions) {
152
+ const ca = Math.max(a, secToFrames(c.start, fps));
153
+ const cb = Math.min(b, secToFrames(c.end, fps));
154
+ if (cb <= ca) continue;
155
+ const from = offset + (ca - a);
156
+ const last = out[out.length - 1];
157
+ if (last && last.text === c.text && last.from + last.durationInFrames === from) {
158
+ last.durationInFrames += cb - ca;
159
+ } else {
160
+ out.push({ from, durationInFrames: cb - ca, text: c.text });
161
+ }
162
+ }
163
+ offset += b - a;
164
+ }
165
+ return out;
166
+ };
167
+
168
+ /** Highlight ranges, or the whole source when analyze.py was not asked for any. */
169
+ export const highlightRanges = (t: Timeline): Range[] =>
170
+ t.highlights && t.highlights.length > 0 ? t.highlights.map((h) => [h.start, h.end] as Range) : [[0, t.source.duration]];
171
+
172
+ export const highlightFrames = (t: Timeline): number => {
173
+ const fps = t.source.fps;
174
+ const total = highlightRanges(t).reduce(
175
+ (sum, [s, e]) => sum + Math.max(1, secToFrames(e, fps) - secToFrames(s, fps)),
176
+ 0,
177
+ );
178
+ return Math.max(1, total);
179
+ };
180
+
181
+ /** Usable measured beat times (empty when the grid was not measured or not confident). */
182
+ export const beatTimes = (t: Timeline): number[] => (t.beats && t.beats.usable ? t.beats.times : []);
183
+
184
+ /** Fictional sample for Remotion Studio previews; real renders always pass a measured timeline. */
185
+ export const SAMPLE_TIMELINE: Timeline = {
186
+ schema: "remotion-ffmpeg-skill/timeline@1",
187
+ source: {
188
+ src: null,
189
+ name: "sample (no source)",
190
+ duration: 8,
191
+ fps: 30,
192
+ width: 1280,
193
+ height: 720,
194
+ has_video: false,
195
+ has_audio: false,
196
+ },
197
+ scenes: [
198
+ { start: 0, end: 4 },
199
+ { start: 4, end: 8 },
200
+ ],
201
+ silences: [[3, 5]],
202
+ speech: [
203
+ [0, 3.15],
204
+ [4.85, 8],
205
+ ],
206
+ peaks: [
207
+ { time: 1.5, rms: 0.09 },
208
+ { time: 6.2, rms: 0.07 },
209
+ ],
210
+ captions: [
211
+ { start: 0.4, end: 2.8, text: "Sample caption for the preview" },
212
+ { start: 5.0, end: 7.6, text: "Second line, placeholder text" },
213
+ ],
214
+ };
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ES2020",
5
+ "moduleResolution": "bundler",
6
+ "jsx": "react-jsx",
7
+ "strict": true,
8
+ "noEmit": true,
9
+ "skipLibCheck": true,
10
+ "esModuleInterop": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "resolveJsonModule": true
13
+ },
14
+ "include": ["src"]
15
+ }