How to Output LAME MP3 Encoded Audio to Stdout

This article explains how to configure the LAME MP3 encoder command-line tool (which utilizes the libmp3lame library) to direct its encoded audio output directly to standard output (stdout) instead of a physical file. By mastering this syntax, you can easily pipe MP3 data into other command-line utilities, media players, or streaming servers.

The Standard Output Syntax

To instruct the LAME encoder to write its output to stdout, you use a single hyphen (-) in place of the output file name.

The basic syntax is:

lame [options] <input_file> -

For example, to encode a WAV file named input.wav to MP3 and output the binary stream directly to your terminal’s stdout:

lame input.wav -

Reading from Stdin and Writing to Stdout

If you are building a data pipeline where LAME receives raw audio data from another program via standard input (stdin) and outputs the encoded MP3 to standard output (stdout), use a hyphen for both the input and output arguments:

cat input.wav | lame - -

In this command, the first hyphen tells LAME to read from stdin, and the second hyphen tells LAME to write to stdout.

Important: Suppress Console Information

When redirecting binary audio data to stdout, LAME’s real-time encoding statistics and progress reports can interfere with the output stream or clutter your terminal screen.

To prevent this, you should use the -S or --silent option. This disables the progress report and error messages, ensuring only the pure MP3 stream is written to stdout:

lame --silent input.wav -

Practical Example: Piping to Another Program

A common use case is piping the stdout stream from LAME directly into another tool, such as a media player like mpv or aplay:

lame --silent input.wav - | mpv -