Skip to content

🎥 Make videos programmatically with React

disallow CRF 0

Jonny Burger8055684896a3
diff --git a/packages/core/src/config/crf.ts b/packages/core/src/config/crf.ts
index ab1c61eb95..201f829924 100644
--- a/packages/core/src/config/crf.ts
+++ b/packages/core/src/config/crf.ts
@@ -47,7 +47,7 @@ export const getValidCrfRanges = (codec: Codec): [number, number] => {
}
if (codec === 'h264') {
- return [0, 51];
+ return [1, 51];
}
if (codec === 'h265') {
@@ -70,6 +70,12 @@ export const validateSelectedCrfAndCodecCombination = (
codec: Codec
) => {
const range = getValidCrfRanges(codec);
+ if (crf === 0 && codec === 'h264') {
+ throw new TypeError(
+ "Setting the CRF to 0 with a H264 codec is not supported anymore because of it's inconsistencies between platforms. Videos with CRF 0 cannot be played on iOS/macOS. 0 is a extreme value with inefficient settings which you probably want. Set CRF to a higher value to fix this error."
+ );
+ }
+
if (crf < range[0] || crf > range[1]) {
throw new TypeError(
`CRF must be between ${range[0]} and ${range[1]} for codec ${codec}. Passed: ${crf}`
diff --git a/packages/core/src/test/crf.test.ts b/packages/core/src/test/crf.test.ts
index 2e50127ebc..40f2bce363 100644
--- a/packages/core/src/test/crf.test.ts
+++ b/packages/core/src/test/crf.test.ts
@@ -41,7 +41,7 @@ describe('crf tests getDefaultCrfForCodec invalid input', () => {
describe('crf tests getValidCrfRanges valid input', () => {
// input crf, input codec, valid range
const validInputs: [Codec, [number, number]][] = [
- ['h264', [0, 51]],
+ ['h264', [1, 51]],
['h265', [0, 51]],
['vp8', [4, 63]],
['vp9', [0, 63]],
@@ -72,7 +72,7 @@ describe('validateSelectedCrfAndCodecCombination valid input', () => {
// input crf, input codec
const validInputs: [number, Codec][] = [
[20, 'h264'],
- [0, 'h264'],
+ [1, 'h264'],
[51, 'h264'],
[20, 'h265'],
[0, 'h265'],
@@ -95,9 +95,9 @@ describe('validateSelectedCrfAndCodecCombination valid input', () => {
describe('validateSelectedCrfAndCodecCombination invalid input', () => {
// input crf, input codec, valid range
const invalidInputs: [number, Codec, [number, number]][] = [
- [80, 'h264', [0, 51]],
- [-1, 'h264', [0, 51]],
- [52, 'h264', [0, 51]],
+ [80, 'h264', [1, 51]],
+ [-1, 'h264', [1, 51]],
+ [52, 'h264', [1, 51]],
[80, 'h265', [0, 51]],
[-1, 'h265', [0, 51]],
[52, 'h265', [0, 51]],
@@ -142,7 +142,7 @@ describe('get crf valid input', () => {
describe('get crf invalid input', () => {
// input crf, input codec, valid range
const invalidInputs: [number, Codec, [number, number]][] = [
- [80, 'h264', [0, 51]],
+ [80, 'h264', [1, 51]],
[80, 'h265', [0, 51]],
[80, 'vp8', [4, 63]],
[80, 'vp9', [0, 63]],
diff --git a/packages/docs/docs/encoding.md b/packages/docs/docs/encoding.md
index 0bc7792235..4d2f7f19de 100644
--- a/packages/docs/docs/encoding.md
+++ b/packages/docs/docs/encoding.md
@@ -59,6 +59,17 @@ No matter which codec you end up using, there's always a tradeoff between file s
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:
+<details style={{fontSize: '0.9em'}}>
+<summary>
+Changelog
+</summary>
+<ul>
+<li>
+Since version 2.1.3, Remotion doesn't allow the CRF to be set to <code>0</code> anymore because of the issues it causes on macOS/iOS and possible other scenarios. Set the CRF to 1 or higher.
+</li>
+</ul>
+</details>
+<div style={{height: 10}}/>
<table>
<tr>
<th>
@@ -79,7 +90,7 @@ Default
H264
</td>
<td>
-0
+1
</td>
<td>
51</td>