@kolbo/kolbo-code-linux-arm64-musl 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,229 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: extract-frames
|
|
3
|
+
description: Extract frames from videos at specific timestamps using Mediabunny
|
|
4
|
+
metadata:
|
|
5
|
+
tags: frames, extract, video, thumbnail, filmstrip, canvas
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Extracting frames from videos
|
|
9
|
+
|
|
10
|
+
Use Mediabunny to extract frames from videos at specific timestamps. This is useful for generating thumbnails, filmstrips, or processing individual frames.
|
|
11
|
+
|
|
12
|
+
## The `extractFrames()` function
|
|
13
|
+
|
|
14
|
+
This function can be copy-pasted into any project.
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import {
|
|
18
|
+
ALL_FORMATS,
|
|
19
|
+
Input,
|
|
20
|
+
UrlSource,
|
|
21
|
+
VideoSample,
|
|
22
|
+
VideoSampleSink,
|
|
23
|
+
} from "mediabunny";
|
|
24
|
+
|
|
25
|
+
type Options = {
|
|
26
|
+
track: { width: number; height: number };
|
|
27
|
+
container: string;
|
|
28
|
+
durationInSeconds: number | null;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type ExtractFramesTimestampsInSecondsFn = (
|
|
32
|
+
options: Options,
|
|
33
|
+
) => Promise<number[]> | number[];
|
|
34
|
+
|
|
35
|
+
export type ExtractFramesProps = {
|
|
36
|
+
src: string;
|
|
37
|
+
timestampsInSeconds: number[] | ExtractFramesTimestampsInSecondsFn;
|
|
38
|
+
onVideoSample: (sample: VideoSample) => void;
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export async function extractFrames({
|
|
43
|
+
src,
|
|
44
|
+
timestampsInSeconds,
|
|
45
|
+
onVideoSample,
|
|
46
|
+
signal,
|
|
47
|
+
}: ExtractFramesProps): Promise<void> {
|
|
48
|
+
using input = new Input({
|
|
49
|
+
formats: ALL_FORMATS,
|
|
50
|
+
source: new UrlSource(src),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const [durationInSeconds, format, videoTrack] = await Promise.all([
|
|
54
|
+
input.computeDuration(),
|
|
55
|
+
input.getFormat(),
|
|
56
|
+
input.getPrimaryVideoTrack(),
|
|
57
|
+
]);
|
|
58
|
+
|
|
59
|
+
if (!videoTrack) {
|
|
60
|
+
throw new Error("No video track found in the input");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (signal?.aborted) {
|
|
64
|
+
throw new Error("Aborted");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const timestamps =
|
|
68
|
+
typeof timestampsInSeconds === "function"
|
|
69
|
+
? await timestampsInSeconds({
|
|
70
|
+
track: {
|
|
71
|
+
width: videoTrack.displayWidth,
|
|
72
|
+
height: videoTrack.displayHeight,
|
|
73
|
+
},
|
|
74
|
+
container: format.name,
|
|
75
|
+
durationInSeconds,
|
|
76
|
+
})
|
|
77
|
+
: timestampsInSeconds;
|
|
78
|
+
|
|
79
|
+
if (timestamps.length === 0) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (signal?.aborted) {
|
|
84
|
+
throw new Error("Aborted");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const sink = new VideoSampleSink(videoTrack);
|
|
88
|
+
|
|
89
|
+
for await (using videoSample of sink.samplesAtTimestamps(timestamps)) {
|
|
90
|
+
if (signal?.aborted) {
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!videoSample) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
onVideoSample(videoSample);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Basic usage
|
|
104
|
+
|
|
105
|
+
Extract frames at specific timestamps:
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
await extractFrames({
|
|
109
|
+
src: "https://remotion.media/video.mp4",
|
|
110
|
+
timestampsInSeconds: [0, 1, 2, 3, 4],
|
|
111
|
+
onVideoSample: (sample) => {
|
|
112
|
+
const canvas = document.createElement("canvas");
|
|
113
|
+
canvas.width = sample.displayWidth;
|
|
114
|
+
canvas.height = sample.displayHeight;
|
|
115
|
+
const ctx = canvas.getContext("2d");
|
|
116
|
+
sample.draw(ctx!, 0, 0);
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Creating a filmstrip
|
|
122
|
+
|
|
123
|
+
Use a callback function to dynamically calculate timestamps based on video metadata:
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
const canvasWidth = 500;
|
|
127
|
+
const canvasHeight = 80;
|
|
128
|
+
const fromSeconds = 0;
|
|
129
|
+
const toSeconds = 10;
|
|
130
|
+
|
|
131
|
+
await extractFrames({
|
|
132
|
+
src: "https://remotion.media/video.mp4",
|
|
133
|
+
timestampsInSeconds: async ({ track, durationInSeconds }) => {
|
|
134
|
+
const aspectRatio = track.width / track.height;
|
|
135
|
+
const amountOfFramesFit = Math.ceil(
|
|
136
|
+
canvasWidth / (canvasHeight * aspectRatio),
|
|
137
|
+
);
|
|
138
|
+
const segmentDuration = toSeconds - fromSeconds;
|
|
139
|
+
const timestamps: number[] = [];
|
|
140
|
+
|
|
141
|
+
for (let i = 0; i < amountOfFramesFit; i++) {
|
|
142
|
+
timestamps.push(
|
|
143
|
+
fromSeconds + (segmentDuration / amountOfFramesFit) * (i + 0.5),
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return timestamps;
|
|
148
|
+
},
|
|
149
|
+
onVideoSample: (sample) => {
|
|
150
|
+
console.log(`Frame at ${sample.timestamp}s`);
|
|
151
|
+
|
|
152
|
+
const canvas = document.createElement("canvas");
|
|
153
|
+
canvas.width = sample.displayWidth;
|
|
154
|
+
canvas.height = sample.displayHeight;
|
|
155
|
+
const ctx = canvas.getContext("2d");
|
|
156
|
+
sample.draw(ctx!, 0, 0);
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Cancellation with AbortSignal
|
|
162
|
+
|
|
163
|
+
Cancel frame extraction after a timeout:
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
const controller = new AbortController();
|
|
167
|
+
|
|
168
|
+
setTimeout(() => controller.abort(), 5000);
|
|
169
|
+
|
|
170
|
+
try {
|
|
171
|
+
await extractFrames({
|
|
172
|
+
src: "https://remotion.media/video.mp4",
|
|
173
|
+
timestampsInSeconds: [0, 1, 2, 3, 4],
|
|
174
|
+
onVideoSample: (sample) => {
|
|
175
|
+
using frame = sample;
|
|
176
|
+
const canvas = document.createElement("canvas");
|
|
177
|
+
canvas.width = frame.displayWidth;
|
|
178
|
+
canvas.height = frame.displayHeight;
|
|
179
|
+
const ctx = canvas.getContext("2d");
|
|
180
|
+
frame.draw(ctx!, 0, 0);
|
|
181
|
+
},
|
|
182
|
+
signal: controller.signal,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
console.log("Frame extraction complete!");
|
|
186
|
+
} catch (error) {
|
|
187
|
+
console.error("Frame extraction was aborted or failed:", error);
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Timeout with Promise.race
|
|
192
|
+
|
|
193
|
+
```tsx
|
|
194
|
+
const controller = new AbortController();
|
|
195
|
+
|
|
196
|
+
const timeoutPromise = new Promise<never>((_, reject) => {
|
|
197
|
+
const timeoutId = setTimeout(() => {
|
|
198
|
+
controller.abort();
|
|
199
|
+
reject(new Error("Frame extraction timed out after 10 seconds"));
|
|
200
|
+
}, 10000);
|
|
201
|
+
|
|
202
|
+
controller.signal.addEventListener("abort", () => clearTimeout(timeoutId), {
|
|
203
|
+
once: true,
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
try {
|
|
208
|
+
await Promise.race([
|
|
209
|
+
extractFrames({
|
|
210
|
+
src: "https://remotion.media/video.mp4",
|
|
211
|
+
timestampsInSeconds: [0, 1, 2, 3, 4],
|
|
212
|
+
onVideoSample: (sample) => {
|
|
213
|
+
using frame = sample;
|
|
214
|
+
const canvas = document.createElement("canvas");
|
|
215
|
+
canvas.width = frame.displayWidth;
|
|
216
|
+
canvas.height = frame.displayHeight;
|
|
217
|
+
const ctx = canvas.getContext("2d");
|
|
218
|
+
frame.draw(ctx!, 0, 0);
|
|
219
|
+
},
|
|
220
|
+
signal: controller.signal,
|
|
221
|
+
}),
|
|
222
|
+
timeoutPromise,
|
|
223
|
+
]);
|
|
224
|
+
|
|
225
|
+
console.log("Frame extraction complete!");
|
|
226
|
+
} catch (error) {
|
|
227
|
+
console.error("Frame extraction was aborted or failed:", error);
|
|
228
|
+
}
|
|
229
|
+
```
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ffmpeg
|
|
3
|
+
description: Using FFmpeg and FFprobe in Remotion
|
|
4
|
+
metadata:
|
|
5
|
+
tags: ffmpeg, ffprobe, video, trimming
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## FFmpeg in Remotion
|
|
9
|
+
|
|
10
|
+
`ffmpeg` and `ffprobe` do not need to be installed. They are available via the `bunx remotion ffmpeg` and `bunx remotion ffprobe`:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
bunx remotion ffmpeg -i input.mp4 output.mp3
|
|
14
|
+
bunx remotion ffprobe input.mp4
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Trimming videos
|
|
18
|
+
|
|
19
|
+
You have 2 options for trimming videos:
|
|
20
|
+
|
|
21
|
+
1. Use the FFmpeg command line. You MUST re-encode the video to avoid frozen frames at the start of the video.
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Re-encodes from the exact frame
|
|
25
|
+
bunx remotion ffmpeg -ss 00:00:05 -i public/input.mp4 -to 00:00:10 -c:v libx264 -c:a aac public/output.mp4
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
2. Use the `trimBefore` and `trimAfter` props of the `<Video>` component. The benefit is that this is non-destructive and you can change the trim at any time.
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { Video } from "@remotion/media";
|
|
32
|
+
|
|
33
|
+
<Video
|
|
34
|
+
src={staticFile("video.mp4")}
|
|
35
|
+
trimBefore={5 * fps}
|
|
36
|
+
trimAfter={10 * fps}
|
|
37
|
+
/>;
|
|
38
|
+
```
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: fonts
|
|
3
|
+
description: Loading Google Fonts and local fonts in Remotion
|
|
4
|
+
metadata:
|
|
5
|
+
tags: fonts, google-fonts, typography, text
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Using fonts in Remotion
|
|
9
|
+
|
|
10
|
+
## Google Fonts with @remotion/google-fonts
|
|
11
|
+
|
|
12
|
+
The recommended way to use Google Fonts. It's type-safe and automatically blocks rendering until the font is ready.
|
|
13
|
+
|
|
14
|
+
### Prerequisites
|
|
15
|
+
|
|
16
|
+
First, the @remotion/google-fonts package needs to be installed.
|
|
17
|
+
If it is not installed, use the following command:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx remotion add @remotion/google-fonts # If project uses npm
|
|
21
|
+
bunx remotion add @remotion/google-fonts # If project uses bun
|
|
22
|
+
yarn remotion add @remotion/google-fonts # If project uses yarn
|
|
23
|
+
pnpm exec remotion add @remotion/google-fonts # If project uses pnpm
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import { loadFont } from "@remotion/google-fonts/Lobster";
|
|
28
|
+
|
|
29
|
+
const { fontFamily } = loadFont();
|
|
30
|
+
|
|
31
|
+
export const MyComposition = () => {
|
|
32
|
+
return <div style={{ fontFamily }}>Hello World</div>;
|
|
33
|
+
};
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Preferrably, specify only needed weights and subsets to reduce file size:
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { loadFont } from "@remotion/google-fonts/Roboto";
|
|
40
|
+
|
|
41
|
+
const { fontFamily } = loadFont("normal", {
|
|
42
|
+
weights: ["400", "700"],
|
|
43
|
+
subsets: ["latin"],
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Waiting for font to load
|
|
48
|
+
|
|
49
|
+
Use `waitUntilDone()` if you need to know when the font is ready:
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
import { loadFont } from "@remotion/google-fonts/Lobster";
|
|
53
|
+
|
|
54
|
+
const { fontFamily, waitUntilDone } = loadFont();
|
|
55
|
+
|
|
56
|
+
await waitUntilDone();
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Local fonts with @remotion/fonts
|
|
60
|
+
|
|
61
|
+
For local font files, use the `@remotion/fonts` package.
|
|
62
|
+
|
|
63
|
+
### Prerequisites
|
|
64
|
+
|
|
65
|
+
First, install @remotion/fonts:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npx remotion add @remotion/fonts # If project uses npm
|
|
69
|
+
bunx remotion add @remotion/fonts # If project uses bun
|
|
70
|
+
yarn remotion add @remotion/fonts # If project uses yarn
|
|
71
|
+
pnpm exec remotion add @remotion/fonts # If project uses pnpm
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Loading a local font
|
|
75
|
+
|
|
76
|
+
Place your font file in the `public/` folder and use `loadFont()`:
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
import { loadFont } from "@remotion/fonts";
|
|
80
|
+
import { staticFile } from "remotion";
|
|
81
|
+
|
|
82
|
+
await loadFont({
|
|
83
|
+
family: "MyFont",
|
|
84
|
+
url: staticFile("MyFont-Regular.woff2"),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
export const MyComposition = () => {
|
|
88
|
+
return <div style={{ fontFamily: "MyFont" }}>Hello World</div>;
|
|
89
|
+
};
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Loading multiple weights
|
|
93
|
+
|
|
94
|
+
Load each weight separately with the same family name:
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
import { loadFont } from "@remotion/fonts";
|
|
98
|
+
import { staticFile } from "remotion";
|
|
99
|
+
|
|
100
|
+
await Promise.all([
|
|
101
|
+
loadFont({
|
|
102
|
+
family: "Inter",
|
|
103
|
+
url: staticFile("Inter-Regular.woff2"),
|
|
104
|
+
weight: "400",
|
|
105
|
+
}),
|
|
106
|
+
loadFont({
|
|
107
|
+
family: "Inter",
|
|
108
|
+
url: staticFile("Inter-Bold.woff2"),
|
|
109
|
+
weight: "700",
|
|
110
|
+
}),
|
|
111
|
+
]);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Available options
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
loadFont({
|
|
118
|
+
family: "MyFont", // Required: name to use in CSS
|
|
119
|
+
url: staticFile("font.woff2"), // Required: font file URL
|
|
120
|
+
format: "woff2", // Optional: auto-detected from extension
|
|
121
|
+
weight: "400", // Optional: font weight
|
|
122
|
+
style: "normal", // Optional: normal or italic
|
|
123
|
+
display: "block", // Optional: font-display behavior
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Using in components
|
|
128
|
+
|
|
129
|
+
Call `loadFont()` at the top level of your component or in a separate file that's imported early:
|
|
130
|
+
|
|
131
|
+
```tsx
|
|
132
|
+
import { loadFont } from "@remotion/google-fonts/Montserrat";
|
|
133
|
+
|
|
134
|
+
const { fontFamily } = loadFont("normal", {
|
|
135
|
+
weights: ["400", "700"],
|
|
136
|
+
subsets: ["latin"],
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
export const Title: React.FC<{ text: string }> = ({ text }) => {
|
|
140
|
+
return (
|
|
141
|
+
<h1
|
|
142
|
+
style={{
|
|
143
|
+
fontFamily,
|
|
144
|
+
fontSize: 80,
|
|
145
|
+
fontWeight: "bold",
|
|
146
|
+
}}
|
|
147
|
+
>
|
|
148
|
+
{text}
|
|
149
|
+
</h1>
|
|
150
|
+
);
|
|
151
|
+
};
|
|
152
|
+
```
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: get-audio-duration
|
|
3
|
+
description: Getting the duration of an audio file in seconds with Mediabunny
|
|
4
|
+
metadata:
|
|
5
|
+
tags: duration, audio, length, time, seconds, mp3, wav
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Getting audio duration with Mediabunny
|
|
9
|
+
|
|
10
|
+
Mediabunny can extract the duration of an audio file. It works in browser, Node.js, and Bun environments.
|
|
11
|
+
|
|
12
|
+
## Getting audio duration
|
|
13
|
+
|
|
14
|
+
```tsx title="get-audio-duration.ts"
|
|
15
|
+
import { Input, ALL_FORMATS, UrlSource } from "mediabunny";
|
|
16
|
+
|
|
17
|
+
export const getAudioDuration = async (src: string) => {
|
|
18
|
+
const input = new Input({
|
|
19
|
+
formats: ALL_FORMATS,
|
|
20
|
+
source: new UrlSource(src, {
|
|
21
|
+
getRetryDelay: () => null,
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const durationInSeconds = await input.computeDuration();
|
|
26
|
+
return durationInSeconds;
|
|
27
|
+
};
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
const duration = await getAudioDuration("https://remotion.media/audio.mp3");
|
|
34
|
+
console.log(duration); // e.g. 180.5 (seconds)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Using with staticFile in Remotion
|
|
38
|
+
|
|
39
|
+
Make sure to wrap the file path in `staticFile()`:
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
import { staticFile } from "remotion";
|
|
43
|
+
|
|
44
|
+
const duration = await getAudioDuration(staticFile("audio.mp3"));
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## In Node.js and Bun
|
|
48
|
+
|
|
49
|
+
Use `FileSource` instead of `UrlSource`:
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
import { Input, ALL_FORMATS, FileSource } from "mediabunny";
|
|
53
|
+
|
|
54
|
+
const input = new Input({
|
|
55
|
+
formats: ALL_FORMATS,
|
|
56
|
+
source: new FileSource(file), // File object from input or drag-drop
|
|
57
|
+
});
|
|
58
|
+
```
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: get-video-dimensions
|
|
3
|
+
description: Getting the width and height of a video file with Mediabunny
|
|
4
|
+
metadata:
|
|
5
|
+
tags: dimensions, width, height, resolution, size, video
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Getting video dimensions with Mediabunny
|
|
9
|
+
|
|
10
|
+
Mediabunny can extract the width and height of a video file. It works in browser, Node.js, and Bun environments.
|
|
11
|
+
|
|
12
|
+
## Getting video dimensions
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { Input, ALL_FORMATS, UrlSource } from "mediabunny";
|
|
16
|
+
|
|
17
|
+
export const getVideoDimensions = async (src: string) => {
|
|
18
|
+
const input = new Input({
|
|
19
|
+
formats: ALL_FORMATS,
|
|
20
|
+
source: new UrlSource(src, {
|
|
21
|
+
getRetryDelay: () => null,
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const videoTrack = await input.getPrimaryVideoTrack();
|
|
26
|
+
if (!videoTrack) {
|
|
27
|
+
throw new Error("No video track found");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
width: videoTrack.displayWidth,
|
|
32
|
+
height: videoTrack.displayHeight,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
const dimensions = await getVideoDimensions("https://remotion.media/video.mp4");
|
|
41
|
+
console.log(dimensions.width); // e.g. 1920
|
|
42
|
+
console.log(dimensions.height); // e.g. 1080
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Using with local files
|
|
46
|
+
|
|
47
|
+
For local files, use `FileSource` instead of `UrlSource`:
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { Input, ALL_FORMATS, FileSource } from "mediabunny";
|
|
51
|
+
|
|
52
|
+
const input = new Input({
|
|
53
|
+
formats: ALL_FORMATS,
|
|
54
|
+
source: new FileSource(file), // File object from input or drag-drop
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const videoTrack = await input.getPrimaryVideoTrack();
|
|
58
|
+
const width = videoTrack.displayWidth;
|
|
59
|
+
const height = videoTrack.displayHeight;
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Using with staticFile in Remotion
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
import { staticFile } from "remotion";
|
|
66
|
+
|
|
67
|
+
const dimensions = await getVideoDimensions(staticFile("video.mp4"));
|
|
68
|
+
```
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: get-video-duration
|
|
3
|
+
description: Getting the duration of a video file in seconds with Mediabunny
|
|
4
|
+
metadata:
|
|
5
|
+
tags: duration, video, length, time, seconds
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Getting video duration with Mediabunny
|
|
9
|
+
|
|
10
|
+
Mediabunny can extract the duration of a video file. It works in browser, Node.js, and Bun environments.
|
|
11
|
+
|
|
12
|
+
## Getting video duration
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { Input, ALL_FORMATS, UrlSource } from "mediabunny";
|
|
16
|
+
|
|
17
|
+
export const getVideoDuration = async (src: string) => {
|
|
18
|
+
const input = new Input({
|
|
19
|
+
formats: ALL_FORMATS,
|
|
20
|
+
source: new UrlSource(src, {
|
|
21
|
+
getRetryDelay: () => null,
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const durationInSeconds = await input.computeDuration();
|
|
26
|
+
return durationInSeconds;
|
|
27
|
+
};
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
const duration = await getVideoDuration("https://remotion.media/video.mp4");
|
|
34
|
+
console.log(duration); // e.g. 10.5 (seconds)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Video files from the public/ directory
|
|
38
|
+
|
|
39
|
+
Make sure to wrap the file path in `staticFile()`:
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
import { staticFile } from "remotion";
|
|
43
|
+
|
|
44
|
+
const duration = await getVideoDuration(staticFile("video.mp4"));
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## In Node.js and Bun
|
|
48
|
+
|
|
49
|
+
Use `FileSource` instead of `UrlSource`:
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
import { Input, ALL_FORMATS, FileSource } from "mediabunny";
|
|
53
|
+
|
|
54
|
+
const input = new Input({
|
|
55
|
+
formats: ALL_FORMATS,
|
|
56
|
+
source: new FileSource(file), // File object from input or drag-drop
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const durationInSeconds = await input.computeDuration();
|
|
60
|
+
```
|