packages/docs/docs/webcodecs/default-on-video-track-handler.mdx
:::warning We are phasing out Remotion WebCodecs and are moving to Mediabunny! :::
This is the default function if no onVideoTrack 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, defaultOnAudioTrackHandler} from '@remotion/webcodecs';
await convertMedia({
src: 'https://remotion.media/BigBuckBunny.mp4',
container: 'webm',
onAudioTrack: (params) => {
// Custom logic for handling video tracks
// ...
// Fall back to the default behavior
return defaultOnAudioTrackHandler(params);
},
});
The default behavior is as follows:
videoCodec which was passed to convertMedia() or the default codec for the container.{type: 'drop'} to remove the video track, but still succeed the other tracks.import {canReencodeVideoTrack, getDefaultVideoCodec, ConvertMediaOnVideoTrackHandler, VideoOperation} from '@remotion/webcodecs';
export const defaultOnVideoTrackHandler: ConvertMediaOnVideoTrackHandler = async ({track, defaultVideoCodec, logLevel, outputContainer, rotate, inputContainer, canCopyTrack, resizeOperation}): Promise<VideoOperation> => {
if (canCopyTrack) {
return Promise.resolve({type: 'copy'});
}
// If for example exporting to audio, the default video codec will be null
if (defaultVideoCodec === null) {
return Promise.resolve({type: 'drop'});
}
const canReencode = await canReencodeVideoTrack({
videoCodec: defaultVideoCodec,
track,
resizeOperation,
rotate,
});
if (canReencode) {
return Promise.resolve({
type: 'reencode',
videoCodec: defaultVideoCodec,
rotation: rotate - track.rotation,
});
}
return Promise.resolve({type: 'fail'});
};