Pipe input in to ffmpeg stdin

51,059

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

Share:
51,059

Related videos on Youtube

AbstractDissonance
Author by

AbstractDissonance

Updated on March 10, 2022

Comments

  • AbstractDissonance
    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.,

    1. Manually load mp3 file
    2. Pipe it in to the ffmpeg spawned process
    3. Get raw output

    (it should work with ffprobe and ffplay also)

  • MrBar
    MrBar over 5 years
    @AbstractDissonance updated the answer to explain better a raw format
  • Sridhar Sarnobat
    Sridhar Sarnobat almost 4 years
    Can 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
    MrBar almost 4 years
    yes 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
    Sridhar Sarnobat almost 4 years
    Thank 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
    Oliver Dixon about 3 years
    Unable to find a suitable output format for 'cat'
  • MrBar
    MrBar about 3 years
    What is the exact command you are using and on which platform?
  • rakslice
    rakslice over 1 year
    On Windows, -i pipe:0 seems to work for input piped in