|
| 1 | +--- |
| 2 | +image: /generated/articles-docs-web-renderer-can-render-media-on-web.png |
| 3 | +id: can-render-media-on-web |
| 4 | +title: canRenderMediaOnWeb() |
| 5 | +crumb: '@remotion/web-renderer' |
| 6 | +--- |
| 7 | + |
| 8 | +:::warning |
| 9 | +Very experimental feature - expect bugs and breaking changes at any time. |
| 10 | +[Track progress on GitHub](https://github.com/remotion-dev/remotion/issues/5913) and discuss in the [`#web-renderer`](https://remotion.dev/discord) channel on Discord. |
| 11 | +::: |
| 12 | + |
| 13 | +_Part of the `@remotion/web-renderer` package._ |
| 14 | + |
| 15 | +Checks if a render can be performed with the given configuration before actually attempting it. |
| 16 | +This is useful for providing feedback to users about browser compatibility and configuration issues. |
| 17 | + |
| 18 | +```tsx twoslash title="Example usage" |
| 19 | +import {canRenderMediaOnWeb} from '@remotion/web-renderer'; |
| 20 | + |
| 21 | +const result = await canRenderMediaOnWeb({ |
| 22 | + container: 'mp4', |
| 23 | + videoCodec: 'h264', |
| 24 | + width: 1920, |
| 25 | + height: 1080, |
| 26 | +}); |
| 27 | + |
| 28 | +if (!result.canRender) { |
| 29 | + for (const issue of result.issues) { |
| 30 | + console.error(issue.message); |
| 31 | + } |
| 32 | +} else { |
| 33 | + console.log('Ready to render!'); |
| 34 | + console.log('Video codec:', result.resolvedVideoCodec); |
| 35 | + console.log('Audio codec:', result.resolvedAudioCodec); |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +## Arguments |
| 40 | + |
| 41 | +An object with the following properties: |
| 42 | + |
| 43 | +### `width` |
| 44 | + |
| 45 | +_number - required_ |
| 46 | + |
| 47 | +The width of the video in pixels. |
| 48 | + |
| 49 | +### `height` |
| 50 | + |
| 51 | +_number - required_ |
| 52 | + |
| 53 | +The height of the video in pixels. |
| 54 | + |
| 55 | +### `container?` |
| 56 | + |
| 57 | +_string_ <TsType type="WebRendererContainer" source="@remotion/web-renderer" /> |
| 58 | + |
| 59 | +The container format. Default is `"mp4"`. |
| 60 | + |
| 61 | +### `videoCodec?` |
| 62 | + |
| 63 | +_string_ <TsType type="WebRendererVideoCodec" source="@remotion/web-renderer" /> |
| 64 | + |
| 65 | +The video codec to use. Default depends on the container: |
| 66 | + |
| 67 | +- For `mp4` container: `"h264"` |
| 68 | +- For `webm` container: `"vp8"` |
| 69 | + |
| 70 | +### `audioCodec?` |
| 71 | + |
| 72 | +_string | null_ <TsType type="WebRendererAudioCodec" source="@remotion/web-renderer" /> |
| 73 | + |
| 74 | +The audio codec to use. Default depends on the container: |
| 75 | + |
| 76 | +- For `mp4` container: `"aac"` |
| 77 | +- For `webm` container: `"opus"` |
| 78 | + |
| 79 | +### `transparent?` |
| 80 | + |
| 81 | +_boolean_ |
| 82 | + |
| 83 | +Whether the video should have an alpha channel. Default is `false`. |
| 84 | + |
| 85 | +Only `vp8` and `vp9` codecs support transparency. |
| 86 | + |
| 87 | +### `muted?` |
| 88 | + |
| 89 | +_boolean_ |
| 90 | + |
| 91 | +If `true`, audio codec checks are skipped. Default is `false`. |
| 92 | + |
| 93 | +### `videoBitrate?` |
| 94 | + |
| 95 | +_number | string_ <TsType type="WebRendererQuality" source="@remotion/web-renderer" /> |
| 96 | + |
| 97 | +The video bitrate. Can be a number (bits per second) or a quality preset: `"very-low"`, `"low"`, `"medium"`, `"high"`, `"very-high"`. |
| 98 | + |
| 99 | +Default is `"medium"`. |
| 100 | + |
| 101 | +### `audioBitrate?` |
| 102 | + |
| 103 | +_number | string_ <TsType type="WebRendererQuality" source="@remotion/web-renderer" /> |
| 104 | + |
| 105 | +The audio bitrate. Can be a number (bits per second) or a quality preset: `"very-low"`, `"low"`, `"medium"`, `"high"`, `"very-high"`. |
| 106 | + |
| 107 | +Default is `"medium"`. |
| 108 | + |
| 109 | +### `outputTarget?` |
| 110 | + |
| 111 | +_string | null_ <TsType type="WebRendererOutputTarget" source="@remotion/web-renderer" /> |
| 112 | + |
| 113 | +The output target to use for rendering. Can be: |
| 114 | + |
| 115 | +- `"web-fs"`: Use the File System Access API for streaming writes to disk |
| 116 | +- `"arraybuffer"`: Buffer the entire video in memory |
| 117 | +- `null`: Auto-detect based on browser support (default) |
| 118 | + |
| 119 | +If `"web-fs"` is requested but not supported by the browser, an `output-target-unsupported` error will be returned. |
| 120 | + |
| 121 | +## Return value |
| 122 | + |
| 123 | +Returns a `Promise` that resolves to an object with the following properties: |
| 124 | + |
| 125 | +### `canRender` |
| 126 | + |
| 127 | +_boolean_ |
| 128 | + |
| 129 | +`true` if the render can proceed, `false` if there are blocking issues. |
| 130 | + |
| 131 | +### `issues` |
| 132 | + |
| 133 | +<TsType type="CanRenderIssue[]" source="@remotion/web-renderer" /> |
| 134 | + |
| 135 | +An array of issues found during the check. Each issue has: |
| 136 | + |
| 137 | +- `type`: The type of issue (see [Issue types](#issue-types) below) |
| 138 | +- `message`: A human-readable description of the issue |
| 139 | +- `severity`: Either `"error"` (blocking) or `"warning"` (non-blocking, e.g. fallback was used) |
| 140 | + |
| 141 | +### `resolvedVideoCodec` |
| 142 | + |
| 143 | +_string_ <TsType type="WebRendererVideoCodec" source="@remotion/web-renderer" /> |
| 144 | + |
| 145 | +The video codec that will be used for rendering. |
| 146 | + |
| 147 | +### `resolvedAudioCodec` |
| 148 | + |
| 149 | +_string | null_ <TsType type="WebRendererAudioCodec" source="@remotion/web-renderer" /> |
| 150 | + |
| 151 | +The audio codec that will be used for rendering. This may differ from the requested codec if a fallback was applied. `null` if `muted` is `true`. |
| 152 | + |
| 153 | +### `resolvedOutputTarget` |
| 154 | + |
| 155 | +<TsType type="WebRendererOutputTarget" source="@remotion/web-renderer" /> |
| 156 | + |
| 157 | +The output target that will be used. See [`renderMediaOnWeb()` outputTarget](/docs/web-renderer/render-media-on-web#outputtarget) for details. |
| 158 | + |
| 159 | +## Issue types |
| 160 | + |
| 161 | +The following issue types may be returned: |
| 162 | + |
| 163 | +| Type | Description | |
| 164 | +| ------------------------------- | ------------------------------------------------------------- | |
| 165 | +| `webcodecs-unavailable` | WebCodecs API is not available in this browser | |
| 166 | +| `container-codec-mismatch` | The video codec is not supported for the selected container | |
| 167 | +| `invalid-dimensions` | H.264 and H.265 require width and height to be multiples of 2 | |
| 168 | +| `video-codec-unsupported` | The browser cannot encode the selected video codec | |
| 169 | +| `audio-codec-unsupported` | The browser cannot encode the selected audio codec | |
| 170 | +| `transparent-video-unsupported` | Transparency requires VP8 or VP9 codec | |
| 171 | +| `webgl-unsupported` | WebGL is required for 3D CSS transforms | |
| 172 | +| `output-target-unsupported` | The requested output target is not supported by this browser | |
| 173 | + |
| 174 | +## See also |
| 175 | + |
| 176 | +- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/web-renderer/src/can-render-media-on-web.ts) |
| 177 | +- [`renderMediaOnWeb()`](/docs/web-renderer/render-media-on-web) |
| 178 | +- [Client-side rendering limitations](/docs/client-side-rendering/limitations) |
0 commit comments