Can libmp3lame read audio from standard input

This article explains whether the libmp3lame library and the associated LAME command-line utility support reading uncompressed audio data directly from standard input (stdin). It clarifies the technical distinction between the C library API and the command-line executable, while providing practical examples of how to pipe raw PCM audio into the encoder.

The Library (libmp3lame) vs. The Command-Line Tool (LAME)

To answer the question accurately, we must distinguish between the libmp3lame software library and the lame command-line interface (CLI).

How to Pipe Uncompressed Audio to the LAME CLI

When using the LAME command-line tool, you can instruct it to read from standard input by using a hyphen (-) in place of the input file path.

Because standard input is a continuous stream, it often lacks the header metadata found in container formats like WAV or AIFF. Therefore, when piping raw, headerless PCM audio, you must explicitly define the audio properties using command-line flags.

Here is the standard command structure for piping raw PCM audio into LAME:

cat input.raw | lame -r -s 44.1 --bitwidth 16 -m s - output.mp3

Explanation of the Parameters: