How to Use FFmpeg -f for Raw Audio Formats

Using FFmpeg to process raw audio requires explicitly defining the audio characteristics because raw audio files lack headers containing metadata like sample rate, channel count, and bit depth. This article explains how to use the -f (format) parameter in FFmpeg to successfully ingest, convert, and output raw PCM (Pulse Code Modulation) audio formats.

Understanding the -f Parameter for Raw Audio

The -f flag in FFmpeg forces the input or output file format. For standard audio files (like MP3 or WAV), FFmpeg automatically detects the container and codec. For raw audio (like .pcm, .raw, or .bin), there is no container structure. You must use the -f parameter to tell FFmpeg exactly how to interpret the raw binary data.

When reading raw audio, the -f parameter is typically paired with sample rate (-ar) and channel (-ac) specifiers so FFmpeg can correctly reconstruct the analog signal.

Common Raw Audio Format Specifiers

FFmpeg supports various raw audio formats under the -f flag. The most common specifiers include:

You can view a full list of supported formats by running ffmpeg -formats in your terminal.

How to Read Raw Audio Files (Input)

To convert a raw audio file to a compressed format, you must place the -f parameter and its corresponding audio properties before the input file (-i).

Example: Converting 16-bit Raw PCM to MP3

If you have a raw audio file recorded at 44,100 Hz, in stereo (2 channels), using signed 16-bit little-endian format, use the following command:

ffmpeg -f s16le -ar 44100 -ac 2 -i input.raw output.mp3

In this command: * -f s16le: Forces FFmpeg to read the input as signed 16-bit little-endian PCM. * -ar 44100: Sets the audio sample rate to 44.1 kHz. * -ac 2: Sets the channel count to 2 (stereo). * -i input.raw: Specifies the raw input file.

How to Write Raw Audio Files (Output)

To export an existing audio file into a raw PCM format, place the -f parameter after the input file, just before the output destination.

Example: Converting WAV to 32-bit Float Raw PCM

To convert a standard WAV file into raw 32-bit floating-point audio:

ffmpeg -i input.wav -f f32le output.raw

In this case, FFmpeg extracts the audio data from the WAV file, strips away the header, and writes the raw 32-bit little-endian float data directly to output.raw.