How to Pipe Raw Audio into FFmpeg on Windows
Piping raw audio from an external encoder or application into FFmpeg
on Windows allows you to process, transcode, or stream audio in real
time without generating temporary files. By using the standard
command-line pipe operator (|) alongside FFmpeg’s stdin
input reader (-i -), you can seamlessly bridge the output
of your audio generator or encoder directly into FFmpeg.
The Basic Command Structure
To pipe raw audio, you must output the raw audio data to standard
output (stdout) from your encoder and configure FFmpeg to
read from standard input (stdin). Because raw audio (PCM)
lacks header information, you must explicitly define the audio
parameters (sample format, sample rate, and channels) in the FFmpeg
command before the input flag.
The general syntax on Windows Command Prompt or PowerShell is:
external_encoder.exe --output-stdout-option | ffmpeg -f s16le -ar 48000 -ac 2 -i - output.mp3Step-by-Step Configuration
Configure the External Encoder: Ensure your external application is set to output raw PCM data directly to
stdout. This option is often designated by flags like-o -,--stdout, or-.Define the Input Format (
-f): You must tell FFmpeg the format of the incoming raw audio. Common formats include:s16le(Signed 16-bit Little Endian PCM)f32le(32-bit Floating Point Little Endian PCM)u8(Unsigned 8-bit PCM)
Set the Sample Rate (
-ar): Specify the sampling frequency in Hz to match the encoder’s output (e.g.,-ar 44100or-ar 48000).Set the Channels (
-ac): Specify the number of audio channels (e.g.,-ac 1for mono,-ac 2for stereo).Specify the Input Source (
-i -): The dash-(orpipe:0) tells FFmpeg to listen to the standard input stream instead of looking for a physical file.
Real-World Example
If you are using a command-line tool like sox to
generate a raw audio test tone and pipe it into FFmpeg to encode it as
an AAC file, the command looks like this:
sox -n -t raw -r 44100 -c 2 -b 16 - synth 10 sine 440 | ffmpeg -f s16le -ar 44100 -ac 2 -i - output.aacHandling Windows PowerShell Quirks
If you are using PowerShell instead of the classic Command Prompt
(cmd.exe), standard piping can sometimes corrupt raw binary
data due to character encoding attempts. To prevent this, force
PowerShell to handle the pipeline as raw bytes, or run the command via
cmd:
cmd /c "external_encoder.exe | ffmpeg -f s16le -ar 48000 -ac 2 -i - output.mp3"