Capítulo 728 de 988

Chapter 728: Resample audio to 16kHz

Core Idea

:::warning We are phasing out Remotion WebCodecs and are moving to Mediabunny!

Key Concepts

  • In the browser
  • On the server

Code Examples

const output = await convertMedia({
  src: 'https://example.com/input.mp4',
  container: 'wav',
  onAudioTrack: async ({track}) => {
    if (
      await canReencodeAudioTrack({
        audioCodec: 'wav',
        track,
        // Ignore this, bitrate is not used for WAV files
        bitrate: 128000,
        sampleRate: 16000,
      })
    ) {
      return {
        type: 'reencode',
        audioCodec: 'wav',
        bitrate: 128000,
        sampleRate: 16000,
      };
    }

    // If this conversion is not supported, return an error
    return {
      type: 'fail',
    };
  },
});

const blob = await output.save(); // returns a `Blob`
  • What it demonstrates: Usage pattern for Resample audio to 16kHz from the official docs.

Key Takeaways

  1. Understand in the browser when working with Resample audio to 16kHz.
  2. Understand on the server when working with Resample audio to 16kHz.

Connects To

  • Buffer Writer: related page in the WebCodecs (@remotion/webcodecs) section.
  • can Copy Audio Track: related page in the WebCodecs (@remotion/webcodecs) section.
  • can Copy Video Track: related page in the WebCodecs (@remotion/webcodecs) section.