🎥 Make videos programmatically with React
support webp
Jonny Burger410de1751ee1
diff --git a/packages/cli/src/determine-image-format.ts b/packages/cli/src/determine-image-format.tsindex 680327ea37..94d631f5cb 100644--- a/packages/cli/src/determine-image-format.ts+++ b/packages/cli/src/determine-image-format.ts@@ -19,6 +19,10 @@ const deriveExtensionFromFilename = (return 'pdf';}+ if (filename?.endsWith('.webp')) {+ return 'webp';+ }+return null;};diff --git a/packages/docs/docs/cli/still.md b/packages/docs/docs/cli/still.mdindex 0520a7cdca..758f7037ff 100644--- a/packages/docs/docs/cli/still.md+++ b/packages/docs/docs/cli/still.md@@ -30,7 +30,7 @@ Inline JSON string isn't supported on Windows because it removes the `"` charact### `--image-format`-`jpeg`, `png` or `pdf`. The default is `png`.+`jpeg`, `png`, `webp` or `pdf`. The default is `png`.### `--config`diff --git a/packages/docs/docs/clipper.md b/packages/docs/docs/clipper.mdindex f232f28330..dce80c160e 100644--- a/packages/docs/docs/clipper.md+++ b/packages/docs/docs/clipper.md@@ -13,7 +13,7 @@ The API may change in any version. Monitor this documentation page to see breakiThis is a special component that will cause Remotion to only partially capture the frame of the video. The remaining area will stay black (if the render image format is `jpeg`) or transparent (if the render image format is `png`).-This component cannot be used if you use [`renderStill()`](/docs/renderer/render-still) to render a PDF.+This component cannot be used if you use [`renderStill()`](/docs/renderer/render-still) to render a PDF or WebP.## Examplediff --git a/packages/docs/docs/config.md b/packages/docs/docs/config.mdindex be1f2fe21f..0977909c04 100644--- a/packages/docs/docs/config.md+++ b/packages/docs/docs/config.md@@ -300,6 +300,7 @@ Determines which in which image format to render the frames. Either:- `png` (default)- `jpeg`- `pdf`+- `webp````ts twoslash title="remotion.config.ts"import { Config } from "@remotion/cli/config";diff --git a/packages/docs/docs/lambda/renderstillonlambda.md b/packages/docs/docs/lambda/renderstillonlambda.mdindex 78344b446d..98f99cd070 100644--- a/packages/docs/docs/lambda/renderstillonlambda.md+++ b/packages/docs/docs/lambda/renderstillonlambda.md@@ -83,7 +83,7 @@ From v3.2.27, negative values are allowed, with `-1` being the last frame._optional - default `"png"`_-The image format that you want - either `"png"`, `"jpeg"` or `"pdf"`.+The image format that you want - either `"png"`, `"jpeg"`, `"webp"` or `"pdf"`.### `quality?`diff --git a/packages/docs/docs/renderer/render-still.md b/packages/docs/docs/renderer/render-still.mdindex b36089afc7..4a510a0352 100644--- a/packages/docs/docs/renderer/render-still.md+++ b/packages/docs/docs/renderer/render-still.md@@ -87,7 +87,7 @@ From v3.2.27, negative values are allowed, with `-1` being the last frame._optional - default: "png"_-Which output format the image should have, either `png`, `jpeg` or `pdf`.+Which output format the image should have, either `png`, `jpeg`, `webp` or `pdf`.### `scale?`diff --git a/packages/docs/docs/stills.md b/packages/docs/docs/stills.mdindex 477de49402..7b2039e7f0 100644--- a/packages/docs/docs/stills.md+++ b/packages/docs/docs/stills.md@@ -23,7 +23,7 @@ You can use the [`npx remotion still`](/docs/cli/#npx-remotion-still) command tonpx remotion still --props='{"custom": "data"}' my-comp out.png```-You can use the `--image-format` flag to determine the output format. The default format is `png`, with `jpeg` and `pdf` being the other options.+You can use the `--image-format` flag to determine the output format. The default format is `png`, with `jpeg`, `webp` and `pdf` being the other options.By default the frame with number of a composition is being rendered, you can control it using the `--frame` flag.diff --git a/packages/renderer/src/image-format.ts b/packages/renderer/src/image-format.tsindex ba0a482ce0..b361086a4c 100644--- a/packages/renderer/src/image-format.ts+++ b/packages/renderer/src/image-format.ts@@ -4,7 +4,7 @@import type {PixelFormat} from './pixel-format';export const validVideoImageFormats = ['png', 'jpeg', 'none'] as const;-export const validStillImageFormats = ['png', 'jpeg', 'pdf'] as const;+export const validStillImageFormats = ['png', 'jpeg', 'pdf', 'webp'] as const;export type VideoImageFormat = typeof validVideoImageFormats[number];export type StillImageFormat = typeof validStillImageFormats[number];diff --git a/packages/renderer/src/screenshot-dom-element.ts b/packages/renderer/src/screenshot-dom-element.tsindex 6895f64a92..ebe5faf0f9 100644--- a/packages/renderer/src/screenshot-dom-element.ts+++ b/packages/renderer/src/screenshot-dom-element.ts@@ -25,7 +25,11 @@ export const screenshotDOMElement = async ({}): Promise<Buffer> => {const {path} = opts;- if (imageFormat === 'png' || imageFormat === 'pdf') {+ if (+ imageFormat === 'png' ||+ imageFormat === 'pdf' ||+ imageFormat === 'webp'+ ) {await puppeteerEvaluateWithCatch({pageFunction: () => {document.body.style.background = 'transparent';diff --git a/packages/renderer/src/take-frame-and-compose.ts b/packages/renderer/src/take-frame-and-compose.tsindex 5d22829d45..f11aa6c7c5 100644--- a/packages/renderer/src/take-frame-and-compose.ts+++ b/packages/renderer/src/take-frame-and-compose.ts@@ -103,6 +103,12 @@ export const takeFrameAndCompose = async ({);}+ if (imageFormat === 'webp') {+ throw new Error(+ "You cannot use compositor APIs (like <Clipper>) if `imageFormat` is 'webp'."+ );+ }+await compose({height: height * scale,width: width * scale,diff --git a/packages/renderer/src/test/render-still.test.ts b/packages/renderer/src/test/render-still.test.tsindex 792c9400e9..0b9d1458b4 100644--- a/packages/renderer/src/test/render-still.test.ts+++ b/packages/renderer/src/test/render-still.test.ts@@ -82,5 +82,7 @@ test('Catches invalid image format', () => {output: '/file/output.png',serveUrl: 'https://gleaming-wisp-de5d2a.netlify.app/',})- ).rejects.toThrow(/Image format should be either "png", "jpeg" or "pdf"/);+ ).rejects.toThrow(+ /Image format should be either "png", "jpeg", "pdf" or "webp"/+ );});diff --git a/packages/renderer/src/test/validate-image-format.test.ts b/packages/renderer/src/test/validate-image-format.test.tsindex 8dbde0a76f..fc1c798851 100644--- a/packages/renderer/src/test/validate-image-format.test.ts+++ b/packages/renderer/src/test/validate-image-format.test.ts@@ -7,6 +7,6 @@ test('"none" is not a valid image format', () => {expect(() => validateStillImageFormat('pdf')).not.toThrow();// @ts-expect-errorexpect(() => validateStillImageFormat('none')).toThrow(- /Image format should be one of: "png", "jpeg", "pdf"/+ /Image format should be one of: "png", "jpeg", "pdf", "webp"/);});