Pipe input in to ffmpeg stdin
Solution 1
ffmpeg has a special pipe flag that instructs the program to consume stdin. note that almost always the input format needs to be defined explicitly.
example (output is in PCM signed 16-bit little-endian format):
cat file.mp3 | ffmpeg -f mp3 -i pipe: -c:a pcm_s16le -f s16le pipe:
pipe docs are here
supported audio types are here
Solution 2
I don't have enough reputation to add a comment, so...
MrBar's example
ffmpeg -i file.mp3 -c:a pcm_s16le -f s16le pipe: | ffmpeg -f mp3 -i pipe: -c:a pcm_s16le -f s16le encoded.mp3
should read,
ffmpeg -i file.mp3 -c:a pcm_s16le -f s16le pipe: | ffmpeg -f s16le -i pipe: -f mp3 encoded.mp3
Solution 3
-
is the same as pipe:
I couldn't find where it's documented, and I don't have the patience to check the source, but -
appears to be the exact same as pipe:
according to my tests with ffmpeg 4.2.4, where pipe:
does what you usually expect from -
in other Linux utilities as mentioned in the documentation of the pipe protocol:
If number is not specified, by default the stdout file descriptor will be used for writing, stdin for reading.
So for example you could rewrite the command from https://stackoverflow.com/a/45902691/895245
ffmpeg -f mp3 -i pipe: -c:a pcm_s16le -f s16le pipe: < file.mp3
a bit more simply as:
ffmpeg -f mp3 -i - -c:a pcm_s16le -f s16le - < file.mp3
Related: What does "dash" - mean as ffmpeg output filename
Related videos on Youtube

AbstractDissonance
Updated on March 10, 2022Comments
-
AbstractDissonance about 1 year
I am trying to use ffmpeg to decode audio data. While it works to load from a file, I would like to avoid using files because to do so, means I would have to use a temporary. Instead, I'd like to pipe in the data(which I've previously loaded) using stdin.
Is this possible?
e.g.,
- Manually load mp3 file
- Pipe it in to the ffmpeg spawned process
- Get raw output
(it should work with ffprobe and ffplay also)
-
MrBar over 5 years@AbstractDissonance updated the answer to explain better a raw format
-
Sridhar Sarnobat almost 4 yearsCan the output of an ffmpeg command be piped as input to a subsequent ffmpeg command? I'm having trouble figuring out if it can be.
-
MrBar almost 4 yearsyes you can!
ffmpeg -i file.mp3 -c:a pcm_s16le -f s16le pipe: | ffmpeg -f mp3 -i pipe: -c:a pcm_s16le -f s16le encoded.mp3
-
Sridhar Sarnobat almost 4 yearsThank you very much. I'm surprised almost nobody mentions this. Unix pipelines are the best thing since since sliced bread (though I don't know what's so great about sliced bread)
-
Oliver Dixon about 3 years
Unable to find a suitable output format for 'cat'
-
MrBar about 3 yearsWhat is the exact command you are using and on which platform?
-
rakslice over 1 yearOn Windows,
-i pipe:0
seems to work for input piped in