Skip to content

🎥 Make videos programmatically with React

improve docs

Jonny Burger67a5ec63a457
diff --git a/packages/docs/components/TableOfContents/gif.tsx b/packages/docs/components/TableOfContents/gif.tsx
index 37909181b9..4f437003c1 100644
--- a/packages/docs/components/TableOfContents/gif.tsx
+++ b/packages/docs/components/TableOfContents/gif.tsx
@@ -6,7 +6,7 @@ export const TableOfContents: React.FC = () => {
return (
<div>
<Grid>
- <TOCItem link="/docs/gif/index">
+ <TOCItem link="/docs/gif/gif">
<strong>{"<Gif>"}</strong>
<div>Render a GIF</div>
</TOCItem>
diff --git a/packages/docs/docs/gif/get-gif-duration-in-seconds.md b/packages/docs/docs/gif/get-gif-duration-in-seconds.md
index 68931a77ac..9598185c22 100644
--- a/packages/docs/docs/gif/get-gif-duration-in-seconds.md
+++ b/packages/docs/docs/gif/get-gif-duration-in-seconds.md
@@ -3,10 +3,65 @@ 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).
+Gets the duration in seconds of a GIF.
+
+:::note
+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>
+:::
+
+## Arguments
+
+### `src`
+
+A string pointing to a GIF asset
+
+## Return value
+
+`Promise<number>` - the duration of the GIF in seconds, not factoring in that whether it is looped.
+
+## Example
+
+```tsx twoslash
+// @module: ESNext
+// @target: ESNext
+import { useCallback, useEffect } from "react";
+import { staticFile } from "remotion";
+// ---cut---
+import { getGifDurationInSeconds } from "@remotion/gif";
+import gif from "./cat.gif";
+
+const MyComp: React.FC = () => {
+ const getDuration = useCallback(async () => {
+ const imported = await getGifDurationInSeconds(gif); // 127.452
+ const publicFile = await getGifDurationInSeconds(staticFile("giphy.gif")); // 2.10
+ const remote = await getGifDurationInSeconds(
+ "https://media.giphy.com/media/xT0GqH01ZyKwd3aT3G/giphy.gif"
+ ); // 3.23
+ }, []);
+
+ useEffect(() => {
+ getDuration();
+ }, []);
+
+ return null;
+};
+```
+
+## See also
-<TableOfContents />
+- [`<Gif>`](/docs/gif/gif)
+- [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/gif.md b/packages/docs/docs/gif/gif.md
index b4c5497f45..8b62f00ce7 100644
--- a/packages/docs/docs/gif/gif.md
+++ b/packages/docs/docs/gif/gif.md
@@ -1,5 +1,5 @@
---
-slug: gif/gif
+slug: gif
sidebar_label: "<Gif>"
title: "<Gif>"
---
@@ -8,48 +8,81 @@ _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
+## Props
### `src`
-A string pointing to an audio asset
+_required_
+
+The source of the GIF. Can be an URL or a local image - see [Importing assets](/docs/assets).
+
+:::note
+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.
-## Return value
+### `fit`
-`Promise<number>` - the duration of the audio file.
+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:
+
+- `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
-// @module: ESNext
-// @target: ESNext
-import { useCallback, useEffect } from "react";
-import { staticFile } from "remotion";
+import { useVideoConfig } 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;
+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"
+ />
+ );
};
```
## See also
-- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/gif/src/get-gif-duration-in-seconds.ts)
+- [`getGifDurationInSeconds()`](/docs/gif/get-gif-duration-in-seconds)
+- [Source code for this component](https://github.com/remotion-dev/remotion/blob/main/packages/gif/src/Gif.tsx)
diff --git a/packages/gif/src/index.ts b/packages/gif/src/index.ts
index b6435525d5..8971c66818 100644
--- a/packages/gif/src/index.ts
+++ b/packages/gif/src/index.ts
@@ -1,3 +1,3 @@
-export {getGifDurationInSeconds} from './get-gif-duration';
+export {getGifDurationInSeconds} from './get-gif-duration-in-seconds';
export {Gif} from './Gif';
export {RemotionGifProps} from './props';