canReencodeAudioTrack()
属于 @remotion/webcodecs 软件包的一部分.
🌐 Part of the @remotion/webcodecs package.
不稳定的 API:此软件包处于实验阶段。在我们移除此提示之前,API 可能随时更改。
给定一个 AudioTrack,确定它是否可以重新编码到另一条轨道。
🌐 Given an AudioTrack, determine if it can be re-encoded to another track.
你可以使用 parseMedia() 获取 AudioTrack,或者在使用 convertMedia() 的 onAudioTrack 回调的转换过程中获取。
🌐 You can obtain an AudioTrack using parseMedia() or during the conversion process using the onAudioTrack callback of convertMedia().
示例
🌐 Examples
Check if audio tracks can be re-encoded to Opusimport {parseMedia } from '@remotion/media-parser'; import {canReencodeAudioTrack } from '@remotion/webcodecs'; const {tracks } = awaitparseMedia ({src : 'https://remotion.media/BigBuckBunny.mp4',fields : {tracks : true, }, }); constaudioTracks =tracks .filter ((t ) =>t .type === 'audio'); for (consttrack ofaudioTracks ) { awaitcanReencodeAudioTrack ({track ,audioCodec : 'opus',bitrate : 128000,sampleRate : null, }); }
Convert an audio track to Opus, otherwise drop itimport {convertMedia ,canReencodeAudioTrack } from '@remotion/webcodecs'; awaitconvertMedia ({src : 'https://remotion.media/BigBuckBunny.mp4',container : 'webm',videoCodec : 'vp8',audioCodec : 'opus',onAudioTrack : async ({track }) => { constcanReencode = awaitcanReencodeAudioTrack ({track ,audioCodec : 'opus',bitrate : 128000,sampleRate : null, }); if (canReencode ) { return {type : 'reencode',audioCodec : 'opus',bitrate : 128000,sampleRate : null}; } return {type : 'drop'}; }, });
应用编程接口
🌐 API
track
一个 AudioTrack 对象。
🌐 A AudioTrack object.
audioCodec
字符串 ConvertMediaAudioCodec
🌐 string ConvertMediaAudioCodec
bitrate
number
你希望重新编码音轨时使用的比特率。
🌐 The bitrate with which you'd like to re-encode the audio track.
sampleRate
数字 | null
🌐 number | null
你希望重新编码音轨的采样率。如果 sampleRate 为 null,则将使用原始音轨的采样率。
🌐 The sample rate with which you'd like to re-encode the audio track. If the sampleRate is null, the sample rate of the original track will be used.
返回值
🌐 Return value
返回一个 Promise<boolean>。
🌐 Returns a Promise<boolean>.
另请参阅
🌐 See also