@kolbo/kolbo-code-darwin-arm64 1.0.3

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 (47) hide show
  1. package/bin/kolbo +0 -0
  2. package/package.json +14 -0
  3. package/skills/frontend-design/SKILL.md +42 -0
  4. package/skills/kolbo/SKILL.md +216 -0
  5. package/skills/remotion-best-practices/SKILL.md +61 -0
  6. package/skills/remotion-best-practices/rules/3d.md +86 -0
  7. package/skills/remotion-best-practices/rules/animations.md +27 -0
  8. package/skills/remotion-best-practices/rules/assets/charts-bar-chart.tsx +173 -0
  9. package/skills/remotion-best-practices/rules/assets/text-animations-typewriter.tsx +100 -0
  10. package/skills/remotion-best-practices/rules/assets/text-animations-word-highlight.tsx +103 -0
  11. package/skills/remotion-best-practices/rules/assets.md +78 -0
  12. package/skills/remotion-best-practices/rules/audio-visualization.md +198 -0
  13. package/skills/remotion-best-practices/rules/audio.md +169 -0
  14. package/skills/remotion-best-practices/rules/calculate-metadata.md +134 -0
  15. package/skills/remotion-best-practices/rules/can-decode.md +81 -0
  16. package/skills/remotion-best-practices/rules/charts.md +120 -0
  17. package/skills/remotion-best-practices/rules/compositions.md +154 -0
  18. package/skills/remotion-best-practices/rules/display-captions.md +184 -0
  19. package/skills/remotion-best-practices/rules/extract-frames.md +229 -0
  20. package/skills/remotion-best-practices/rules/ffmpeg.md +38 -0
  21. package/skills/remotion-best-practices/rules/fonts.md +152 -0
  22. package/skills/remotion-best-practices/rules/get-audio-duration.md +58 -0
  23. package/skills/remotion-best-practices/rules/get-video-dimensions.md +68 -0
  24. package/skills/remotion-best-practices/rules/get-video-duration.md +60 -0
  25. package/skills/remotion-best-practices/rules/gifs.md +141 -0
  26. package/skills/remotion-best-practices/rules/images.md +134 -0
  27. package/skills/remotion-best-practices/rules/import-srt-captions.md +69 -0
  28. package/skills/remotion-best-practices/rules/light-leaks.md +73 -0
  29. package/skills/remotion-best-practices/rules/lottie.md +70 -0
  30. package/skills/remotion-best-practices/rules/maps.md +412 -0
  31. package/skills/remotion-best-practices/rules/measuring-dom-nodes.md +34 -0
  32. package/skills/remotion-best-practices/rules/measuring-text.md +140 -0
  33. package/skills/remotion-best-practices/rules/parameters.md +109 -0
  34. package/skills/remotion-best-practices/rules/sequencing.md +118 -0
  35. package/skills/remotion-best-practices/rules/sfx.md +30 -0
  36. package/skills/remotion-best-practices/rules/subtitles.md +36 -0
  37. package/skills/remotion-best-practices/rules/tailwind.md +11 -0
  38. package/skills/remotion-best-practices/rules/text-animations.md +20 -0
  39. package/skills/remotion-best-practices/rules/timing.md +179 -0
  40. package/skills/remotion-best-practices/rules/transcribe-captions.md +70 -0
  41. package/skills/remotion-best-practices/rules/transitions.md +197 -0
  42. package/skills/remotion-best-practices/rules/transparent-videos.md +106 -0
  43. package/skills/remotion-best-practices/rules/trimming.md +51 -0
  44. package/skills/remotion-best-practices/rules/videos.md +171 -0
  45. package/skills/remotion-best-practices/rules/voiceover.md +99 -0
  46. package/skills/video-production/SKILL.md +152 -0
  47. package/skills/youtube-clipper/SKILL.md +187 -0
@@ -0,0 +1,134 @@
1
+ ---
2
+ name: calculate-metadata
3
+ description: Dynamically set composition duration, dimensions, and props
4
+ metadata:
5
+ tags: calculateMetadata, duration, dimensions, props, dynamic
6
+ ---
7
+
8
+ # Using calculateMetadata
9
+
10
+ Use `calculateMetadata` on a `<Composition>` to dynamically set duration, dimensions, and transform props before rendering.
11
+
12
+ ```tsx
13
+ <Composition
14
+ id="MyComp"
15
+ component={MyComponent}
16
+ durationInFrames={300}
17
+ fps={30}
18
+ width={1920}
19
+ height={1080}
20
+ defaultProps={{ videoSrc: "https://remotion.media/video.mp4" }}
21
+ calculateMetadata={calculateMetadata}
22
+ />
23
+ ```
24
+
25
+ ## Setting duration based on a video
26
+
27
+ Use the [`getVideoDuration`](./get-video-duration.md) and [`getVideoDimensions`](./get-video-dimensions.md) skills to get the video duration and dimensions:
28
+
29
+ ```tsx
30
+ import { CalculateMetadataFunction } from "remotion";
31
+ import { getVideoDuration } from "./get-video-duration";
32
+
33
+ const calculateMetadata: CalculateMetadataFunction<Props> = async ({
34
+ props,
35
+ }) => {
36
+ const durationInSeconds = await getVideoDuration(props.videoSrc);
37
+
38
+ return {
39
+ durationInFrames: Math.ceil(durationInSeconds * 30),
40
+ };
41
+ };
42
+ ```
43
+
44
+ ## Matching dimensions of a video
45
+
46
+ Use the [`getVideoDimensions`](./get-video-dimensions.md) skill to get the video dimensions:
47
+
48
+ ```tsx
49
+ import { CalculateMetadataFunction } from "remotion";
50
+ import { getVideoDuration } from "./get-video-duration";
51
+ import { getVideoDimensions } from "./get-video-dimensions";
52
+
53
+ const calculateMetadata: CalculateMetadataFunction<Props> = async ({
54
+ props,
55
+ }) => {
56
+ const dimensions = await getVideoDimensions(props.videoSrc);
57
+
58
+ return {
59
+ width: dimensions.width,
60
+ height: dimensions.height,
61
+ };
62
+ };
63
+ ```
64
+
65
+ ## Setting duration based on multiple videos
66
+
67
+ ```tsx
68
+ const calculateMetadata: CalculateMetadataFunction<Props> = async ({
69
+ props,
70
+ }) => {
71
+ const metadataPromises = props.videos.map((video) =>
72
+ getVideoDuration(video.src),
73
+ );
74
+ const allMetadata = await Promise.all(metadataPromises);
75
+
76
+ const totalDuration = allMetadata.reduce(
77
+ (sum, durationInSeconds) => sum + durationInSeconds,
78
+ 0,
79
+ );
80
+
81
+ return {
82
+ durationInFrames: Math.ceil(totalDuration * 30),
83
+ };
84
+ };
85
+ ```
86
+
87
+ ## Setting a default outName
88
+
89
+ Set the default output filename based on props:
90
+
91
+ ```tsx
92
+ const calculateMetadata: CalculateMetadataFunction<Props> = async ({
93
+ props,
94
+ }) => {
95
+ return {
96
+ defaultOutName: `video-${props.id}.mp4`,
97
+ };
98
+ };
99
+ ```
100
+
101
+ ## Transforming props
102
+
103
+ Fetch data or transform props before rendering:
104
+
105
+ ```tsx
106
+ const calculateMetadata: CalculateMetadataFunction<Props> = async ({
107
+ props,
108
+ abortSignal,
109
+ }) => {
110
+ const response = await fetch(props.dataUrl, { signal: abortSignal });
111
+ const data = await response.json();
112
+
113
+ return {
114
+ props: {
115
+ ...props,
116
+ fetchedData: data,
117
+ },
118
+ };
119
+ };
120
+ ```
121
+
122
+ The `abortSignal` cancels stale requests when props change in the Studio.
123
+
124
+ ## Return value
125
+
126
+ All fields are optional. Returned values override the `<Composition>` props:
127
+
128
+ - `durationInFrames`: Number of frames
129
+ - `width`: Composition width in pixels
130
+ - `height`: Composition height in pixels
131
+ - `fps`: Frames per second
132
+ - `props`: Transformed props passed to the component
133
+ - `defaultOutName`: Default output filename
134
+ - `defaultCodec`: Default codec for rendering
@@ -0,0 +1,81 @@
1
+ ---
2
+ name: can-decode
3
+ description: Check if a video can be decoded by the browser using Mediabunny
4
+ metadata:
5
+ tags: decode, validation, video, audio, compatibility, browser
6
+ ---
7
+
8
+ # Checking if a video can be decoded
9
+
10
+ Use Mediabunny to check if a video can be decoded by the browser before attempting to play it.
11
+
12
+ First, install the right version of Mediabunny:
13
+
14
+ ```bash
15
+ npx remotion add mediabunny
16
+ ```
17
+
18
+ ## The `canDecode()` function
19
+
20
+ This function can be copy-pasted into any project.
21
+
22
+ ```tsx
23
+ import { Input, ALL_FORMATS, UrlSource } from "mediabunny";
24
+
25
+ export const canDecode = async (src: string) => {
26
+ const input = new Input({
27
+ formats: ALL_FORMATS,
28
+ source: new UrlSource(src, {
29
+ getRetryDelay: () => null,
30
+ }),
31
+ });
32
+
33
+ try {
34
+ await input.getFormat();
35
+ } catch {
36
+ return false;
37
+ }
38
+
39
+ const videoTrack = await input.getPrimaryVideoTrack();
40
+ if (videoTrack && !(await videoTrack.canDecode())) {
41
+ return false;
42
+ }
43
+
44
+ const audioTrack = await input.getPrimaryAudioTrack();
45
+ if (audioTrack && !(await audioTrack.canDecode())) {
46
+ return false;
47
+ }
48
+
49
+ return true;
50
+ };
51
+ ```
52
+
53
+ ## Usage
54
+
55
+ ```tsx
56
+ const src = "https://remotion.media/video.mp4";
57
+ const isDecodable = await canDecode(src);
58
+
59
+ if (isDecodable) {
60
+ console.log("Video can be decoded");
61
+ } else {
62
+ console.log("Video cannot be decoded by this browser");
63
+ }
64
+ ```
65
+
66
+ ## Using with Blob
67
+
68
+ For file uploads or drag-and-drop, use `BlobSource`:
69
+
70
+ ```tsx
71
+ import { Input, ALL_FORMATS, BlobSource } from "mediabunny";
72
+
73
+ export const canDecodeBlob = async (blob: Blob) => {
74
+ const input = new Input({
75
+ formats: ALL_FORMATS,
76
+ source: new BlobSource(blob),
77
+ });
78
+
79
+ // Same validation logic as above
80
+ };
81
+ ```
@@ -0,0 +1,120 @@
1
+ ---
2
+ name: charts
3
+ description: Chart and data visualization patterns for Remotion. Use when creating bar charts, pie charts, line charts, stock graphs, or any data-driven animations.
4
+ metadata:
5
+ tags: charts, data, visualization, bar-chart, pie-chart, line-chart, stock-chart, svg-paths, graphs
6
+ ---
7
+
8
+ # Charts in Remotion
9
+
10
+ Create charts using React code - HTML, SVG, and D3.js are all supported.
11
+
12
+ Disable all animations from third party libraries - they cause flickering.
13
+ Drive all animations from `useCurrentFrame()`.
14
+
15
+ ## Bar Chart
16
+
17
+ ```tsx
18
+ const STAGGER_DELAY = 5;
19
+ const frame = useCurrentFrame();
20
+ const { fps } = useVideoConfig();
21
+
22
+ const bars = data.map((item, i) => {
23
+ const height = spring({
24
+ frame,
25
+ fps,
26
+ delay: i * STAGGER_DELAY,
27
+ config: { damping: 200 },
28
+ });
29
+ return <div style={{ height: height * item.value }} />;
30
+ });
31
+ ```
32
+
33
+ ## Pie Chart
34
+
35
+ Animate segments using stroke-dashoffset, starting from 12 o'clock:
36
+
37
+ ```tsx
38
+ const progress = interpolate(frame, [0, 100], [0, 1]);
39
+ const circumference = 2 * Math.PI * radius;
40
+ const segmentLength = (value / total) * circumference;
41
+ const offset = interpolate(progress, [0, 1], [segmentLength, 0]);
42
+
43
+ <circle
44
+ r={radius}
45
+ cx={center}
46
+ cy={center}
47
+ fill="none"
48
+ stroke={color}
49
+ strokeWidth={strokeWidth}
50
+ strokeDasharray={`${segmentLength} ${circumference}`}
51
+ strokeDashoffset={offset}
52
+ transform={`rotate(-90 ${center} ${center})`}
53
+ />;
54
+ ```
55
+
56
+ ## Line Chart / Path Animation
57
+
58
+ Use `@remotion/paths` for animating SVG paths (line charts, stock graphs, signatures).
59
+
60
+ Install: `npx remotion add @remotion/paths`
61
+ Docs: https://remotion.dev/docs/paths.md
62
+
63
+ ### Convert data points to SVG path
64
+
65
+ ```tsx
66
+ type Point = { x: number; y: number };
67
+
68
+ const generateLinePath = (points: Point[]): string => {
69
+ if (points.length < 2) return "";
70
+ return points.map((p, i) => `${i === 0 ? "M" : "L"} ${p.x} ${p.y}`).join(" ");
71
+ };
72
+ ```
73
+
74
+ ### Draw path with animation
75
+
76
+ ```tsx
77
+ import { evolvePath } from "@remotion/paths";
78
+
79
+ const path = "M 100 200 L 200 150 L 300 180 L 400 100";
80
+ const progress = interpolate(frame, [0, 2 * fps], [0, 1], {
81
+ extrapolateLeft: "clamp",
82
+ extrapolateRight: "clamp",
83
+ easing: Easing.out(Easing.quad),
84
+ });
85
+
86
+ const { strokeDasharray, strokeDashoffset } = evolvePath(progress, path);
87
+
88
+ <path
89
+ d={path}
90
+ fill="none"
91
+ stroke="#FF3232"
92
+ strokeWidth={4}
93
+ strokeDasharray={strokeDasharray}
94
+ strokeDashoffset={strokeDashoffset}
95
+ />;
96
+ ```
97
+
98
+ ### Follow path with marker/arrow
99
+
100
+ ```tsx
101
+ import {
102
+ getLength,
103
+ getPointAtLength,
104
+ getTangentAtLength,
105
+ } from "@remotion/paths";
106
+
107
+ const pathLength = getLength(path);
108
+ const point = getPointAtLength(path, progress * pathLength);
109
+ const tangent = getTangentAtLength(path, progress * pathLength);
110
+ const angle = Math.atan2(tangent.y, tangent.x);
111
+
112
+ <g
113
+ style={{
114
+ transform: `translate(${point.x}px, ${point.y}px) rotate(${angle}rad)`,
115
+ transformOrigin: "0 0",
116
+ }}
117
+ >
118
+ <polygon points="0,0 -20,-10 -20,10" fill="#FF3232" />
119
+ </g>;
120
+ ```
@@ -0,0 +1,154 @@
1
+ ---
2
+ name: compositions
3
+ description: Defining compositions, stills, folders, default props and dynamic metadata
4
+ metadata:
5
+ tags: composition, still, folder, props, metadata
6
+ ---
7
+
8
+ A `<Composition>` defines the component, width, height, fps and duration of a renderable video.
9
+
10
+ It normally is placed in the `src/Root.tsx` file.
11
+
12
+ ```tsx
13
+ import { Composition } from "remotion";
14
+ import { MyComposition } from "./MyComposition";
15
+
16
+ export const RemotionRoot = () => {
17
+ return (
18
+ <Composition
19
+ id="MyComposition"
20
+ component={MyComposition}
21
+ durationInFrames={100}
22
+ fps={30}
23
+ width={1080}
24
+ height={1080}
25
+ />
26
+ );
27
+ };
28
+ ```
29
+
30
+ ## Default Props
31
+
32
+ Pass `defaultProps` to provide initial values for your component.
33
+ Values must be JSON-serializable (`Date`, `Map`, `Set`, and `staticFile()` are supported).
34
+
35
+ ```tsx
36
+ import { Composition } from "remotion";
37
+ import { MyComposition, MyCompositionProps } from "./MyComposition";
38
+
39
+ export const RemotionRoot = () => {
40
+ return (
41
+ <Composition
42
+ id="MyComposition"
43
+ component={MyComposition}
44
+ durationInFrames={100}
45
+ fps={30}
46
+ width={1080}
47
+ height={1080}
48
+ defaultProps={
49
+ {
50
+ title: "Hello World",
51
+ color: "#ff0000",
52
+ } satisfies MyCompositionProps
53
+ }
54
+ />
55
+ );
56
+ };
57
+ ```
58
+
59
+ Use `type` declarations for props rather than `interface` to ensure `defaultProps` type safety.
60
+
61
+ ## Folders
62
+
63
+ Use `<Folder>` to organize compositions in the sidebar.
64
+ Folder names can only contain letters, numbers, and hyphens.
65
+
66
+ ```tsx
67
+ import { Composition, Folder } from "remotion";
68
+
69
+ export const RemotionRoot = () => {
70
+ return (
71
+ <>
72
+ <Folder name="Marketing">
73
+ <Composition id="Promo" /* ... */ />
74
+ <Composition id="Ad" /* ... */ />
75
+ </Folder>
76
+ <Folder name="Social">
77
+ <Folder name="Instagram">
78
+ <Composition id="Story" /* ... */ />
79
+ <Composition id="Reel" /* ... */ />
80
+ </Folder>
81
+ </Folder>
82
+ </>
83
+ );
84
+ };
85
+ ```
86
+
87
+ ## Stills
88
+
89
+ Use `<Still>` for single-frame images. It does not require `durationInFrames` or `fps`.
90
+
91
+ ```tsx
92
+ import { Still } from "remotion";
93
+ import { Thumbnail } from "./Thumbnail";
94
+
95
+ export const RemotionRoot = () => {
96
+ return (
97
+ <Still id="Thumbnail" component={Thumbnail} width={1280} height={720} />
98
+ );
99
+ };
100
+ ```
101
+
102
+ ## Calculate Metadata
103
+
104
+ Use `calculateMetadata` to make dimensions, duration, or props dynamic based on data.
105
+
106
+ ```tsx
107
+ import { Composition, CalculateMetadataFunction } from "remotion";
108
+ import { MyComposition, MyCompositionProps } from "./MyComposition";
109
+
110
+ const calculateMetadata: CalculateMetadataFunction<
111
+ MyCompositionProps
112
+ > = async ({ props, abortSignal }) => {
113
+ const data = await fetch(`https://api.example.com/video/${props.videoId}`, {
114
+ signal: abortSignal,
115
+ }).then((res) => res.json());
116
+
117
+ return {
118
+ durationInFrames: Math.ceil(data.duration * 30),
119
+ props: {
120
+ ...props,
121
+ videoUrl: data.url,
122
+ },
123
+ };
124
+ };
125
+
126
+ export const RemotionRoot = () => {
127
+ return (
128
+ <Composition
129
+ id="MyComposition"
130
+ component={MyComposition}
131
+ durationInFrames={100} // Placeholder, will be overridden
132
+ fps={30}
133
+ width={1080}
134
+ height={1080}
135
+ defaultProps={{ videoId: "abc123" }}
136
+ calculateMetadata={calculateMetadata}
137
+ />
138
+ );
139
+ };
140
+ ```
141
+
142
+ The function can return `props`, `durationInFrames`, `width`, `height`, `fps`, and codec-related defaults. It runs once before rendering begins.
143
+
144
+ ## Nesting compositions within another
145
+
146
+ To add a composition within another composition, you can use the `<Sequence>` component with a `width` and `height` prop to specify the size of the composition.
147
+
148
+ ```tsx
149
+ <AbsoluteFill>
150
+ <Sequence width={COMPOSITION_WIDTH} height={COMPOSITION_HEIGHT}>
151
+ <CompositionComponent />
152
+ </Sequence>
153
+ </AbsoluteFill>
154
+ ```
@@ -0,0 +1,184 @@
1
+ ---
2
+ name: display-captions
3
+ description: Displaying captions in Remotion with TikTok-style pages and word highlighting
4
+ metadata:
5
+ tags: captions, subtitles, display, tiktok, highlight
6
+ ---
7
+
8
+ # Displaying captions in Remotion
9
+
10
+ This guide explains how to display captions in Remotion, assuming you already have captions in the [`Caption`](https://www.remotion.dev/docs/captions/caption) format.
11
+
12
+ ## Prerequisites
13
+
14
+ Read [Transcribing audio](transcribe-captions.md) for how to generate captions.
15
+
16
+ First, the [`@remotion/captions`](https://www.remotion.dev/docs/captions) package needs to be installed.
17
+ If it is not installed, use the following command:
18
+
19
+ ```bash
20
+ npx remotion add @remotion/captions
21
+ ```
22
+
23
+ ## Fetching captions
24
+
25
+ First, fetch your captions JSON file. Use [`useDelayRender()`](https://www.remotion.dev/docs/use-delay-render) to hold the render until the captions are loaded:
26
+
27
+ ```tsx
28
+ import { useState, useEffect, useCallback } from "react";
29
+ import { AbsoluteFill, staticFile, useDelayRender } from "remotion";
30
+ import type { Caption } from "@remotion/captions";
31
+
32
+ export const MyComponent: React.FC = () => {
33
+ const [captions, setCaptions] = useState<Caption[] | null>(null);
34
+ const { delayRender, continueRender, cancelRender } = useDelayRender();
35
+ const [handle] = useState(() => delayRender());
36
+
37
+ const fetchCaptions = useCallback(async () => {
38
+ try {
39
+ // Assuming captions.json is in the public/ folder.
40
+ const response = await fetch(staticFile("captions123.json"));
41
+ const data = await response.json();
42
+ setCaptions(data);
43
+ continueRender(handle);
44
+ } catch (e) {
45
+ cancelRender(e);
46
+ }
47
+ }, [continueRender, cancelRender, handle]);
48
+
49
+ useEffect(() => {
50
+ fetchCaptions();
51
+ }, [fetchCaptions]);
52
+
53
+ if (!captions) {
54
+ return null;
55
+ }
56
+
57
+ return <AbsoluteFill>{/* Render captions here */}</AbsoluteFill>;
58
+ };
59
+ ```
60
+
61
+ ## Creating pages
62
+
63
+ Use `createTikTokStyleCaptions()` to group captions into pages. The `combineTokensWithinMilliseconds` option controls how many words appear at once:
64
+
65
+ ```tsx
66
+ import { useMemo } from "react";
67
+ import { createTikTokStyleCaptions } from "@remotion/captions";
68
+ import type { Caption } from "@remotion/captions";
69
+
70
+ // How often captions should switch (in milliseconds)
71
+ // Higher values = more words per page
72
+ // Lower values = fewer words (more word-by-word)
73
+ const SWITCH_CAPTIONS_EVERY_MS = 1200;
74
+
75
+ const { pages } = useMemo(() => {
76
+ return createTikTokStyleCaptions({
77
+ captions,
78
+ combineTokensWithinMilliseconds: SWITCH_CAPTIONS_EVERY_MS,
79
+ });
80
+ }, [captions]);
81
+ ```
82
+
83
+ ## Rendering with Sequences
84
+
85
+ Map over the pages and render each one in a `<Sequence>`. Calculate the start frame and duration from the page timing:
86
+
87
+ ```tsx
88
+ import { Sequence, useVideoConfig, AbsoluteFill } from "remotion";
89
+ import type { TikTokPage } from "@remotion/captions";
90
+
91
+ const CaptionedContent: React.FC = () => {
92
+ const { fps } = useVideoConfig();
93
+
94
+ return (
95
+ <AbsoluteFill>
96
+ {pages.map((page, index) => {
97
+ const nextPage = pages[index + 1] ?? null;
98
+ const startFrame = (page.startMs / 1000) * fps;
99
+ const endFrame = Math.min(
100
+ nextPage ? (nextPage.startMs / 1000) * fps : Infinity,
101
+ startFrame + (SWITCH_CAPTIONS_EVERY_MS / 1000) * fps,
102
+ );
103
+ const durationInFrames = endFrame - startFrame;
104
+
105
+ if (durationInFrames <= 0) {
106
+ return null;
107
+ }
108
+
109
+ return (
110
+ <Sequence
111
+ key={index}
112
+ from={startFrame}
113
+ durationInFrames={durationInFrames}
114
+ >
115
+ <CaptionPage page={page} />
116
+ </Sequence>
117
+ );
118
+ })}
119
+ </AbsoluteFill>
120
+ );
121
+ };
122
+ ```
123
+
124
+ ## White-space preservation
125
+
126
+ The captions are whitespace sensitive. You should include spaces in the `text` field before each word. Use `whiteSpace: "pre"` to preserve the whitespace in the captions.
127
+
128
+ ## Separate component for captions
129
+
130
+ Put captioning logic in a separate component.
131
+ Make a new file for it.
132
+
133
+ ## Word highlighting
134
+
135
+ A caption page contains `tokens` which you can use to highlight the currently spoken word:
136
+
137
+ ```tsx
138
+ import { AbsoluteFill, useCurrentFrame, useVideoConfig } from "remotion";
139
+ import type { TikTokPage } from "@remotion/captions";
140
+
141
+ const HIGHLIGHT_COLOR = "#39E508";
142
+
143
+ const CaptionPage: React.FC<{ page: TikTokPage }> = ({ page }) => {
144
+ const frame = useCurrentFrame();
145
+ const { fps } = useVideoConfig();
146
+
147
+ // Current time relative to the start of the sequence
148
+ const currentTimeMs = (frame / fps) * 1000;
149
+ // Convert to absolute time by adding the page start
150
+ const absoluteTimeMs = page.startMs + currentTimeMs;
151
+
152
+ return (
153
+ <AbsoluteFill style={{ justifyContent: "center", alignItems: "center" }}>
154
+ <div style={{ fontSize: 80, fontWeight: "bold", whiteSpace: "pre" }}>
155
+ {page.tokens.map((token) => {
156
+ const isActive =
157
+ token.fromMs <= absoluteTimeMs && token.toMs > absoluteTimeMs;
158
+
159
+ return (
160
+ <span
161
+ key={token.fromMs}
162
+ style={{ color: isActive ? HIGHLIGHT_COLOR : "white" }}
163
+ >
164
+ {token.text}
165
+ </span>
166
+ );
167
+ })}
168
+ </div>
169
+ </AbsoluteFill>
170
+ );
171
+ };
172
+ ```
173
+
174
+ ## Display captions alongside video content
175
+
176
+ By default, put the captions alongside the video content, so the captions are in sync.
177
+ For each video, make a new captions JSON file.
178
+
179
+ ```tsx
180
+ <AbsoluteFill>
181
+ <Video src={staticFile("video.mp4")} />
182
+ <CaptionPage page={page} />
183
+ </AbsoluteFill>
184
+ ```