How to Generate Pink Noise with FFmpeg

Generating pink noise with FFmpeg is a straightforward process that utilizes the tool's built-in audio source filters. This guide provides a direct, step-by-step tutorial on how to create a pink noise audio file using simple FFmpeg commands, explaining the necessary parameters to customize the duration, sample rate, and output format for your needs.

To generate pink noise, you will use the anoisesrc (audio noise source) filter inside FFmpeg. This filter allows you to specify the color of the noise, the sample rate, the amplitude, and the duration of the output file.

The Basic Command

Open your terminal or command prompt and run the following command to generate a 10-second WAV file of pink noise:

ffmpeg -f lavfi -i "anoisesrc=color=pink:sample_rate=48000:amplitude=0.5" -t 10 output.wav

Command Breakdown

  • -f lavfi: This tells FFmpeg to use the Libavfilter virtual input device, which is required for generating synthetic audio or video.
  • -i "anoisesrc=...": This defines the input filter and its parameters:
    • color=pink: Specifies that the generated noise should be pink (which decreases in density by 3 decibels per octave, making it sound deeper and softer than white noise).
    • sample_rate=48000: Sets the audio sampling rate to 48 kHz (you can change this to 44100 for CD quality).
    • amplitude=0.5: Sets the volume level of the noise on a scale from 0.0 to 1.0. Keeping it at 0.5 prevents digital clipping and distortion.
  • -t 10: Specifies the duration of the output file in seconds. In this case, it will generate 10 seconds of audio.
  • output.wav: The name and format of the final file. You can change the extension to .mp3, .ogg, or .flac depending on your requirements.

Generating Pink Noise in MP3 Format

If you need a compressed, widely compatible format like MP3 and want a longer duration (for example, 5 minutes), use the following command:

ffmpeg -f lavfi -i "anoisesrc=color=pink:sample_rate=44100:amplitude=0.5" -t 300 -b:a 192k output.mp3

In this variation:

  • -t 300 sets the duration to 300 seconds (5 minutes).
  • -b:a 192k sets the audio bitrate to 192 kbps to ensure high-quality MP3 compression.