🎥 Make videos programmatically with React
normalizing audio levels
Jonny Burger7d94beed816c
diff --git a/packages/docs/docs/recorder/editing/captions.mdx b/packages/docs/docs/recorder/editing/captions.mdxindex 05d8304e4f..11f9282eb4 100644--- a/packages/docs/docs/recorder/editing/captions.mdx+++ b/packages/docs/docs/recorder/editing/captions.mdx@@ -43,4 +43,4 @@ const autocorrectWord = (word: Word): Word => {## Highlight WordsTo highlight specific words, click on the desired word within the captions. In the opening editor, choose the `monospace` option to apply a monospaced font and default blue color to the selected word.-If you wish to change the highlighting color, modify the `WORD_HIGHLIGHT_COLOR` constant in the `colors.ts` file.+If you wish to change the highlighting color, modify the `WORD_HIGHLIGHT_COLOR` constant in the `config/themes.ts` file.diff --git a/packages/docs/docs/recorder/editing/normalizing-audio.mdx b/packages/docs/docs/recorder/editing/normalizing-audio.mdxnew file mode 100644index 0000000000..87bda28b40--- /dev/null+++ b/packages/docs/docs/recorder/editing/normalizing-audio.mdx@@ -0,0 +1,81 @@+---+image: /generated/articles-docs-recorder-editing-normalizing-audio.png+title: Normalizing audio levels+crumb: Recorder+---++Ideally, you use the audio loudness meter in the Recording interface to ensure that the audio levels are consistent across recordings.++If you need to do equalize the audio levels after the fact, you can use the following script:++:::note+This is a destructive action - your recordings will be overwritten.+Commit your changes before you run this.+:::++```tsx title="normalize.ts"+import { $ } from "bun";+import { renameSync } from "fs";+import { WEBCAM_PREFIX } from "./config/cameras";++type FfmpegVolumeOutput = {+ input_i: string;+ input_tp: string;+ input_lra: string;+ input_thresh: string;+ output_i: string;+ output_tp: string;+ output_lra: string;+ output_thresh: string;+ normalization_type: string;+ target_offset: string;+};++// Set your composition ID here+const id = "euro";++const files = await $`ls public/${id}`.quiet();+const webcamFiles = files.stdout+ .toString("utf8")+ .split("\n")+ .filter((f) => f.startsWith(WEBCAM_PREFIX));++const decibelValues: number[] = [];++for (const file of webcamFiles) {+ const path = `public/${id}/${file}`;+ const cmd =+ await $`ffmpeg -hide_banner -i ${path} -af loudnorm=I=-23:LRA=7:print_format=json -f null -`.quiet();+ const output = cmd.stderr.toString("utf8");+ const lines = output.split("\n");+ const indexOfLineBeforeStart = lines.findIndex((line) =>+ line.includes("[Parsed_loudnorm_0 @"),+ );+ const remaining = lines.slice(indexOfLineBeforeStart + 1);+ const indexOfOut = remaining.findIndex((i) => i.startsWith("[out#0"));+ const actual = indexOfOut === -1 ? remaining : remaining.slice(0, indexOfOut);+ const json = JSON.parse(actual.join("\n")) as FfmpegVolumeOutput;+ console.log(path, `${json.input_i}dB`);+ decibelValues.push(parseFloat(json.input_i));+}++const average = decibelValues.reduce((a, b) => a + b, 0) / decibelValues.length;+console.log("Average", `${average}dB`);+const toApply = Math.max(average, -20);+console.log("Applying", `${toApply}dB`);++for (const file of webcamFiles) {+ const path = `public/${id}/${file}`;+ const copiedPath = `public/${id}/normalized-${file}`;+ await $`ffmpeg -hide_banner -i ${path} -af loudnorm=I=${toApply}:LRA=7:TP=-2.0 -c:v copy ${copiedPath} -y`;+ renameSync(copiedPath, path);+}+```++This will calculate the average loudness of all recordings and edit each file so it has the same loudness as the average.++Execute it using:++```shell+bun normalize.ts+```diff --git a/packages/docs/docs/recorder/exporting-subtitles.mdx b/packages/docs/docs/recorder/exporting-subtitles.mdxnew file mode 100644index 0000000000..ce87662340--- /dev/null+++ b/packages/docs/docs/recorder/exporting-subtitles.mdx@@ -0,0 +1,33 @@+---+image: /generated/articles-docs-recorder-exporting-subtitles.png+title: Exporting subtitles+sidebar_label: Subtitles+crumb: Recorder+---++## Non-landscape layout++If you export a video in the `square` layout, then the subtitles will be burned into the video.++The idea behind this is that the square videos are posted on platforms like x.com and LinkedIn, where the video appears in a feed, muted by default.+It is important that the subtitles are always visible and have a large font size.++## Landscape layout++If you export a video in the `landscape` layout, then the subtitles will be by default exported as a `.srt` file, located in `out/[composition-id]/captions.srt`.+This is caused by the use of the [`<Artifact>`](/docs/artifact) API in [`remotion/captions/srt/EmitSrtFile.tsx`](https://github.com/remotion-dev/recorder/blob/main/remotion/captions/srt/EmitSrtFile.tsx).++When posting to YouTube, you should upload the SRT file alongside your video, so that viewers can use the native YouTube feature to toggle the subtitles and adjust the font size.++## Burn subtitles++If you want to burn the subtitles into the video in landscape layout, edit the [`remotion/captions/srt/SrtPreviewAndEditor/SrtPreviewAndEditor.tsx`](https://github.com/remotion-dev/recorder/blob/main/remotion/captions/srt/SrtPreviewAndEditor/SrtPreviewAndEditor.tsx) file and delete the following lines:++```diff title="remotion/captions/srt/SrtPreviewAndEditor/SrtPreviewAndEditor.tsx"+- // During rendering, you will get the actual .srt file instead of the preview.+- if (getRemotionEnvironment().isRendering) {+- return null;+- }+```++Now your video will include the subtitles as an overlay on top of the video.diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex 7cc04f1f7b..0adae3f160 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -969,10 +969,6 @@ module.exports = {{type: "category",label: "Record",- link: {- type: "doc",- id: "recorder/record/index",- },items: ["recorder/record/index","recorder/record/manually",@@ -997,10 +993,19 @@ module.exports = {"recorder/editing/music","recorder/editing/b-roll","recorder/editing/cutting-clips",+ "recorder/editing/normalizing-audio",+ ],+ },+ {+ type: "category",+ label: "Exporting",+ collapsed: false,+ items: [+ "recorder/exporting",+ "recorder/lambda-rendering",+ "recorder/exporting-subtitles",],},- "recorder/exporting",- "recorder/lambda-rendering","recorder/source-control","recorder/external-recordings","recorder/upgrading",diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 31145ba863..1c20e0b4d1 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -2381,6 +2381,13 @@ export const articles = [compId: "articles-docs-recorder-editing-music",crumb: "Recorder",},+ {+ id: "recorder/editing/normalizing-audio",+ title: "Normalizing audio levels",+ relativePath: "docs/recorder/editing/normalizing-audio.mdx",+ compId: "articles-docs-recorder-editing-normalizing-audio",+ crumb: "Recorder",+ },{id: "recorder/editing/scenes",title: "Scenes",@@ -2402,6 +2409,13 @@ export const articles = [compId: "articles-docs-recorder-editing-transitions",crumb: "Recorder",},+ {+ id: "recorder/exporting-subtitles",+ title: "Exporting subtitles",+ relativePath: "docs/recorder/exporting-subtitles.mdx",+ compId: "articles-docs-recorder-exporting-subtitles",+ crumb: "Recorder",+ },{id: "recorder/exporting",title: "Exporting a video",diff --git a/packages/docs/static/generated/articles-docs-recorder-editing-normalizing-audio.png b/packages/docs/static/generated/articles-docs-recorder-editing-normalizing-audio.pngnew file mode 100644index 0000000000..39c7b3343dBinary files /dev/null and b/packages/docs/static/generated/articles-docs-recorder-editing-normalizing-audio.png differdiff --git a/packages/docs/static/generated/articles-docs-recorder-exporting-subtitles.png b/packages/docs/static/generated/articles-docs-recorder-exporting-subtitles.pngnew file mode 100644index 0000000000..b1a1bb8304Binary files /dev/null and b/packages/docs/static/generated/articles-docs-recorder-exporting-subtitles.png differ