canRenderAudioCodec()
Very experimental feature - expect bugs and breaking changes at any time.
Track progress on GitHub and discuss in the #web-renderer channel on Discord.
Available from v4.0.401 - Part of the @remotion/web-renderer package.
Checks if the browser supports encoding audio with the specified codec and options. Use this function to verify browser capabilities before attempting to render.
Example usagetsximport {canRenderAudioCodec } from '@remotion/web-renderer';constcanRender = awaitcanRenderAudioCodec ('aac', {sampleRate : 44100,numberOfChannels : 2,bitrate : 'medium',});if (canRender ) {console .log ('AAC encoding is supported!');} else {console .log ('AAC encoding is not supported, try opus instead.');}
Arguments
codec
string WebRendererAudioCodec
The audio codec to check support for. One of:
"aac"- AAC codec (widely supported, used in MP4)"opus"- Opus codec (used in WebM)
options?
object CanRenderAudioCodecOptions
An optional object with the following properties:
numberOfChannels?
number
The number of audio channels (e.g., 2 for stereo).
sampleRate?
number
The audio sample rate in Hz (e.g., 44100 or 48000).
bitrate?
number | string WebRendererQuality
The target bitrate for encoding. Can be either:
- A number representing bits per second
- A quality preset:
"very-low","low","medium","high", or"very-high"
Return value
Returns Promise<boolean> - resolves to true if the browser supports encoding with the specified configuration, false otherwise.
Example: Finding a supported codec
Find supported audio codectsximport {canRenderAudioCodec } from '@remotion/web-renderer';import type {WebRendererAudioCodec } from '@remotion/web-renderer';constfindSupportedAudioCodec = async ():Promise <WebRendererAudioCodec | null> => {constcodecs :WebRendererAudioCodec [] = ['aac', 'opus'];for (constcodec ofcodecs ) {if (awaitcanRenderAudioCodec (codec )) {returncodec ;}}return null;};constcodec = awaitfindSupportedAudioCodec ();console .log ('Supported audio codec:',codec );