Pipe Raw PCM Audio to FFmpeg and Transcode to FLAC

This guide explains how to stream raw PCM audio data directly into FFmpeg using standard input (stdin) and transcode it into the lossless FLAC format. Because raw PCM data lacks header information, you must explicitly define the input audio properties—such as sample rate, bit depth, and channel count—for FFmpeg to interpret and convert the stream correctly.

To pipe raw PCM data into FFmpeg, you send the byte stream to stdin and instruct FFmpeg to read from the pipe using -i pipe:0 (or simply -i -). Since raw PCM does not contain metadata headers, you must place the input format specifiers before the input flag in the command.

Here is the template for the command:

[your_pcm_generator] | ffmpeg -f s16le -ar 44100 -ac 2 -i pipe:0 output.flac

Command Breakdown

Real-World Example using cat

If you have a raw PCM file named audio.raw containing 16-bit stereo PCM at 48kHz, you can pipe it and transcode it like this:

cat audio.raw | ffmpeg -f s16le -ar 48000 -ac 2 -i - output.flac

This method allows you to seamlessly integrate FFmpeg into audio processing pipelines, enabling real-time compression from programming languages, scripts, or other command-line audio tools.