canCopyVideoTrack()
Part of the @remotion/webcodecs package.
🚧 Unstable API
We might change the API at any time, until we remove this notice.
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().
Examples​
Check if a video tracks can be copiedtsximport {parseMedia } from '@remotion/media-parser';import {canCopyVideoTrack } from '@remotion/webcodecs';Âconst {tracks ,container } = awaitparseMedia ({src : 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.webm',fields : {tracks : true,container : true,},});ÂconstvideoTracks =tracks .filter ((t ) =>t .type === 'video');Âfor (consttrack ofvideoTracks ) {canCopyVideoTrack ({outputContainer : 'webm',inputTrack :track ,inputContainer :container ,rotationToApply : 0,resizeOperation : null,outputVideoCodec : null,}); // boolean}
Copy a video track to VP8, otherwise drop ittsximport {convertMedia ,canCopyVideoTrack } from '@remotion/webcodecs';ÂawaitconvertMedia ({src : 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.webm',container : 'webm',videoCodec : 'vp8',audioCodec : 'opus',onVideoTrack : async ({track ,inputContainer ,outputContainer }) => {constcanCopy =canCopyVideoTrack ({outputContainer ,inputTrack :track ,inputContainer ,rotationToApply : 0,resizeOperation : null,outputVideoCodec : null,});Âif (canCopy ) {return {type : 'copy'};}Â// In reality, you would re-encode the track herereturn {type : 'drop'};},});
API​
inputTrack​
string VideoTrack
The input video track.
rotationToApply​
number
The number of degrees to rotate the video track.
inputContainer​
string MediaParserContainer
The container format of the input media.
outputContainer​
string ConvertMediaContainer
The container format of the output media.
resizeOperation​
string ResizeOperation
The resize operation to apply to the video track.
outputVideoCodec​
string | null ConvertMediaVideoCodec
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.
Rotation behavior​
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
Return value​
Returns a boolean.