Skip to main content
Also available as a 2min video
以编程方式从视频中去除静音

getSilentParts()v4.0.18

在 Node.js 中获取视频或音频的静音部分。对于从视频中剪掉静音部分很有用。

🌐 Gets the silent parts of a video or audio in Node.js. Useful for cutting out silence from a video.

示例​

🌐 Example

silent-parts.mjs
import {getSilentParts} from '@remotion/renderer'; const {silentParts, durationInSeconds} = await getSilentParts({ src: '/Users/john/Documents/bunny.mp4', noiseThresholdInDecibels: -20, minDurationInSeconds: 1, }); console.log(silentParts); // [{startInSeconds: 0, endInSeconds: 1.5}]
info

传递一个绝对路径给 getSilentParts()。不支持 URL。

参数​

🌐 Arguments

一个具有以下属性的对象:

🌐 An object which takes the following properties:

source​

string

本地视频或音频文件路径。

🌐 A local video or audio file path.

noiseThresholdInDecibels?​

number

分贝阈值。如果音频低于此阈值,则被视为静音。默认值为 -20。必须小于 30。

🌐 The threshold in decibels. If the audio is below this threshold, it is considered silent. The default is -20. Must be less than 30.

minDurationInSeconds?​

number

静默部分的最短持续时间(秒)。默认值为 1。

🌐 The minimum duration of a silent part in seconds. The default is 1.

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

返回值是一个具有以下属性的对象:

🌐 The return value is an object with the following properties:

silentParts​

具有以下属性的对象数组:

🌐 An array of objects with the following properties:

  • startInSeconds:静音部分的开始时间,以秒为单位。
  • endInSeconds:静音部分的结束时间,以秒为单位。

audibleParts​

silentParts 数组的逆。
一个包含以下属性的对象数组:

🌐 The inverse of the silentParts array.
An array of objects with the following properties:

  • startInSeconds:可听部分的开始时间,以秒为单位。
  • endInSeconds:可听部分的结束时间,以秒为单位。

durationInSeconds​

媒体的时间长度,以秒为单位。

🌐 The time length of the media in seconds.

兼容性​

🌐 Compatibility

BrowsersServersEnvironments
Chrome
Firefox
Safari
Node.js
Bun
Serverless Functions

另请参阅​

🌐 See also