packages/docs/docs/webcodecs/can-reencode-video-track.mdx
:::warning We are phasing out Remotion WebCodecs and are moving to Mediabunny! :::
Part of the @remotion/webcodecs package.
:::warning Unstable API: This package is experimental. We might change the API at any time, until we remove this notice. :::
Given a VideoTrack, determine if it can be re-encoded to another track.
You can obtain a VideoTrack using parseMedia() or during the conversion process using the onVideoTrack callback of convertMedia().
import {parseMedia} from '@remotion/media-parser';
import {canReencodeVideoTrack} from '@remotion/webcodecs';
const {tracks} = await parseMedia({
src: 'https://remotion.media/BigBuckBunny.mp4',
fields: {
tracks: true,
},
});
const videoTracks = tracks.filter((t) => t.type === 'video');
for (const track of videoTracks) {
await canReencodeVideoTrack({
track,
videoCodec: 'vp8',
resizeOperation: null,
rotate: null,
});
}
import {convertMedia, canReencodeVideoTrack} from '@remotion/webcodecs';
await convertMedia({
src: 'https://remotion.media/BigBuckBunny.mp4',
container: 'webm',
videoCodec: 'vp8',
audioCodec: 'opus',
onVideoTrack: async ({track, resizeOperation, rotate}) => {
const canReencode = await canReencodeVideoTrack({
track,
videoCodec: 'vp8',
resizeOperation,
rotate,
});
if (canReencode) {
return {type: 'reencode', videoCodec: 'vp8'};
}
return {type: 'drop'};
},
});
trackA VideoTrack object.
videoCodecstring <TsType type="ConvertMediaVideoCodec" source="@remotion/webcodecs" />
One of the supported video codecs: "vp8", "vp9".
resizeOperationThe resize operation you would like to apply.
rotateThe rotate operation you would like to apply.
Returns a Promise<boolean>.