🎥 Make videos programmatically with React
docs
Jonny Burgerdd3ee1dab705
diff --git a/packages/docs/docs/renderer/get-silent-parts.md b/packages/docs/docs/renderer/get-silent-parts.mdnew file mode 100644index 0000000000..6b25f25d0c--- /dev/null+++ b/packages/docs/docs/renderer/get-silent-parts.md@@ -0,0 +1,78 @@+---+image: /generated/articles-docs-renderer-get-silent-parts.png+id: get-silent-parts+title: getSilentParts()+crumb: "@remotion/renderer"+---++# getSilentParts()<AvailableFrom v="4.0.18" />++:::note+This function is meant to be used **in Node.js applications**. It cannot run in the browser.+:::++Gets the silent parts of a video or audio in Node.js. Useful for cutting out silence from a video.++## Example++```ts twoslash title="silent-parts.mjs"+// @module: ESNext+// @target: ESNext+import { getSilentParts } from "@remotion/renderer";++const { silentParts, durationInSeconds } = await getSilentParts({+ src: "./bunny.mp4",+ noiseThresholdInDecibels: -20,+ minDuration: 1,+});++console.log(silentParts); // [{startInSeconds: 0, endInSeconds: 1.5}]+```++## Arguments++An object which takes the following properties:++### `source`++_string_++A local video or audio file path.++### `noiseThresholdInDecibels`++_number, optional_++The threshold in decibels. If the audio is below this threshold, it is considered silent. The default is `-20`. Must be less than `30`.++### `minDuration`++_number, optional_++The minimum duration of a silent part in seconds. The default is `1`.++### `logLevel`++_`"info" | "warn" | "error" | "verbose"`, optional_++The log level. The default is `"info"`.++## Return Value++The return value is an object with the following properties:++### `silentParts`++An array of objects with the following properties:++- `startInSeconds`: The start time of the silent part in seconds.+- `endInSeconds`: The end time of the silent part in seconds.++### `durationInSeconds`++The time length of the media in seconds.++## See also++- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/renderer/src/get-silent-parts.ts)+- [getVideoMetadata()](/docs/renderer/get-video-metadata)diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex 32c2cb1a87..d5690016a8 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -119,6 +119,7 @@ module.exports = {"renderer/ensure-ffprobe","renderer/get-can-extract-frames-fast","renderer/get-video-metadata",+ "renderer/get-silent-parts",],},{diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 725683dfd0..20e7adb0e3 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -1347,7 +1347,7 @@ export const articles = [},{id: "gl-options",- title: "GL Options",+ title: "--gl flag",relativePath: "docs/open-gl.md",compId: "articles-docs-open-gl",crumb: "Flags",@@ -1737,6 +1737,13 @@ export const articles = [compId: "articles-docs-renderer-get-compositions",crumb: "@remotion/renderer",},+ {+ id: "get-silent-parts",+ title: "getSilentParts()",+ relativePath: "docs/renderer/get-silent-parts.md",+ compId: "articles-docs-renderer-get-silent-parts",+ crumb: "@remotion/renderer",+ },{id: "get-video-metadata",title: "getVideoMetadata()",diff --git a/packages/docs/static/generated/articles-docs-renderer-get-silent-parts.png b/packages/docs/static/generated/articles-docs-renderer-get-silent-parts.pngnew file mode 100644index 0000000000..23b351b599Binary files /dev/null and b/packages/docs/static/generated/articles-docs-renderer-get-silent-parts.png differdiff --git a/packages/renderer/rust/commands/mod.rs b/packages/renderer/rust/commands/mod.rsindex 9e90e4eb92..1c8830b1e2 100644--- a/packages/renderer/rust/commands/mod.rs+++ b/packages/renderer/rust/commands/mod.rs@@ -53,7 +53,7 @@ pub fn execute_command(opts: CliInputCommandPayload) -> Result<Vec<u8>, ErrorWitCliInputCommandPayload::GetSilences(_command) => {let filter = format!("silencedetect=n={}dB:d={}",- _command.noiseThresholdInDecibel, _command.minDuration+ _command.noiseThresholdInDecibels, _command.minDuration);let res = get_silent_parts::get_silent_parts(_command.src, filter.to_string())?;let str = serde_json::to_string(&res)?;diff --git a/packages/renderer/rust/payloads.rs b/packages/renderer/rust/payloads.rsindex b5aee8b8e1..820cdc6e74 100644--- a/packages/renderer/rust/payloads.rs+++ b/packages/renderer/rust/payloads.rs@@ -66,7 +66,7 @@ pub mod payloads {#[allow(non_snake_case)]pub struct GetSilences {pub src: String,- pub noiseThresholdInDecibel: f64,+ pub noiseThresholdInDecibels: f64,pub minDuration: f64,}diff --git a/packages/renderer/src/compositor/payloads.ts b/packages/renderer/src/compositor/payloads.tsindex ebe8d84f27..3a46d61d0d 100644--- a/packages/renderer/src/compositor/payloads.ts+++ b/packages/renderer/src/compositor/payloads.ts@@ -52,7 +52,7 @@ export type SilentParts = SilentPart[];export type GetSilentPartsResponse = {silentParts: SilentParts;- duration: number;+ durationInSeconds: number;};export type CompositorCommand = {@@ -71,7 +71,7 @@ export type CompositorCommand = {};GetSilences: {src: string;- noiseThresholdInDecibel: number;+ noiseThresholdInDecibels: number;minDuration: number;};Echo: {diff --git a/packages/renderer/src/get-silent-parts.ts b/packages/renderer/src/get-silent-parts.tsindex bded9988c4..4bd8e29026 100644--- a/packages/renderer/src/get-silent-parts.ts+++ b/packages/renderer/src/get-silent-parts.ts@@ -7,14 +7,14 @@ import type {LogLevel} from './log-level';export const getSilentParts = async ({src,- noiseThresholdInDecibel: passednoiseThresholdInDecibel,+ noiseThresholdInDecibels: passednoiseThresholdInDecibels,minDuration: passedMinDuration,logLevel,}: {src: string;minDuration?: number;logLevel?: LogLevel;- noiseThresholdInDecibel?: number;+ noiseThresholdInDecibels?: number;}): Promise<GetSilentPartsResponse> => {const compositor = startLongRunningCompositor(getIdealMaximumFrameCacheItems(),@@ -34,24 +34,24 @@ export const getSilentParts = async ({);}- const noiseThresholdInDecibel = passednoiseThresholdInDecibel ?? -20;+ const noiseThresholdInDecibels = passednoiseThresholdInDecibels ?? -20;- if (typeof noiseThresholdInDecibel !== 'number') {+ if (typeof noiseThresholdInDecibels !== 'number') {throw new Error(- `noiseThresholdInDecibel must be a number, but was ${noiseThresholdInDecibel}`+ `noiseThresholdInDecibels must be a number, but was ${noiseThresholdInDecibels}`);}- if (noiseThresholdInDecibel >= 30) {+ if (noiseThresholdInDecibels >= 30) {throw new Error(- `noiseThresholdInDecibel must be less than 0, but was ${noiseThresholdInDecibel}`+ `noiseThresholdInDecibels must be less than 30, but was ${noiseThresholdInDecibels}`);}const res = await compositor.executeCommand('GetSilences', {src,minDuration,- noiseThresholdInDecibel,+ noiseThresholdInDecibels,});const response = JSON.parse(res.toString('utf-8')) as GetSilentPartsResponse;diff --git a/packages/renderer/src/test/get-silent-parts.test.ts b/packages/renderer/src/test/get-silent-parts.test.tsindex f770455511..25238873c3 100644--- a/packages/renderer/src/test/get-silent-parts.test.ts+++ b/packages/renderer/src/test/get-silent-parts.test.ts@@ -14,15 +14,16 @@ test('Should be able to get the silences from a video', async () => {});test('Sensitive settings', async () => {- const {silentParts} = await getSilentParts({+ const {silentParts, durationInSeconds} = await getSilentParts({src: exampleVideos.webcam,- noiseThresholdInDecibel: 0,+ noiseThresholdInDecibels: 0,minDuration: 0.1,logLevel: 'info',});expect(silentParts.length).toEqual(1);expect(silentParts[0].startInSeconds).toBe(0);expect(silentParts[0].endInSeconds).toBe(2.789);+ expect(durationInSeconds).toBe(durationInSeconds);});test('Long duration', async () => {