extractAudio()v4.0.49
note
This function is meant to be used in Node.js applications. It cannot run in the browser.
Extracts the audio from a video source and saves it to the specified output path. It does not convert the audio to a different format.
Example
ts
import {resolve } from "node:path";import {extractAudio ,getVideoMetadata } from "@remotion/renderer";constvideoSource =resolve (process .cwd (), "/Users/john/path-to-video.mp4");constvideoMetadata = awaitgetVideoMetadata (videoSource );constaudioOutput =resolve (process .cwd (),`./output-audio-path.${videoMetadata .audioFileExtension }`,);awaitextractAudio ({videoSource ,audioOutput ,});
ts
import {resolve } from "node:path";import {extractAudio ,getVideoMetadata } from "@remotion/renderer";constvideoSource =resolve (process .cwd (), "/Users/john/path-to-video.mp4");constvideoMetadata = awaitgetVideoMetadata (videoSource );constaudioOutput =resolve (process .cwd (),`./output-audio-path.${videoMetadata .audioFileExtension }`,);awaitextractAudio ({videoSource ,audioOutput ,});
info
Pass an absolute path to extractAudio()
. URLs are not supported.
Arguments
An object containing the following properties:
videoSource
string
The path to the video source from which the audio will be extracted.
outputPath
string
The path where the extracted audio will be saved. The file extension must match the audio codec. To find the appropriate file extension, use getVideoMetadata()
to read the field audioFileExtension
.
logLevel?
One of verbose
, info
, warn
, error
.Determines how much is being logged to the console.
verbose
will also log console.log
's from the browser.Default
info
.binariesDirectory?
v4.0.120
The directory where the platform-specific binaries and libraries that Remotion needs are located. Those include an ffmpeg
and ffprobe
binary, a Rust binary for various tasks, and various shared libraries. If the value is set to null
, which is the default, then the path of a platform-specific package located at node_modules/@remotion/compositor-*
is selected.This option is useful in environments where Remotion is not officially supported to run like bundled serverless functions or Electron.
Return Value
The function returns a Promise<void>
, which resolves once the audio extraction is complete.