Skip to main content

extractAudio()v4.0.49

note

此函数旨在用于 Node.js 应用程序。无法在浏览器中运行。

从视频源中提取音频并将其保存到指定的输出路径。它不会将音频转换为不同的格式。

示例​

ts
import { resolve } from "node:path";
import { extractAudio, getVideoMetadata } from "@remotion/renderer";
 
const videoSource = resolve(process.cwd(), "/Users/john/path-to-video.mp4");
 
const videoMetadata = await getVideoMetadata(videoSource);
const audioOutput = resolve(
process.cwd(),
`./output-audio-path.${videoMetadata.audioFileExtension}`,
);
 
await extractAudio({
videoSource,
audioOutput,
});
ts
import { resolve } from "node:path";
import { extractAudio, getVideoMetadata } from "@remotion/renderer";
 
const videoSource = resolve(process.cwd(), "/Users/john/path-to-video.mp4");
 
const videoMetadata = await getVideoMetadata(videoSource);
const audioOutput = resolve(
process.cwd(),
`./output-audio-path.${videoMetadata.audioFileExtension}`,
);
 
await extractAudio({
videoSource,
audioOutput,
});
info

将绝对路径传递给 extractAudio()。不支持 URL。

参数​

包含以下属性的对象:

videoSource​

string

要从中提取音频的视频源路径。

outputPath​

string

提取的音频将保存到的路径。文件扩展名必须与音频编解码器匹配。要找到适当的文件扩展名,请使用 getVideoMetadata() 读取字段 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.

返回值​

该函数返回一个 Promise<void>,一旦音频提取完成,该 Promise 将解析。

参见​