Skip to content

🎥 Make videos programmatically with React

getting there

Jonny Burger1dd7d3625161
diff --git a/packages/docs/components/TableOfContents/gif.tsx b/packages/docs/components/TableOfContents/gif.tsx
new file mode 100644
index 0000000000..37909181b9
--- /dev/null
+++ b/packages/docs/components/TableOfContents/gif.tsx
@@ -0,0 +1,20 @@
+import React from "react";
+import { Grid } from "./Grid";
+import { TOCItem } from "./TOCItem";
+
+export const TableOfContents: React.FC = () => {
+ return (
+ <div>
+ <Grid>
+ <TOCItem link="/docs/gif/index">
+ <strong>{"<Gif>"}</strong>
+ <div>Render a GIF</div>
+ </TOCItem>
+ <TOCItem link="/docs/gif/get-gif-duration-in-seconds">
+ <strong>getGifDurationInSeconds()</strong>
+ <div>Get the runtime of a GIF</div>
+ </TOCItem>
+ </Grid>
+ </div>
+ );
+};
diff --git a/packages/docs/docs/gif.md b/packages/docs/docs/gif.md
deleted file mode 100644
index cdc495d4a5..0000000000
--- a/packages/docs/docs/gif.md
+++ /dev/null
@@ -1,124 +0,0 @@
----
-id: gif
-sidebar_label: "@remotion/gif"
-title: "@remotion/gif"
----
-
-import Tabs from '@theme/Tabs';
-import TabItem from '@theme/TabItem';
-
-You can install this package from NPM to get a component for displaying GIFs that synchronize with Remotions [`useCurrentFrame()`](/docs/use-current-frame).
-
-<Tabs
-defaultValue="npm"
-values={[
-{ label: 'npm', value: 'npm', },
-{ label: 'yarn', value: 'yarn', },
-{ label: 'pnpm', value: 'pnpm', },
-]
-}>
-<TabItem value="npm">
-
-```bash
-npm i @remotion/gif
-```
-
- </TabItem>
-
- <TabItem value="pnpm">
-
-```bash
-pnpm i @remotion/gif
-```
-
- </TabItem>
-
- <TabItem value="yarn">
-
-```bash
-yarn add @remotion/gif
-```
-
- </TabItem>
-</Tabs>
-
-Also update **all the other Remotion packages** to have the same version: `remotion`, `@remotion/cli` and others.
-
-:::note
-Make sure no package version number has a `^` character in front of it as it can lead to a version conflict.
-:::
-
-## Props
-
-### `src`
-
-_required_
-
-The source of the GIF. Can be an URL or a local image - see [Importing assets](/docs/assets).
-
-:::info
-Remote GIFs need to support [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS).
-
-<details>
-<summary>More info</summary>
-<ul>
-<li>
-Remotion's origin is usually <code>http://localhost:3000</code>, but it may be different if rendering on Lambda or the port is busy.
-</li>
-<li>
-You can <a href="/docs/chromium-flags#--disable-web-security">disable CORS</a> during renders.
-</li>
-</ul>
-</details>
-:::
-
-### `width`
-
-The display width.
-
-### `height`
-
-The display height.
-
-### `fit`
-
-Must be one of these values:
-
-- `'fill'`: The GIF will completely fill the container, and will be stretched if necessary. (_default_)
-- `'contain'`: The GIF is scaled to fit the box, while aspect ratio is maintained.
-- `'cover'`: The GIF completely fills the container and maintains it's aspect ratio. It will be cropped if necessary.
-
-### `onLoad`
-
-Callback that gets called once the GIF has loaded and finished processing. As its only argument, the callback gives the following object:
-
-- `loaded`: Will be always `true`.
-- `width`: Width of the GIF file in pixels.
-- `height`: Height of the GIF file in pixels.
-- `delays`: Array of timestamps of type `number` containing position of each frame.
-- `frames`: Array of frames of type [`ImageData`](https://developer.mozilla.org/en-US/docs/Web/API/ImageData)
-
-### `style`
-
-Allows to pass in custom CSS styles.
-
-## Example
-
-```tsx twoslash
-import { useVideoConfig } from "remotion";
-// ---cut---
-import { Gif } from "@remotion/gif";
-
-export const MyComponent: React.FC = () => {
- const { width, height } = useVideoConfig();
-
- return (
- <Gif
- src="https://media.giphy.com/media/3o72F7YT6s0EMFI0Za/giphy.gif"
- width={width}
- height={height}
- fit="fill"
- />
- );
-};
-```
diff --git a/packages/docs/docs/gif/get-gif-duration-in-seconds.md b/packages/docs/docs/gif/get-gif-duration-in-seconds.md
new file mode 100644
index 0000000000..68931a77ac
--- /dev/null
+++ b/packages/docs/docs/gif/get-gif-duration-in-seconds.md
@@ -0,0 +1,12 @@
+---
+title: getGifDurationInSeconds()
+id: get-gif-duration-in-seconds
+---
+
+import {TableOfContents} from '../../components/TableOfContents/renderer';
+
+_Part of the [`@remotion/gif`](/docs/gif) package_
+
+You can install this package from NPM to get a component for displaying GIFs that synchronize with Remotions [`useCurrentFrame()`](/docs/use-current-frame).
+
+<TableOfContents />
diff --git a/packages/docs/docs/gif/gif.md b/packages/docs/docs/gif/gif.md
new file mode 100644
index 0000000000..b4c5497f45
--- /dev/null
+++ b/packages/docs/docs/gif/gif.md
@@ -0,0 +1,55 @@
+---
+slug: gif/gif
+sidebar_label: "<Gif>"
+title: "<Gif>"
+---
+
+_Part of the [`@remotion/gif`](/docs/gif) package_
+
+Displays a GIF that synchronizes with Remotions [`useCurrentFrame()`](/docs/use-current-frame).
+
+Gets the duration in seconds of an audio source. Remotion will create an invisible `<audio>` tag, load the audio and return the duration.
+
+## Arguments
+
+### `src`
+
+A string pointing to an audio asset
+
+## Return value
+
+`Promise<number>` - the duration of the audio file.
+
+## Example
+
+```tsx twoslash
+// @module: ESNext
+// @target: ESNext
+import { useCallback, useEffect } from "react";
+import { staticFile } from "remotion";
+// ---cut---
+import { getAudioDurationInSeconds } from "@remotion/media-utils";
+import music from "./music.mp3";
+
+const MyComp: React.FC = () => {
+ const getDuration = useCallback(async () => {
+ const imported = await getAudioDurationInSeconds(music); // 127.452
+ const publicFile = await getAudioDurationInSeconds(
+ staticFile("voiceover.wav")
+ ); // 33.221
+ const remote = await getAudioDurationInSeconds(
+ "https://example.com/remote-audio.aac"
+ ); // 50.24
+ }, []);
+
+ useEffect(() => {
+ getDuration();
+ }, []);
+
+ return null;
+};
+```
+
+## See also
+
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/gif/src/get-gif-duration-in-seconds.ts)
diff --git a/packages/docs/docs/gif/index.md b/packages/docs/docs/gif/index.md
new file mode 100644
index 0000000000..c0ab238d4d
--- /dev/null
+++ b/packages/docs/docs/gif/index.md
@@ -0,0 +1,55 @@
+---
+sidebar_label: "@remotion/gif"
+title: "@remotion/gif"
+---
+
+import Tabs from '@theme/Tabs';
+import TabItem from '@theme/TabItem';
+import {TableOfContents} from '../../components/TableOfContents/gif';
+
+You can install this package from NPM to get a component for displaying GIFs that synchronize with Remotions [`useCurrentFrame()`](/docs/use-current-frame).
+
+<Tabs
+defaultValue="npm"
+values={[
+{ label: 'npm', value: 'npm', },
+{ label: 'yarn', value: 'yarn', },
+{ label: 'pnpm', value: 'pnpm', },
+]
+}>
+<TabItem value="npm">
+
+```bash
+npm i @remotion/gif
+```
+
+ </TabItem>
+
+ <TabItem value="pnpm">
+
+```bash
+pnpm i @remotion/gif
+```
+
+ </TabItem>
+
+ <TabItem value="yarn">
+
+```bash
+yarn add @remotion/gif
+```
+
+ </TabItem>
+</Tabs>
+
+Also update **all the other Remotion packages** to have the same version: `remotion`, `@remotion/cli` and others.
+
+:::note
+Make sure no package version number has a `^` character in front of it as it can lead to a version conflict.
+:::
+
+## APIs
+
+The following APIs are available:
+
+<TableOfContents />
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index eedf1eb0e0..0c8f67dd2d 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -187,7 +187,15 @@ module.exports = {
"lambda/uninstall",
],
},
- "gif",
+ {
+ type: "category",
+ label: "@remotion/gif",
+ link: {
+ type: "doc",
+ id: "gif/index",
+ },
+ items: ["gif/gif", "gif/get-gif-duration-in-seconds"],
+ },
{
type: "category",
label: "@remotion/media-utils",
diff --git a/packages/gif/src/get-gif-duration.ts b/packages/gif/src/get-gif-duration-in-seconds.ts
similarity index 100%
rename from packages/gif/src/get-gif-duration.ts
rename to packages/gif/src/get-gif-duration-in-seconds.ts
diff --git a/vercel.json b/vercel.json
index 9d15ef1697..bdae445640 100644
--- a/vercel.json
+++ b/vercel.json
@@ -35,6 +35,11 @@
"destination": "https://remotion.dev/docs/skia",
"permanent": false
},
+ {
+ "source": "/gif",
+ "destination": "https://remotion.dev/docs/gif",
+ "permanent": false
+ },
{
"source": "/lottie",
"destination": "https://remotion.dev/docs/lottie",