Function: mixAudio()
ts
function mixAudio(
videoPath,
audioPath,
options?
): Promise<MixAudioResult>;Mix (or replace) an external audio track, such as background music or a voice-over, into a video. The video stream is copied unchanged, so only the audio is re-encoded. Only local files are supported.
Parameters
| Parameter | Type | Description |
|---|---|---|
videoPath | string | Local path of the source video. |
audioPath | string | Local path of the audio to mix in. |
options | Partial<MixAudioOptions> | Volumes, start offset and looping. |
Returns
Promise<MixAudioResult>
The path and duration of the output video, written to the cache directory.
Throws
Error synchronously when either path is empty.
Example
ts
// Replace the original audio with a voice-over
const { outputPath } = await mixAudio(videoPath, voiceOverPath, {
originalAudioVolume: 0,
});