Capítulo 833 de 988

Chapter 833: Normalizing audio levels

Core Idea

Ideally, you use the audio loudness meter in the Recording interface to ensure that the audio levels are consistent across recordings.

Key Concepts

  • Normalizing audio levels: Ideally, you use the audio loudness meter in the Recording interface to ensure that the audio levels are consistent across recordings..

Code Examples

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 toA
// ...(truncated)
  • What it demonstrates: Usage pattern for Normalizing audio levels from the official docs.

Key Takeaways

  1. Understand normalizing audio levels when working with Normalizing audio levels.

Connects To

  • Captions: related page in the Recorder (@remotion/recorder) section.
  • Create: related page in the Recorder (@remotion/recorder) section.
  • Demo: related page in the Recorder (@remotion/recorder) section.