Skip to main content

canReencodeAudioTrack()

属于 @remotion/webcodecs 软件包的一部分.

🌐 Part of the @remotion/webcodecs package.

warning

不稳定的 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 Opus
import {parseMedia} from '@remotion/media-parser'; import {canReencodeAudioTrack} from '@remotion/webcodecs'; const {tracks} = await parseMedia({ src: 'https://remotion.media/BigBuckBunny.mp4', fields: { tracks: true, }, }); const audioTracks = tracks.filter((t) => t.type === 'audio'); for (const track of audioTracks) { await canReencodeAudioTrack({ track, audioCodec: 'opus', bitrate: 128000, sampleRate: null, }); }
Convert an audio track to Opus, otherwise drop it
import {convertMedia, canReencodeAudioTrack} from '@remotion/webcodecs'; await convertMedia({ src: 'https://remotion.media/BigBuckBunny.mp4', container: 'webm', videoCodec: 'vp8', audioCodec: 'opus', onAudioTrack: async ({track}) => { const canReencode = await canReencodeAudioTrack({ 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