packages/docs/docs/webcodecs/can-copy-video-track.mdx
:::warning We are phasing out Remotion WebCodecs and are moving to Mediabunny! :::
Part of the @remotion/webcodecs package.
import {UnstableDisclaimer} from './UnstableDisclaimer';
<details> <summary>🚧 Unstable API</summary> <UnstableDisclaimer /> </details>Given a VideoTrack, determine if it can be copied to the output without re-encoding.
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 {canCopyVideoTrack} from '@remotion/webcodecs';
const {tracks, container} = await parseMedia({
src: 'https://remotion.media/BigBuckBunny.webm',
fields: {
tracks: true,
container: true,
},
});
const videoTracks = tracks.filter((t) => t.type === 'video');
for (const track of videoTracks) {
canCopyVideoTrack({
outputContainer: 'webm',
inputTrack: track,
inputContainer: container,
rotationToApply: 0,
resizeOperation: null,
outputVideoCodec: null,
}); // boolean
}
import {convertMedia, canCopyVideoTrack} from '@remotion/webcodecs';
await convertMedia({
src: 'https://remotion.media/BigBuckBunny.webm',
container: 'webm',
videoCodec: 'vp8',
audioCodec: 'opus',
onVideoTrack: async ({track, inputContainer, outputContainer}) => {
const canCopy = canCopyVideoTrack({
outputContainer,
inputTrack: track,
inputContainer,
rotationToApply: 0,
resizeOperation: null,
outputVideoCodec: null,
});
if (canCopy) {
return {type: 'copy'};
}
// In reality, you would re-encode the track here
return {type: 'drop'};
},
});
inputTrackstring <TsType type="VideoTrack" source="@remotion/media-parser" />
The input video track.
rotationToApplynumber
The number of degrees to rotate the video track.
inputContainerstring <TsType type="MediaParserContainer" source="@remotion/media-parser" />
The container format of the input media.
outputContainerstring <TsType type="ConvertMediaContainer" source="@remotion/webcodecs" />
The container format of the output media.
resizeOperationstring <TsType type="ResizeOperation" source="@remotion/webcodecs" />
The resize operation to apply to the video track.
outputVideoCodecstring | null <TsType type="ConvertMediaVideoCodec" source="@remotion/webcodecs" />
The desired video codec of the output media. If null, it means you don't care about the video codec as long as it can be copied.
Any rotationToApply is in addition to an auto-rotation that is applied by default to fix the orientation of the video track.
If rotationToApply is not the same amount of rotation as inputRotation, this function will always return false, because rotation cannot be performed without re-encoding.
See: Rotating a video
Returns a boolean.