canCopyVideoTrack()
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 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 copiedtsx
import {parseMedia } from '@remotion/media-parser';import {canCopyVideoTrack } from '@remotion/webcodecs';const {videoTracks } = awaitparseMedia ({src : 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',fields : {tracks : true,},});for (consttrack ofvideoTracks ) {canCopyVideoTrack ({inputCodec :track .codecWithoutConfig ,container : 'webm',}); // boolean}
Check if a video tracks can be copiedtsx
import {parseMedia } from '@remotion/media-parser';import {canCopyVideoTrack } from '@remotion/webcodecs';const {videoTracks } = awaitparseMedia ({src : 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',fields : {tracks : true,},});for (consttrack ofvideoTracks ) {canCopyVideoTrack ({inputCodec :track .codecWithoutConfig ,container : 'webm',}); // boolean}
Copy a video track to VP8, otherwise drop ittsx
import {convertMedia ,canCopyVideoTrack } from '@remotion/webcodecs';awaitconvertMedia ({src : 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',container : 'webm',videoCodec : 'vp8',audioCodec : 'opus',onVideoTrack : async ({track }) => {constcanCopy =canCopyVideoTrack ({inputCodec :track .codecWithoutConfig ,container : 'webm',});if (canCopy ) {return {type : 'copy'};}// In reality, you would re-encode the track herereturn {type : 'drop'};},});
Copy a video track to VP8, otherwise drop ittsx
import {convertMedia ,canCopyVideoTrack } from '@remotion/webcodecs';awaitconvertMedia ({src : 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',container : 'webm',videoCodec : 'vp8',audioCodec : 'opus',onVideoTrack : async ({track }) => {constcanCopy =canCopyVideoTrack ({inputCodec :track .codecWithoutConfig ,container : 'webm',});if (canCopy ) {return {type : 'copy'};}// In reality, you would re-encode the track herereturn {type : 'drop'};},});
API
inputCodec
string MediaParserVideoCodec
The codec of the input video track.
container
string ConvertMediaContainer
The container format of the output media.
Return value
Returns a boolean
.