canReencodeVideoTrack()
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()
.
Examples
Check if video tracks can be re-encoded to VP8tsx
import {parseMedia } from '@remotion/media-parser';import {canReencodeVideoTrack } from '@remotion/webcodecs';const {videoTracks } = awaitparseMedia ({src : 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',fields : {tracks : true,},});for (consttrack ofvideoTracks ) {awaitcanReencodeVideoTrack ({track ,videoCodec : 'vp8',});}
Check if video tracks can be re-encoded to VP8tsx
import {parseMedia } from '@remotion/media-parser';import {canReencodeVideoTrack } from '@remotion/webcodecs';const {videoTracks } = awaitparseMedia ({src : 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',fields : {tracks : true,},});for (consttrack ofvideoTracks ) {awaitcanReencodeVideoTrack ({track ,videoCodec : 'vp8',});}
Convert a video track to VP8, otherwise drop ittsx
import {convertMedia ,canReencodeVideoTrack } from '@remotion/webcodecs';awaitconvertMedia ({src : 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',container : 'webm',videoCodec : 'vp8',audioCodec : 'opus',onVideoTrack : async ({track }) => {constcanReencode = awaitcanReencodeVideoTrack ({track ,videoCodec : 'vp8',});if (canReencode ) {return {type : 'reencode',videoCodec : 'vp8'};}return {type : 'drop'};},});
Convert a video track to VP8, otherwise drop ittsx
import {convertMedia ,canReencodeVideoTrack } from '@remotion/webcodecs';awaitconvertMedia ({src : 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',container : 'webm',videoCodec : 'vp8',audioCodec : 'opus',onVideoTrack : async ({track }) => {constcanReencode = awaitcanReencodeVideoTrack ({track ,videoCodec : 'vp8',});if (canReencode ) {return {type : 'reencode',videoCodec : 'vp8'};}return {type : 'drop'};},});
API
track
A VideoTrack
object.
videoCodec
string ConvertMediaVideoCodec
One of the supported video codecs: "vp8"
, "vp9"
.
Return value
Returns a Promise<boolean>
.