49

How can I pipe the output of ffmpeg to ffplay?

At the moment I use a workaround in bash :

mkfifo spam
(ffplay spam 2> /dev/null &) ; capture /dev/stdout | ffmpeg -i - spam

4 Answers 4

27

I do not know if it is ffmpeg that cannot output its data to stdout, or ffplay that cannot take its input from stdin.

If it is ffmpeg that cannot output its data to stdout:

capture /dev/stdout | ffmpeg -i - >(ffplay 2> /dev/null)

(You migth need to add a - argument to ffplay so it takes its input from stdin.)

If it is ffplay that cannot take its input from stdin:

ffplay <(capture /dev/stdout | ffmpeg -i -) 2> /dev/null

For more informations about the <(command) and >(command) construct, see the Process Substitution section of the bash manual.

3
  • 6
    for me this didnt work without explicitly specifying output format with "-f". as specified on ffmpeg.org/ffmpeg.html: "format is normally auto detected for input files and guessed from the file extension for output files". in given answer ffmpeg wont be able to guess output format. so i think ffmpeg should have "-f fmt" added to it. Commented Jun 8, 2015 at 11:50
  • 1
    ffmpeg 2.8.6 does support stdin input as mentioned in other answers. You can check for that support with: stackoverflow.com/questions/12999674/… Commented Aug 17, 2016 at 7:30
  • Can you elaborate what capture is? Ideally a link to a repo or the official website. Commented Dec 16, 2023 at 10:04
54
ffmpeg -i input.avi <options> -f matroska - | ffplay -

will work; you need to set a container format for the output. This is normally set with ffmpeg looking at the extension you give the output, but here you have to set it manually with -f. I recommend matroska (MKV) because it can contain almost any video, so whatever you're transcoding it to should work perfectly well.

Note that if you are using Ubuntu 12.04, ffmpeg has been replaced by the libav fork, and you should use avconv and avplay instead; the syntax is otherwise identical. There is a sort-of ffmpeg there, but it's crippled by design.

2
  • 5
    Win10: Error occur as pipe:: Invalid data found when processing inputK in Power Shell, but works well in command prompt Commented Jun 25, 2019 at 16:39
  • 1
    The powershell invalid data thing is because of powershell parsing the binary data flowing through a | pipe as text, so ffplay in this case gets something it's not expecting. The solution is to run it in a cmd.exe to do the piping stuff, or powershell module Use-RawPipeline, while waiting for this to be implemented in powershell: github.com/PowerShell/PowerShell/issues/1908 Commented Jan 18, 2022 at 22:53
20

ffmpeg supports piping operations. See that section of the documentation here.

I don't know how ffplay works, but to pipe the output of ffmpeg to standard output, you can add the pipe command to the end of the ffmpeg command. Example:

ffmpeg -i input.flv pipe:1 | ffplay -i -
5
  • 1
    thanks, i somehow missed that section of the man pages.. however i could not get this construct to work, the output filename needs to be removed from ffmpeg and input pipe added to ffplay args. i will edit your post accordingly.. Commented Aug 18, 2011 at 3:09
  • Thanks. As I said, I've never used ffplay before, but I know ffmpeg. Commented Aug 18, 2011 at 13:17
  • In my man ffplay, I cannot see ffplay supporting the -i switch - is it maybe ffmpeg only? Commented May 29, 2013 at 20:34
  • 2
    pipe:1 vs -? - works on ffmpeg 2.8.6. Commented Aug 17, 2016 at 7:33
  • your correct that ffplay does not support -i, though the above might work/might have worked in the past. This should also work: ffmpeg -i input.flv <options> -f matroska - | ffplay - Commented Apr 16, 2022 at 19:26
12

looks like normal pipes work (at least in windows):

ffmpeg -i sintel.mpg -pix_fmt yuv420p -f rawvideo - | ffplay -f rawvideo -pix_fmt yuv420p -s 720x480 -

haven't tried it with more complicated input/output though...

Here's another variation that seems to have a slightly faster startup:

ffmpeg -f dshow -i video=screen-capture-recorder -pix_fmt yuv420p -f mpegts - | ffplay -analyzeduration 10 -f mpegts -
4
  • 10
    I was getting Unable to find a suitable output format for 'pipe:' - I needed to specify a codec with -f. Commented Jul 31, 2016 at 0:40
  • Works, but very low image quality Commented Jun 25, 2019 at 16:44
  • If it's low image quality then make sure that what you're initially capturing is high image quality (save it to a file first, etc.) it "should" be normal quality... Commented Jun 26, 2019 at 4:40
  • 1
    These days, its -video_size and -pixel_format instead of -s and -pix_fmt (ffmpeg 8) Commented Sep 18 at 15:47

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.