canReencodeAudioTrack()
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 an AudioTrack
, determine if it can be re-encoded to another track.
You can obtain an AudioTrack
using parseMedia()
or during the conversion process using the onAudioTrack
callback of convertMedia()
.
Examples
Check if an audio track can be re-encoded to Opustsx
import {parseMedia } from '@remotion/media-parser';import {canReencodeAudioTrack } from '@remotion/webcodecs';const {audioTracks } = awaitparseMedia ({src : 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',fields : {tracks : true,},});for (consttrack ofaudioTracks ) {awaitcanReencodeAudioTrack ({track ,audioCodec : 'opus',bitrate : 128000,});}
Check if an audio track can be re-encoded to Opustsx
import {parseMedia } from '@remotion/media-parser';import {canReencodeAudioTrack } from '@remotion/webcodecs';const {audioTracks } = awaitparseMedia ({src : 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',fields : {tracks : true,},});for (consttrack ofaudioTracks ) {awaitcanReencodeAudioTrack ({track ,audioCodec : 'opus',bitrate : 128000,});}
Convert an audio track to Opus, otherwise drop ittsx
import {convertMedia ,canReencodeAudioTrack } from '@remotion/webcodecs';awaitconvertMedia ({src : 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',container : 'webm',videoCodec : 'vp8',audioCodec : 'opus',onAudioTrack : async ({track }) => {constcanReencode = awaitcanReencodeAudioTrack ({track ,audioCodec : 'opus',bitrate : 128000,});if (canReencode ) {return {type : 'reencode',audioCodec : 'opus',bitrate : 128000};}return {type : 'drop'};},});
Convert an audio track to Opus, otherwise drop ittsx
import {convertMedia ,canReencodeAudioTrack } from '@remotion/webcodecs';awaitconvertMedia ({src : 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',container : 'webm',videoCodec : 'vp8',audioCodec : 'opus',onAudioTrack : async ({track }) => {constcanReencode = awaitcanReencodeAudioTrack ({track ,audioCodec : 'opus',bitrate : 128000,});if (canReencode ) {return {type : 'reencode',audioCodec : 'opus',bitrate : 128000};}return {type : 'drop'};},});
API
track
A AudioTrack
object.
audioCodec
string ConvertMediaAudioCodec
bitrate
number
The bitrate with which you'd like to re-encode the audio track.
Return value
Returns a Promise<boolean>
.