Skip to content

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 ​

ParameterTypeDescription
videoPathstringLocal path of the source video.
audioPathstringLocal path of the audio to mix in.
optionsPartial<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,
});

Released under the MIT License.