Skip to content

🎥 Make videos programmatically with React

document Render as GIF

Jonny Burgerd786a28e711f
diff --git a/packages/core/src/config/index.ts b/packages/core/src/config/index.ts
index 63f14c5041..5ecb1d5d1f 100644
--- a/packages/core/src/config/index.ts
+++ b/packages/core/src/config/index.ts
@@ -154,7 +154,8 @@ export const Config = {
setScale,
/**
* Specify which frames should be picked for rendering a GIF
- * Default: 1
+ * Default: 1, which means every frame
+ * https://remotion.dev/docs/render-as-gif
*/
setEveryNthFrame,
/**
diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.ts
index 144aef89fc..bd2e926388 100644
--- a/packages/core/src/internals.ts
+++ b/packages/core/src/internals.ts
@@ -163,7 +163,7 @@ export const Internals = {
getOutputCodecOrUndefined,
getWebpackOverrideFn,
getQuality,
- getEveryNthFrame: getAndValidateEveryNthFrame,
+ getAndValidateEveryNthFrame,
getLoop,
getScale,
getShouldOutputImageSequence,
diff --git a/packages/docs/docs/cli/render.md b/packages/docs/docs/cli/render.md
index 72a58d63f6..cb92fbb9b3 100644
--- a/packages/docs/docs/cli/render.md
+++ b/packages/docs/docs/cli/render.md
@@ -81,9 +81,17 @@ Specify a location for a dotenv file. Default `.env`. Available in v2.2 and late
### `--every-nth-frame`
+_available from v3.1_
+
[Render only every nth frame.](/docs/config#seteverynthframe) This option may only be set when rendering GIFs. This allows you to lower the FPS of the GIF.
-For example, if the `fps` is 30, and `--every-nth-frame` is 2, the FPS of the GIF is `15`.
+For example only every second frame, every third frame and so on. Only works for rendering GIFs. [See here for more details.](/docs/render-as-gif#reducing-frame-rate)
+
+### `--loop`
+
+_available from v3.1_
+
+[Set the looping behavior.](/docs/config#setloop) This option may only be set when rendering GIFs. [See here for more details.](/docs/render-as-gif#changing-the-number-of-loops)
### `--bundle-cache`
diff --git a/packages/docs/docs/config.md b/packages/docs/docs/config.md
index 7aea020d0c..c67ad435d4 100644
--- a/packages/docs/docs/config.md
+++ b/packages/docs/docs/config.md
@@ -306,7 +306,7 @@ The [command line flag](/docs/cli/render#--ffprobe-executable) `--ffprobe-execut
### setEveryNthFrame()
-This option may only be set when rendering GIFs. It determines how many frames are rendered, while the other ones gets skipped in order to lower the FPS of the GIF.
+This option may only be set when rendering GIFs. [It determines how many frames are rendered, while the other ones gets skipped in order to lower the FPS of the GIF.](/docs/render-as-gif)
For example, if the `fps` is 30, and `everyNthFrame` is 2, the FPS of the GIF is `15`.
@@ -320,7 +320,7 @@ The [command line flag](/docs/cli/render#--every-nth-frame) `--every-nth-frame`
### setLoop()
-This option may only be set when rendering GIFs. If it is set, it will limit the amount of times a GIF will loop. If set to `0`, the GIF will play once, if set to `1`, it will play twice. If set to `null` or not set at all, it will play forever.
+This option may only be set when rendering GIFs. [If it is set, it will limit the amount of times a GIF will loop. If set to `0`, the GIF will play once, if set to `1`, it will play twice. If set to `null` or not set at all, it will play forever](/docs/render-as-gif).
```ts twoslash
import { Config } from "remotion";
diff --git a/packages/docs/docs/encoding.md b/packages/docs/docs/encoding.md
index 62993f9ba4..efe6480295 100644
--- a/packages/docs/docs/encoding.md
+++ b/packages/docs/docs/encoding.md
@@ -235,6 +235,10 @@ You can set the codec to `h264-mkv` to use the mkv container format together wit
This preset was created for Remotion Lambda, and is optimal for when concatenating multiple video clips into one.
:::
+## GIFs
+
+You can also [render you video as a GIF](/docs/render-as-gif).
+
## What other settings do you need?
Which of the dozens of options that FFMPEG supports would you like to see exposed in Remotion? Let us know by opening an [issue on our issue tracker!](https://github.com/remotion-dev/remotion/issues)
diff --git a/packages/docs/docs/lambda/cli/render.md b/packages/docs/docs/lambda/cli/render.md
index 402ede7489..7096c84a2c 100644
--- a/packages/docs/docs/lambda/cli/render.md
+++ b/packages/docs/docs/lambda/cli/render.md
@@ -138,6 +138,20 @@ Specify a location for a dotenv file. Default `.env`.
[Render a subset of a video](/docs/config#setframerange). Example: `--frames=0-9` to select the first 10 frames. To render a still, use the [`still`](/docs/lambda/cli/still) command.
+### `--every-nth-frame`
+
+_available from v3.1_
+
+[Render only every nth frame.](/docs/config#seteverynthframe) This option may only be set when rendering GIFs. This allows you to lower the FPS of the GIF.
+
+For example only every second frame, every third frame and so on. Only works for rendering GIFs. [See here for more details.](/docs/render-as-gif)
+
+### `--loop`
+
+_available from v3.1_
+
+[Set the looping behavior.](/docs/config#setloop) This option may only be set when rendering GIFs. [See here for more details.](/docs/render-as-gif#changing-the-number-of-loops)
+
### `--out-name`
The file name of the media output as stored in the S3 bucket. By default, it is `out` plus the appropriate file extension, for example: `out.mp4`. Must match `/([0-9a-zA-Z-!_.*'()]+)/g`.
diff --git a/packages/docs/docs/lambda/rendermediaonlambda.md b/packages/docs/docs/lambda/rendermediaonlambda.md
index 1f4bc47923..b8394a9846 100644
--- a/packages/docs/docs/lambda/rendermediaonlambda.md
+++ b/packages/docs/docs/lambda/rendermediaonlambda.md
@@ -139,12 +139,18 @@ _optional, available from v2.6.5_
Allows you to set certain Chromium / Google Chrome flags. See: [Chromium flags](/docs/chromium-flags).
-### `concurrencyPerLambda`
+### `concurrencyPerLambda`
_optional, available from v3.0.30_
By default, each Lambda function renders with concurrency 1 (one open browser tab). You may use the option to customize this value.
+### `everyNthFrame?`
+
+_optional, available from v3.1_
+
+Renders only every nth frame. For example only every second frame, every third frame and so on. Only works for rendering GIFs. [See here for more details.](/docs/render-as-gif)
+
#### `disableWebSecurity`
_boolean - default `false`_
diff --git a/packages/docs/docs/render-as-gif.md b/packages/docs/docs/render-as-gif.md
new file mode 100644
index 0000000000..f22584c465
--- /dev/null
+++ b/packages/docs/docs/render-as-gif.md
@@ -0,0 +1,48 @@
+---
+id: render-as-gif
+title: Render as GIF
+---
+
+_Available since v3.1_
+
+You can render a video as a GIF by:
+
+- passing `--codec=gif` in the command line
+- setting `codec: "gif"` in [`renderMedia()`](/docs/renderer/render-media), [`stitchFramesToVideo()`](/docs/renderer/stitch-frames-to-video) or [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda).
+
+## Reducing frame rate
+
+Commonly a GIF has a lower frame rate than a video. For this, we support a parameter `everyNthFrame` that works as follows:
+
+- By default, `everyNthFrame` is set to `1`: Frames `0`, `1`, `2`, `3`, `4` and so on are rendered.
+- Assuming `everyNthFrame` is `2`, only every 2nd frame is rendered: `1`, `3`, `5`, `7` and so on. A 30FPS video would now become a 15FPS GIF.
+- If `everyNthFrame` is `3`, only every 3rd frame is rendered: `2`, `5`, `8`, `11` and the pattern continues.
+
+`everyNthFrame` is supported:
+
+- in [`renderFrames()`](/docs/renderer/render-frames#everynthframe), [`renderMedia()`](/docs/renderer/render-media#everynthframe) and [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda#everynthframe)
+- in the CLI using `--every-nth-frame=2` [locally](/docs/cli/render#--every-nth-frame) or [on Lambda](/docs/lambda/cli/render#--every-nth-frame).
+
+## Changing the number of loops
+
+<!-- Changing the title will change other links -->
+
+The `loop` option allows you to set the number of loops as follows:
+
+- `null` (or omitting in the CLI) means to play the GIF indefinitely.
+- `0` disables looping.
+- `1` loops the GIF once (plays twice in total)
+- `2` loops the GIF twice (plays three times in total)
+- and so on.
+
+The `loop` option can be set:
+
+- In the CLI using the `--loop=0` flag when rendering [locally](/docs/cli/render#--loop) or on [Lambda](/docs/lambda/cli/render#--loop).
+
+## Importing GIFs
+
+Wondering how to import other GIFs into a Remotion project? [See here.](/docs/gif)
+
+## See also
+
+- [Encoding guide](/docs/encoding)
diff --git a/packages/docs/docs/renderer/render-frames.md b/packages/docs/docs/renderer/render-frames.md
index 8cd3aa28d5..d5f35b647f 100644
--- a/packages/docs/docs/renderer/render-frames.md
+++ b/packages/docs/docs/renderer/render-frames.md
@@ -252,6 +252,12 @@ _optional, available from v2.6.3_
A number describing how long one frame may take to resolve all `delayRender()` calls before the render times out and fails. Default: `30000`
+### `everyNthFrame`
+
+_optional, available from v3.1_
+
+Renders only every nth frame. For example only every second frame, every third frame and so on. Only meant for rendering GIFs. [See here for more details.](/docs/render-as-gif)
+
### `chromiumOptions?`
_optional, available from v2.6.5_
diff --git a/packages/docs/docs/renderer/render-media.md b/packages/docs/docs/renderer/render-media.md
index 507310b3fa..847a1aa4d1 100644
--- a/packages/docs/docs/renderer/render-media.md
+++ b/packages/docs/docs/renderer/render-media.md
@@ -67,7 +67,7 @@ An object describing a composition using `id`, `width`, `height`, `fps` and `dur
### `codec`
-_"h264" (default) | "h265" | "vp8" | "vp9" | "mp3" | "aac" | "wav" | "prores" | "h264-mkv"_
+_"h264" (default) | "h265" | "vp8" | "vp9" | "mp3" | "aac" | "wav" | "prores" | "h264-mkv" | "gif"_
Choose a suitable codec for your output media. Refer to the [Encoding guide](/docs/encoding) to find the best codec for your use case.
@@ -79,7 +79,7 @@ An object of arbitrary shape that will be passed as [props to your composition](
### `parallelism`
-_number | null - optional_
+_number | null - optional_
How many threads should be used for rendering frames. By default `null`, which will use half of the threads that your CPU has.
Type `node -e "console.log(require('os').cpus().length)"` into your command line to find out how many threads your CPU has.
@@ -118,6 +118,12 @@ _optional, available from v3.0.11_
A string defining the absolute path on disk of the browser executable that should be used. By default Remotion will try to detect it automatically and download one if none is available. If `puppeteerInstance` is defined, it will take precedence over `browserExecutable`.
+### `everyNthFrame?`
+
+_optional, available from v3.1_
+
+Renders only every nth frame. For example only every second frame, every third frame and so on. Only works for rendering GIFs. [See here for more details.](/docs/render-as-gif)
+
### `pixelFormat`
_string - optional_
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 6d2ec23e8c..ff36721a23 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -108,6 +108,7 @@ module.exports = {
"stills",
"scaling",
"video-manipulation",
+ "render-as-gif",
],
},
{