packages/docs/docs/webcodecs/default-on-audio-track-handler.mdx
:::warning We are phasing out Remotion WebCodecs and are moving to Mediabunny! :::
This is the default function if no onAudioTrack handler is provided to convertMedia().
You may use this function if you want to customize part of the track transformation logic, but fall back to the default behavior for the rest.
import {convertMedia, defaultOnVideoTrackHandler} from '@remotion/webcodecs';
await convertMedia({
src: 'https://remotion.media/BigBuckBunny.mp4',
container: 'webm',
onVideoTrack: (params) => {
// Custom logic for handling video tracks
// ...
// Fall back to the default behavior
return defaultOnVideoTrackHandler(params);
},
});
The default behavior is as follows:
audioCodec which was passed to convertMedia() or the default codec for the container.{type: 'drop'} to remove the audio track, but still succeed the other tracks.This is the source code for the default function. You may use this as a reference to create your own custom handler.
import {canReencodeAudioTrack, AudioOperation, ConvertMediaOnAudioTrackHandler, getDefaultAudioCodec} from '@remotion/webcodecs';
const DEFAULT_BITRATE = 128_000;
export const defaultOnAudioTrackHandler: ConvertMediaOnAudioTrackHandler = async ({track, defaultAudioCodec, logLevel, inputContainer, outputContainer, canCopyTrack}): Promise<AudioOperation> => {
const bitrate = DEFAULT_BITRATE;
if (canCopyTrack) {
return Promise.resolve({type: 'copy'});
}
// In the future, we might support containers that don't support audio
// (like GIF, animated WebP, etc.) - in that case, we should drop the audio
if (defaultAudioCodec === null) {
return Promise.resolve({type: 'drop'});
}
const canReencode = await canReencodeAudioTrack({
audioCodec: defaultAudioCodec,
track,
bitrate,
sampleRate: null,
});
if (canReencode) {
return Promise.resolve({
type: 'reencode',
bitrate,
audioCodec: defaultAudioCodec,
sampleRate: null,
});
}
return Promise.resolve({type: 'fail'});
};