How to Use FFmpeg -f Parameter for Raw Audio

This article explains how to use the -f parameter in FFmpeg to force and specify raw audio formats during media conversion. You will learn the correct command-line syntax, how to define essential audio parameters for headerless files, and see practical examples of converting to and from raw PCM data.

Why the -f Parameter is Necessary for Raw Audio

By default, FFmpeg detects the format of an input file by reading its container header (such as MP3, WAV, or AAC). However, raw audio formats—like raw PCM—are headerless. They contain nothing but raw sample bytes, meaning FFmpeg cannot automatically detect the sample rate, channel count, or sample format.

The -f (format) parameter forces FFmpeg to use a specific demuxer (for input) or muxer (for output) to interpret or write this raw byte stream.

Specifying Raw Audio Input

When reading a raw audio file, you must place the -f parameter before the input file (-i). Because raw audio has no header, you must also manually specify the sample rate (-ar) and the number of channels (-ac).

Example: Converting Raw PCM to WAV

To convert a raw, signed 16-bit little-endian PCM file to a standard WAV file, use the following command:

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

In this command: * -f s16le: Forces FFmpeg to interpret the input as Signed 16-bit Little Endian raw PCM. * -ar 44100: Sets the audio sampling rate to 44.1 kHz. * -ac 2: Sets the channel count to 2 (stereo). * -i input.raw: Specifies the input file.

Specifying Raw Audio Output

To output raw audio from a standard audio file, place the -f parameter after the input file, just before the output filename.

Example: Extracting MP3 to Raw Float 32-bit PCM

To extract the audio from an MP3 and write it as a raw, 32-bit floating-point little-endian stream:

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

In this case, FFmpeg transcodes the MP3 data and writes the raw samples directly to output.raw without adding any container headers.

Common Raw Audio Format Identifiers

Below are the most common format identifiers used with the -f parameter in FFmpeg:

Format Identifier Description
s16le Signed 16-bit Little Endian PCM
s16be Signed 16-bit Big Endian PCM
u8 Unsigned 8-bit PCM
s32le Signed 32-bit Little Endian PCM
f32le 32-bit Floating-Point Little Endian PCM
alaw A-law logarithmic PCM (commonly used in telephony)
mulaw Mu-law logarithmic PCM (commonly used in telephony)

To see a complete list of all formats supported by your specific FFmpeg installation, run:

ffmpeg -formats