Skip to content

🎥 Make videos programmatically with React

update

Jonny Burgerf78368adb618
diff --git a/packages/docs/docs/sfx/PlayButton.tsx b/packages/docs/docs/sfx/PlayButton.tsx
new file mode 100644
index 0000000000..4c757361a9
--- /dev/null
+++ b/packages/docs/docs/sfx/PlayButton.tsx
@@ -0,0 +1,65 @@
+import {Button} from '@remotion/design';
+import React, {useCallback, useRef, useState} from 'react';
+
+export const PlayButton: React.FC<{
+ readonly src: string;
+ readonly size?: number;
+}> = ({src, size = 48}) => {
+ const [playing, setPlaying] = useState(false);
+ const audioRef = useRef<HTMLAudioElement | null>(null);
+
+ const iconSize = Math.round(size * 0.5);
+
+ const toggle = useCallback(
+ (e: React.MouseEvent) => {
+ e.preventDefault();
+ e.stopPropagation();
+ if (playing) {
+ audioRef.current?.pause();
+ if (audioRef.current) {
+ audioRef.current.currentTime = 0;
+ }
+ setPlaying(false);
+ } else {
+ const audio = new Audio(src);
+ audioRef.current = audio;
+ audio.play();
+ audio.addEventListener('ended', () => {
+ setPlaying(false);
+ });
+ setPlaying(true);
+ }
+ },
+ [playing, src],
+ );
+
+ return (
+ <Button
+ className={`rounded-full p-0`}
+ style={{width: size, height: size}}
+ onClick={toggle}
+ title={playing ? 'Stop' : 'Play'}
+ >
+ {playing ? (
+ <svg
+ width={iconSize}
+ height={iconSize}
+ viewBox="0 0 24 24"
+ fill="currentColor"
+ >
+ <rect x="6" y="4" width="4" height="16" />
+ <rect x="14" y="4" width="4" height="16" />
+ </svg>
+ ) : (
+ <svg
+ width={iconSize}
+ height={iconSize}
+ viewBox="0 0 24 24"
+ fill="currentColor"
+ >
+ <polygon points="6,4 20,12 6,20" />
+ </svg>
+ )}
+ </Button>
+ );
+};
diff --git a/packages/docs/docs/sfx/table-of-contents.tsx b/packages/docs/docs/sfx/table-of-contents.tsx
index ed76b50e68..d21fa30d77 100644
--- a/packages/docs/docs/sfx/table-of-contents.tsx
+++ b/packages/docs/docs/sfx/table-of-contents.tsx
@@ -1,20 +1,27 @@
-import React from "react";
-import { Grid } from "../../components/TableOfContents/Grid";
-import { TOCItem } from "../../components/TableOfContents/TOCItem";
+import React from 'react';
+import {Grid} from '../../components/TableOfContents/Grid';
+import {TOCItem} from '../../components/TableOfContents/TOCItem';
+import {PlayButton} from './PlayButton';
export const TableOfContents: React.FC = () => {
- return (
- <div>
- <Grid>
- <TOCItem link="/docs/sfx/whip">
- <strong>whip</strong>
- <div>URL for a whip sound effect</div>
- </TOCItem>
- <TOCItem link="/docs/sfx/whoosh">
- <strong>whoosh</strong>
- <div>URL for a whoosh sound effect</div>
- </TOCItem>
- </Grid>
- </div>
- );
+ return (
+ <div>
+ <Grid>
+ <TOCItem link="/docs/sfx/whip">
+ <strong>whip</strong>
+ <div>URL for a whip sound effect</div>
+ <div style={{marginTop: 8}}>
+ <PlayButton src="https://remotion.media/whip.wav" size={32} />
+ </div>
+ </TOCItem>
+ <TOCItem link="/docs/sfx/whoosh">
+ <strong>whoosh</strong>
+ <div>URL for a whoosh sound effect</div>
+ <div style={{marginTop: 8}}>
+ <PlayButton src="https://remotion.media/whoosh.wav" size={32} />
+ </div>
+ </TOCItem>
+ </Grid>
+ </div>
+ );
};
diff --git a/packages/docs/docs/sfx/whip.mdx b/packages/docs/docs/sfx/whip.mdx
index 98aa035f4d..1b14181679 100644
--- a/packages/docs/docs/sfx/whip.mdx
+++ b/packages/docs/docs/sfx/whip.mdx
@@ -6,13 +6,18 @@ crumb: '@remotion/sfx'
# whip<AvailableFrom v="4.0.429" />
+import {PlayButton} from './PlayButton';
+
+<PlayButton src="https://remotion.media/whip.wav" />
+<br />
+
A URL pointing to a whip sound effect WAV file.
## Example
```tsx twoslash title="MyComp.tsx"
import {whip} from '@remotion/sfx';
-import {Audio} from 'remotion';
+import {Audio} from '@remotion/media';
const MyVideo = () => {
return <Audio src={whip} />;
@@ -21,7 +26,17 @@ const MyVideo = () => {
## Value
-`"https://remotion.media/whip.wav"`
+```bash
+https://remotion.media/whip.wav
+```
+
+## Duration
+
+0.173 seconds (2 channels, 96000 Hz, 24-bit)
+
+## Attribution
+
+SWSH_Badminton Racquet_Recording_01_JW Audio by JW_Audio - [freesound.org/s/838766](https://freesound.org/s/838766/) - License: Creative Commons 0
## See also
diff --git a/packages/docs/docs/sfx/whoosh.mdx b/packages/docs/docs/sfx/whoosh.mdx
index abae9ee4ce..2963877b75 100644
--- a/packages/docs/docs/sfx/whoosh.mdx
+++ b/packages/docs/docs/sfx/whoosh.mdx
@@ -6,13 +6,18 @@ crumb: '@remotion/sfx'
# whoosh<AvailableFrom v="4.0.429" />
+import {PlayButton} from './PlayButton';
+
+<PlayButton src="https://remotion.media/whoosh.wav" />
+<br />
+
A URL pointing to a whoosh sound effect WAV file.
## Example
```tsx twoslash title="MyComp.tsx"
import {whoosh} from '@remotion/sfx';
-import {Audio} from 'remotion';
+import {Audio} from '@remotion/media';
const MyVideo = () => {
return <Audio src={whoosh} />;
@@ -21,7 +26,17 @@ const MyVideo = () => {
## Value
-`"https://remotion.media/whoosh.wav"`
+```bash
+https://remotion.media/whoosh.wav
+```
+
+## Duration
+
+0.154 seconds (1 channel, 44100 Hz, 16-bit)
+
+## Attribution
+
+Woosh by 1bob - [freesound.org/s/831936](https://freesound.org/s/831936/) - License: Creative Commons 0
## See also
diff --git a/packages/sfx/bundle.ts b/packages/sfx/bundle.ts
index 846bbbc8a0..f7b114c5c3 100644
--- a/packages/sfx/bundle.ts
+++ b/packages/sfx/bundle.ts
@@ -1,5 +1,5 @@
-import {build} from 'bun';
import path from 'path';
+import {build} from 'bun';
if (process.env.NODE_ENV !== 'production') {
throw new Error('This script must be run using NODE_ENV=production');
diff --git a/packages/skills/skills/remotion/SKILL.md b/packages/skills/skills/remotion/SKILL.md
index 2f4684a0de..7ddaa0fdf3 100644
--- a/packages/skills/skills/remotion/SKILL.md
+++ b/packages/skills/skills/remotion/SKILL.md
@@ -21,6 +21,10 @@ For some video operations, such as trimming videos or detecting silence, FFmpeg
When needing to visualize audio (spectrum bars, waveforms, bass-reactive effects), load the [./rules/audio-visualization.md](./rules/audio-visualization.md) file for more information.
+## Sound effects
+
+When needing to use sound effects, load the [./rules/sound-effects.md](./rules/sound-effects.md) file for more information.
+
## How to use
Read individual rule files for detailed explanations and code examples:
diff --git a/packages/skills/skills/remotion/rules/sfx.md b/packages/skills/skills/remotion/rules/sfx.md
new file mode 100644
index 0000000000..c4ddab0285
--- /dev/null
+++ b/packages/skills/skills/remotion/rules/sfx.md
@@ -0,0 +1,14 @@
+---
+name: sfx
+description: Including sound effects
+metadata:
+ tags: sfx, sound, effect, audio
+---
+
+# Sound effect rules
+
+## Prerequisites
+
+```bash
+npx remotion add @remotion/sfx
+```
\ No newline at end of file