提取音频()v4.0.49
🌐 extractAudio()v4.0.49
从视频源中提取音频并保存到指定的输出路径。它不会将音频转换为不同的格式。
🌐 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
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 ,
});传递一个绝对路径给 extractAudio()。不支持 URL。
参数
🌐 Arguments
一个包含以下属性的对象:
🌐 An object containing the following properties:
videoSource
string
将要提取音频的视频源的路径。
🌐 The path to the video source from which the audio will be extracted.
outputPath
string
提取的音频将保存的路径。文件扩展名必须与音频编解码器匹配。要找到合适的文件扩展名,请使用 getVideoMetadata() 来读取字段 audioFileExtension。
🌐 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 trace, verbose, info, warn, error.Determines how much info is being logged to the console.
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
该函数返回一个 Promise<void>,在音频提取完成后会被解析。
🌐 The function returns a Promise<void>, which resolves once the audio extraction is complete.
兼容性
🌐 Compatibility
| Browsers | Servers | Environments | |||||||
|---|---|---|---|---|---|---|---|---|---|
Chrome | Firefox | Safari | Node.js | Bun | Serverless Functions | ||||
另请参阅
🌐 See also