@kolbo/kolbo-code-linux-x64-baseline 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.
- package/bin/kolbo +0 -0
- package/package.json +14 -0
- package/skills/frontend-design/SKILL.md +42 -0
- package/skills/kolbo/SKILL.md +216 -0
- package/skills/remotion-best-practices/SKILL.md +61 -0
- package/skills/remotion-best-practices/rules/3d.md +86 -0
- package/skills/remotion-best-practices/rules/animations.md +27 -0
- package/skills/remotion-best-practices/rules/assets/charts-bar-chart.tsx +173 -0
- package/skills/remotion-best-practices/rules/assets/text-animations-typewriter.tsx +100 -0
- package/skills/remotion-best-practices/rules/assets/text-animations-word-highlight.tsx +103 -0
- package/skills/remotion-best-practices/rules/assets.md +78 -0
- package/skills/remotion-best-practices/rules/audio-visualization.md +198 -0
- package/skills/remotion-best-practices/rules/audio.md +169 -0
- package/skills/remotion-best-practices/rules/calculate-metadata.md +134 -0
- package/skills/remotion-best-practices/rules/can-decode.md +81 -0
- package/skills/remotion-best-practices/rules/charts.md +120 -0
- package/skills/remotion-best-practices/rules/compositions.md +154 -0
- package/skills/remotion-best-practices/rules/display-captions.md +184 -0
- package/skills/remotion-best-practices/rules/extract-frames.md +229 -0
- package/skills/remotion-best-practices/rules/ffmpeg.md +38 -0
- package/skills/remotion-best-practices/rules/fonts.md +152 -0
- package/skills/remotion-best-practices/rules/get-audio-duration.md +58 -0
- package/skills/remotion-best-practices/rules/get-video-dimensions.md +68 -0
- package/skills/remotion-best-practices/rules/get-video-duration.md +60 -0
- package/skills/remotion-best-practices/rules/gifs.md +141 -0
- package/skills/remotion-best-practices/rules/images.md +134 -0
- package/skills/remotion-best-practices/rules/import-srt-captions.md +69 -0
- package/skills/remotion-best-practices/rules/light-leaks.md +73 -0
- package/skills/remotion-best-practices/rules/lottie.md +70 -0
- package/skills/remotion-best-practices/rules/maps.md +412 -0
- package/skills/remotion-best-practices/rules/measuring-dom-nodes.md +34 -0
- package/skills/remotion-best-practices/rules/measuring-text.md +140 -0
- package/skills/remotion-best-practices/rules/parameters.md +109 -0
- package/skills/remotion-best-practices/rules/sequencing.md +118 -0
- package/skills/remotion-best-practices/rules/sfx.md +30 -0
- package/skills/remotion-best-practices/rules/subtitles.md +36 -0
- package/skills/remotion-best-practices/rules/tailwind.md +11 -0
- package/skills/remotion-best-practices/rules/text-animations.md +20 -0
- package/skills/remotion-best-practices/rules/timing.md +179 -0
- package/skills/remotion-best-practices/rules/transcribe-captions.md +70 -0
- package/skills/remotion-best-practices/rules/transitions.md +197 -0
- package/skills/remotion-best-practices/rules/transparent-videos.md +106 -0
- package/skills/remotion-best-practices/rules/trimming.md +51 -0
- package/skills/remotion-best-practices/rules/videos.md +171 -0
- package/skills/remotion-best-practices/rules/voiceover.md +99 -0
- package/skills/video-production/SKILL.md +152 -0
- package/skills/youtube-clipper/SKILL.md +187 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gif
|
|
3
|
+
description: Displaying GIFs, APNG, AVIF and WebP in Remotion
|
|
4
|
+
metadata:
|
|
5
|
+
tags: gif, animation, images, animated, apng, avif, webp
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Using Animated images in Remotion
|
|
9
|
+
|
|
10
|
+
## Basic usage
|
|
11
|
+
|
|
12
|
+
Use `<AnimatedImage>` to display a GIF, APNG, AVIF or WebP image synchronized with Remotion's timeline:
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { AnimatedImage, staticFile } from "remotion";
|
|
16
|
+
|
|
17
|
+
export const MyComposition = () => {
|
|
18
|
+
return (
|
|
19
|
+
<AnimatedImage src={staticFile("animation.gif")} width={500} height={500} />
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Remote URLs are also supported (must have CORS enabled):
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
<AnimatedImage
|
|
28
|
+
src="https://example.com/animation.gif"
|
|
29
|
+
width={500}
|
|
30
|
+
height={500}
|
|
31
|
+
/>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Sizing and fit
|
|
35
|
+
|
|
36
|
+
Control how the image fills its container with the `fit` prop:
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
// Stretch to fill (default)
|
|
40
|
+
<AnimatedImage src={staticFile("animation.gif")} width={500} height={300} fit="fill" />
|
|
41
|
+
|
|
42
|
+
// Maintain aspect ratio, fit inside container
|
|
43
|
+
<AnimatedImage src={staticFile("animation.gif")} width={500} height={300} fit="contain" />
|
|
44
|
+
|
|
45
|
+
// Fill container, crop if needed
|
|
46
|
+
<AnimatedImage src={staticFile("animation.gif")} width={500} height={300} fit="cover" />
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Playback speed
|
|
50
|
+
|
|
51
|
+
Use `playbackRate` to control the animation speed:
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
<AnimatedImage src={staticFile("animation.gif")} width={500} height={500} playbackRate={2} /> {/* 2x speed */}
|
|
55
|
+
<AnimatedImage src={staticFile("animation.gif")} width={500} height={500} playbackRate={0.5} /> {/* Half speed */}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Looping behavior
|
|
59
|
+
|
|
60
|
+
Control what happens when the animation finishes:
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
// Loop indefinitely (default)
|
|
64
|
+
<AnimatedImage src={staticFile("animation.gif")} width={500} height={500} loopBehavior="loop" />
|
|
65
|
+
|
|
66
|
+
// Play once, show final frame
|
|
67
|
+
<AnimatedImage src={staticFile("animation.gif")} width={500} height={500} loopBehavior="pause-after-finish" />
|
|
68
|
+
|
|
69
|
+
// Play once, then clear canvas
|
|
70
|
+
<AnimatedImage src={staticFile("animation.gif")} width={500} height={500} loopBehavior="clear-after-finish" />
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Styling
|
|
74
|
+
|
|
75
|
+
Use the `style` prop for additional CSS (use `width` and `height` props for sizing):
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
<AnimatedImage
|
|
79
|
+
src={staticFile("animation.gif")}
|
|
80
|
+
width={500}
|
|
81
|
+
height={500}
|
|
82
|
+
style={{
|
|
83
|
+
borderRadius: 20,
|
|
84
|
+
position: "absolute",
|
|
85
|
+
top: 100,
|
|
86
|
+
left: 50,
|
|
87
|
+
}}
|
|
88
|
+
/>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Getting GIF duration
|
|
92
|
+
|
|
93
|
+
Use `getGifDurationInSeconds()` from `@remotion/gif` to get the duration of a GIF.
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npx remotion add @remotion/gif
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
import { getGifDurationInSeconds } from "@remotion/gif";
|
|
101
|
+
import { staticFile } from "remotion";
|
|
102
|
+
|
|
103
|
+
const duration = await getGifDurationInSeconds(staticFile("animation.gif"));
|
|
104
|
+
console.log(duration); // e.g. 2.5
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
This is useful for setting the composition duration to match the GIF:
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
import { getGifDurationInSeconds } from "@remotion/gif";
|
|
111
|
+
import { staticFile, CalculateMetadataFunction } from "remotion";
|
|
112
|
+
|
|
113
|
+
const calculateMetadata: CalculateMetadataFunction = async () => {
|
|
114
|
+
const duration = await getGifDurationInSeconds(staticFile("animation.gif"));
|
|
115
|
+
return {
|
|
116
|
+
durationInFrames: Math.ceil(duration * 30),
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Alternative
|
|
122
|
+
|
|
123
|
+
If `<AnimatedImage>` does not work (only supported in Chrome and Firefox), you can use `<Gif>` from `@remotion/gif` instead.
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
npx remotion add @remotion/gif # If project uses npm
|
|
127
|
+
bunx remotion add @remotion/gif # If project uses bun
|
|
128
|
+
yarn remotion add @remotion/gif # If project uses yarn
|
|
129
|
+
pnpm exec remotion add @remotion/gif # If project uses pnpm
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
import { Gif } from "@remotion/gif";
|
|
134
|
+
import { staticFile } from "remotion";
|
|
135
|
+
|
|
136
|
+
export const MyComposition = () => {
|
|
137
|
+
return <Gif src={staticFile("animation.gif")} width={500} height={500} />;
|
|
138
|
+
};
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The `<Gif>` component has the same props as `<AnimatedImage>` but only supports GIF files.
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: images
|
|
3
|
+
description: Embedding images in Remotion using the <Img> component
|
|
4
|
+
metadata:
|
|
5
|
+
tags: images, img, staticFile, png, jpg, svg, webp
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Using images in Remotion
|
|
9
|
+
|
|
10
|
+
## The `<Img>` component
|
|
11
|
+
|
|
12
|
+
Always use the `<Img>` component from `remotion` to display images:
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { Img, staticFile } from "remotion";
|
|
16
|
+
|
|
17
|
+
export const MyComposition = () => {
|
|
18
|
+
return <Img src={staticFile("photo.png")} />;
|
|
19
|
+
};
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Important restrictions
|
|
23
|
+
|
|
24
|
+
**You MUST use the `<Img>` component from `remotion`.** Do not use:
|
|
25
|
+
|
|
26
|
+
- Native HTML `<img>` elements
|
|
27
|
+
- Next.js `<Image>` component
|
|
28
|
+
- CSS `background-image`
|
|
29
|
+
|
|
30
|
+
The `<Img>` component ensures images are fully loaded before rendering, preventing flickering and blank frames during video export.
|
|
31
|
+
|
|
32
|
+
## Local images with staticFile()
|
|
33
|
+
|
|
34
|
+
Place images in the `public/` folder and use `staticFile()` to reference them:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
my-video/
|
|
38
|
+
├─ public/
|
|
39
|
+
│ ├─ logo.png
|
|
40
|
+
│ ├─ avatar.jpg
|
|
41
|
+
│ └─ icon.svg
|
|
42
|
+
├─ src/
|
|
43
|
+
├─ package.json
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
import { Img, staticFile } from "remotion";
|
|
48
|
+
|
|
49
|
+
<Img src={staticFile("logo.png")} />;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Remote images
|
|
53
|
+
|
|
54
|
+
Remote URLs can be used directly without `staticFile()`:
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
<Img src="https://example.com/image.png" />
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Ensure remote images have CORS enabled.
|
|
61
|
+
|
|
62
|
+
For animated GIFs, use the `<Gif>` component from `@remotion/gif` instead.
|
|
63
|
+
|
|
64
|
+
## Sizing and positioning
|
|
65
|
+
|
|
66
|
+
Use the `style` prop to control size and position:
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
<Img
|
|
70
|
+
src={staticFile("photo.png")}
|
|
71
|
+
style={{
|
|
72
|
+
width: 500,
|
|
73
|
+
height: 300,
|
|
74
|
+
position: "absolute",
|
|
75
|
+
top: 100,
|
|
76
|
+
left: 50,
|
|
77
|
+
objectFit: "cover",
|
|
78
|
+
}}
|
|
79
|
+
/>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Dynamic image paths
|
|
83
|
+
|
|
84
|
+
Use template literals for dynamic file references:
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
import { Img, staticFile, useCurrentFrame } from "remotion";
|
|
88
|
+
|
|
89
|
+
const frame = useCurrentFrame();
|
|
90
|
+
|
|
91
|
+
// Image sequence
|
|
92
|
+
<Img src={staticFile(`frames/frame${frame}.png`)} />
|
|
93
|
+
|
|
94
|
+
// Selecting based on props
|
|
95
|
+
<Img src={staticFile(`avatars/${props.userId}.png`)} />
|
|
96
|
+
|
|
97
|
+
// Conditional images
|
|
98
|
+
<Img src={staticFile(`icons/${isActive ? "active" : "inactive"}.svg`)} />
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
This pattern is useful for:
|
|
102
|
+
|
|
103
|
+
- Image sequences (frame-by-frame animations)
|
|
104
|
+
- User-specific avatars or profile images
|
|
105
|
+
- Theme-based icons
|
|
106
|
+
- State-dependent graphics
|
|
107
|
+
|
|
108
|
+
## Getting image dimensions
|
|
109
|
+
|
|
110
|
+
Use `getImageDimensions()` to get the dimensions of an image:
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
import { getImageDimensions, staticFile } from "remotion";
|
|
114
|
+
|
|
115
|
+
const { width, height } = await getImageDimensions(staticFile("photo.png"));
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
This is useful for calculating aspect ratios or sizing compositions:
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
import {
|
|
122
|
+
getImageDimensions,
|
|
123
|
+
staticFile,
|
|
124
|
+
CalculateMetadataFunction,
|
|
125
|
+
} from "remotion";
|
|
126
|
+
|
|
127
|
+
const calculateMetadata: CalculateMetadataFunction = async () => {
|
|
128
|
+
const { width, height } = await getImageDimensions(staticFile("photo.png"));
|
|
129
|
+
return {
|
|
130
|
+
width,
|
|
131
|
+
height,
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
```
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: import-srt-captions
|
|
3
|
+
description: Importing .srt subtitle files into Remotion using @remotion/captions
|
|
4
|
+
metadata:
|
|
5
|
+
tags: captions, subtitles, srt, import, parse
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Importing .srt subtitles into Remotion
|
|
9
|
+
|
|
10
|
+
If you have an existing `.srt` subtitle file, you can import it into Remotion using `parseSrt()` from `@remotion/captions`.
|
|
11
|
+
|
|
12
|
+
If you don't have a .srt file, read [Transcribing audio](transcribe-captions.md) for how to generate captions instead.
|
|
13
|
+
|
|
14
|
+
## Prerequisites
|
|
15
|
+
|
|
16
|
+
First, the @remotion/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 # If project uses npm
|
|
21
|
+
bunx remotion add @remotion/captions # If project uses bun
|
|
22
|
+
yarn remotion add @remotion/captions # If project uses yarn
|
|
23
|
+
pnpm exec remotion add @remotion/captions # If project uses pnpm
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Reading an .srt file
|
|
27
|
+
|
|
28
|
+
Use `staticFile()` to reference an `.srt` file in your `public` folder, then fetch and parse it:
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { useState, useEffect, useCallback } from "react";
|
|
32
|
+
import { AbsoluteFill, staticFile, useDelayRender } from "remotion";
|
|
33
|
+
import { parseSrt } from "@remotion/captions";
|
|
34
|
+
import type { Caption } from "@remotion/captions";
|
|
35
|
+
|
|
36
|
+
export const MyComponent: React.FC = () => {
|
|
37
|
+
const [captions, setCaptions] = useState<Caption[] | null>(null);
|
|
38
|
+
const { delayRender, continueRender, cancelRender } = useDelayRender();
|
|
39
|
+
const [handle] = useState(() => delayRender());
|
|
40
|
+
|
|
41
|
+
const fetchCaptions = useCallback(async () => {
|
|
42
|
+
try {
|
|
43
|
+
const response = await fetch(staticFile("subtitles.srt"));
|
|
44
|
+
const text = await response.text();
|
|
45
|
+
const { captions: parsed } = parseSrt({ input: text });
|
|
46
|
+
setCaptions(parsed);
|
|
47
|
+
continueRender(handle);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
cancelRender(e);
|
|
50
|
+
}
|
|
51
|
+
}, [continueRender, cancelRender, handle]);
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
fetchCaptions();
|
|
55
|
+
}, [fetchCaptions]);
|
|
56
|
+
|
|
57
|
+
if (!captions) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return <AbsoluteFill>{/* Use captions here */}</AbsoluteFill>;
|
|
62
|
+
};
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Remote URLs are also supported - you can `fetch()` a remote file via URL instead of using `staticFile()`.
|
|
66
|
+
|
|
67
|
+
## Using imported captions
|
|
68
|
+
|
|
69
|
+
Once parsed, the captions are in the `Caption` format and can be used with all `@remotion/captions` utilities.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: light-leaks
|
|
3
|
+
description: Light leak overlay effects for Remotion using @remotion/light-leaks.
|
|
4
|
+
metadata:
|
|
5
|
+
tags: light-leaks, overlays, effects, transitions
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Light Leaks
|
|
9
|
+
|
|
10
|
+
This only works from Remotion 4.0.415 and up. Use `npx remotion versions` to check your Remotion version and `npx remotion upgrade` to upgrade your Remotion version.
|
|
11
|
+
|
|
12
|
+
`<LightLeak>` from `@remotion/light-leaks` renders a WebGL-based light leak effect. It reveals during the first half of its duration and retracts during the second half.
|
|
13
|
+
|
|
14
|
+
Typically used inside a `<TransitionSeries.Overlay>` to play over the cut point between two scenes. See the **transitions** rule for `<TransitionSeries>` and overlay usage.
|
|
15
|
+
|
|
16
|
+
## Prerequisites
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npx remotion add @remotion/light-leaks
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Basic usage with TransitionSeries
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { TransitionSeries } from "@remotion/transitions";
|
|
26
|
+
import { LightLeak } from "@remotion/light-leaks";
|
|
27
|
+
|
|
28
|
+
<TransitionSeries>
|
|
29
|
+
<TransitionSeries.Sequence durationInFrames={60}>
|
|
30
|
+
<SceneA />
|
|
31
|
+
</TransitionSeries.Sequence>
|
|
32
|
+
<TransitionSeries.Overlay durationInFrames={30}>
|
|
33
|
+
<LightLeak />
|
|
34
|
+
</TransitionSeries.Overlay>
|
|
35
|
+
<TransitionSeries.Sequence durationInFrames={60}>
|
|
36
|
+
<SceneB />
|
|
37
|
+
</TransitionSeries.Sequence>
|
|
38
|
+
</TransitionSeries>;
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Props
|
|
42
|
+
|
|
43
|
+
- `durationInFrames?` — defaults to the parent sequence/composition duration. The effect reveals during the first half and retracts during the second half.
|
|
44
|
+
- `seed?` — determines the shape of the light leak pattern. Different seeds produce different patterns. Default: `0`.
|
|
45
|
+
- `hueShift?` — rotates the hue in degrees (`0`–`360`). Default: `0` (yellow-to-orange). `120` = green, `240` = blue.
|
|
46
|
+
|
|
47
|
+
## Customizing the look
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { LightLeak } from "@remotion/light-leaks";
|
|
51
|
+
|
|
52
|
+
// Blue-tinted light leak with a different pattern
|
|
53
|
+
<LightLeak seed={5} hueShift={240} />;
|
|
54
|
+
|
|
55
|
+
// Green-tinted light leak
|
|
56
|
+
<LightLeak seed={2} hueShift={120} />;
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Standalone usage
|
|
60
|
+
|
|
61
|
+
`<LightLeak>` can also be used outside of `<TransitionSeries>`, for example as a decorative overlay in any composition:
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import { AbsoluteFill } from "remotion";
|
|
65
|
+
import { LightLeak } from "@remotion/light-leaks";
|
|
66
|
+
|
|
67
|
+
const MyComp: React.FC = () => (
|
|
68
|
+
<AbsoluteFill>
|
|
69
|
+
<MyContent />
|
|
70
|
+
<LightLeak durationInFrames={60} seed={3} />
|
|
71
|
+
</AbsoluteFill>
|
|
72
|
+
);
|
|
73
|
+
```
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: lottie
|
|
3
|
+
description: Embedding Lottie animations in Remotion.
|
|
4
|
+
metadata:
|
|
5
|
+
category: Animation
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Using Lottie Animations in Remotion
|
|
9
|
+
|
|
10
|
+
## Prerequisites
|
|
11
|
+
|
|
12
|
+
First, the @remotion/lottie package needs to be installed.
|
|
13
|
+
If it is not, use the following command:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx remotion add @remotion/lottie # If project uses npm
|
|
17
|
+
bunx remotion add @remotion/lottie # If project uses bun
|
|
18
|
+
yarn remotion add @remotion/lottie # If project uses yarn
|
|
19
|
+
pnpm exec remotion add @remotion/lottie # If project uses pnpm
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Displaying a Lottie file
|
|
23
|
+
|
|
24
|
+
To import a Lottie animation:
|
|
25
|
+
|
|
26
|
+
- Fetch the Lottie asset
|
|
27
|
+
- Wrap the loading process in `delayRender()` and `continueRender()`
|
|
28
|
+
- Save the animation data in a state
|
|
29
|
+
- Render the Lottie animation using the `Lottie` component from the `@remotion/lottie` package
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { Lottie, LottieAnimationData } from "@remotion/lottie";
|
|
33
|
+
import { useEffect, useState } from "react";
|
|
34
|
+
import { cancelRender, continueRender, delayRender } from "remotion";
|
|
35
|
+
|
|
36
|
+
export const MyAnimation = () => {
|
|
37
|
+
const [handle] = useState(() => delayRender("Loading Lottie animation"));
|
|
38
|
+
|
|
39
|
+
const [animationData, setAnimationData] =
|
|
40
|
+
useState<LottieAnimationData | null>(null);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
fetch("https://assets4.lottiefiles.com/packages/lf20_zyquagfl.json")
|
|
44
|
+
.then((data) => data.json())
|
|
45
|
+
.then((json) => {
|
|
46
|
+
setAnimationData(json);
|
|
47
|
+
continueRender(handle);
|
|
48
|
+
})
|
|
49
|
+
.catch((err) => {
|
|
50
|
+
cancelRender(err);
|
|
51
|
+
});
|
|
52
|
+
}, [handle]);
|
|
53
|
+
|
|
54
|
+
if (!animationData) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return <Lottie animationData={animationData} />;
|
|
59
|
+
};
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Styling and animating
|
|
63
|
+
|
|
64
|
+
Lottie supports the `style` prop to allow styles and animations:
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
return (
|
|
68
|
+
<Lottie animationData={animationData} style={{ width: 400, height: 400 }} />
|
|
69
|
+
);
|
|
70
|
+
```
|