Skip to content

🎥 Make videos programmatically with React

add encoding guide

Jonny Burgerbb0ceab45e76
diff --git a/packages/docs/docs/config.md b/packages/docs/docs/config.md
index 8c86a68427..8fc7449ad3 100644
--- a/packages/docs/docs/config.md
+++ b/packages/docs/docs/config.md
@@ -103,31 +103,34 @@ The [command line flags](cli) `--sequence` and `--codec` will take precedence ov
The JPEG quality of each frame. Must be a number between 0 and 100. [Default: 80](https://github.com/chromium/chromium/blob/99314be8152e688bafbbf9a615536bdbb289ea87/headless/lib/browser/protocol/headless_handler.cc#L32).
```tsx
-Config.output.setQuality(90);
+Config.Output.setQuality(90);
```
The [command line flag](cli) `--quality` will take precedence over this option.
### setCrf()
-To set Constant Rate Factor (CRF) of the output. Use this rate control mode if you want to keep the best quality and care less about the file size.
-This is the recommended rate control mode for most uses.
+To set Constant Rate Factor (CRF) of the output. [Use this setting to choose how to make the tradeoff between size and quality.](encoding#controlling-quality-using-the-crf-setting)
-Ranges for CRF scale, by codec:-
+Ranges for CRF scale, by codec:
- `h264` crf range is 0-51 where crf 18 is _default_.
- `h265` crf range is 0-51 where crf 23 is _default_.
- `vp8` crf range is 4-63 where crf 9 is _default_.
-- `vp9` crf range is 0-63 where crf 28 is _default_.
+- `vp9` crf range is 0-63 where crf 28 is _default_.
-Where 0 is lossless, 23 is the default for `h264`, and 51 is worst quality possible for `h264` and `h265` codec. A lower value generally leads to higher quality.
+Where the lowest value is lossless, and the highest is the worst quality possible. A lower value generally leads to higher quality.
The range is exponential, so increasing the CRF value +6 results in roughly half the bitrate / file size, while -6 leads to roughly twice the bitrate.
Choose the highest CRF value that still provides an acceptable quality. If the output looks good, then try a higher value. If it looks bad, choose a lower value.
```tsx
-Config.output.setCrf(16);
+Config.Output.setCrf(16);
```
The [command line flag](cli) `--crf` will take precedence over this option.
+
+## See also
+
+- [Encoding guide](encoding)
diff --git a/packages/docs/docs/encoding.md b/packages/docs/docs/encoding.md
new file mode 100644
index 0000000000..7a5d58db16
--- /dev/null
+++ b/packages/docs/docs/encoding.md
@@ -0,0 +1,135 @@
+---
+id: encoding
+title: Encoding Guide
+---
+
+Backed by [FFMPEG](https://ffmpeg.org/), Remotion allows you to configure a variety of encoding settings. The goal of this page is to help you navigate through the settings and to help you choose the right one.
+
+## Choosing a codec
+
+Remotion supports 4 codecs: `h264` (_default_), `h265`, `vp8` and `vp9`. The first two produce an output that will be an MP4, the last two are for generating WebM videos. While H264 will work well in most cases, sometimes it's worth going for a different codec. Refer to the table below to see the advantages and drawbacks of each codec.
+
+<table>
+ <tr>
+ <th>Codec</th>
+ <th>File extension</th>
+ <th>File size</th>
+ <th>Rendering time</th>
+ <th>Browser compatibility</th>
+ </tr>
+ <tr>
+ <td>H.264 <sub>also known as MPEG-4</sub></td>
+ <td>.mp4</td>
+ <td style={{color: 'red'}}>Large</td>
+ <td style={{color: 'green', fontWeight: 'bold'}}>Very fast</td>
+ <td><a href="https://caniuse.com/mpeg4" style={{color: 'green', fontWeight: 'bold'}}>Very good</a></td>
+ </tr>
+ <tr>
+ <td>H.265 <sub>also known as HEVC</sub></td>
+ <td>.mp4 or .hevc</td>
+ <td style={{color: 'darkorange'}}>Medium</td>
+ <td style={{color: 'green'}}>Fast</td>
+ <td><a href="https://caniuse.com/hevc" style={{color: 'red', fontWeight: 'bold'}}>Very poor</a></td>
+ </tr>
+ <tr>
+ <td>VP8</td>
+ <td>.webm</td>
+ <td style={{color: 'green'}}>Small</td>
+ <td style={{color: 'red'}}>Slow</td>
+ <td><a href="https://caniuse.com/webm" style={{color: 'darkorange'}}>Okay</a></td>
+ </tr>
+ <tr>
+ <td>VP9</td>
+ <td>.webm</td>
+ <td style={{color: 'green', fontWeight: 'bold'}}>Very small</td>
+ <td style={{color: 'red', fontWeight: 'bold'}}>Very slow</td>
+ <td><a href="https://caniuse.com/webm" style={{color: 'darkorange'}}>Okay</a></td>
+ </tr>
+</table>
+
+:::info
+Click on a browser compatibility link to see exactly which browsers are supported on caniuse.com.
+:::
+
+You can set a config using [`Config.Output.setCodec()` in the config file](config#setcodec) or the [`--codec`](cli) CLi flag.
+
+## Controlling quality using the CRF setting
+
+No matter which codec to use, you have to choose a tradeoff between file size and video quality. You can control it by setting the so called CRF (Constant Rate Factor). The **lower the number, the better the quality** is, the higher the number, the smaller the file is - of course at the cost of quality.
+
+Be cautious: Every codec has it's own range of acceptable values and a different default. So while `23` will look very good on a H264 video, it will look terrible on a WebM video. Use this chart to determine which CRF value to use:
+
+<table>
+<tr>
+<th>
+Codec
+</th>
+<th>
+Minimum - Best quality
+</th>
+<th>
+Maximum - Best compression
+</th>
+<th>
+Default
+</th>
+</tr>
+<tr>
+<td>
+H264
+</td>
+<td>
+0
+</td>
+<td>
+51</td>
+<td>
+18
+</td>
+</tr>
+<tr>
+<td>
+H265
+</td>
+<td>
+0
+</td>
+<td>
+51</td>
+<td>
+23
+</td>
+</tr>
+<tr>
+<td>
+VP8
+</td>
+<td>
+4
+</td>
+<td>
+63</td>
+<td>
+9
+</td>
+</tr>
+<tr>
+<td>
+VP9
+</td>
+<td>
+0
+</td>
+<td>
+63</td>
+<td>
+31
+</td>
+</tr>
+</table>
+
+You can [set a CRF in the config file using the `Config.Output.setCrf()`](config#setcrf) function or use the [`--crf`](cli#flags) command line flag.
+
+## 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/JonnyBurger/remotion/issues)
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 4423b2b040..fb029bfeb0 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -24,6 +24,7 @@ module.exports = {
"use-img-and-iframe",
"javascript",
"using-randomness",
+ "encoding",
],
},
{