How can I pipe output of ffmpeg to ffplay?

23

9

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

wim

Posted 2011-08-12T07:11:03.370

Reputation: 2 523

Answers

18

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.

jfg956

Posted 2011-08-12T07:11:03.370

Reputation: 1 021

4

for me this didnt work without explicitly specifying output format with "-f". as specified on https://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.

– Pavel K. – 2015-06-08T11:50:06.547

1

ffmpeg 2.8.6 does support stdin input as mentioned in other answers. You can check for that support with: http://stackoverflow.com/questions/12999674/ffmpeg-which-file-formats-support-stdin-usage

– Ciro Santilli 新疆改造中心法轮功六四事件 – 2016-08-17T07:30:19.507

18

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.

evilsoup

Posted 2011-08-12T07:11:03.370

Reputation: 10 085

Win10: Error occur as pipe:: Invalid data found when processing inputK in Power Shell, but works well in command prompt – John – 2019-06-25T16:39:18.953

11

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 -

matzahboy

Posted 2011-08-12T07:11:03.370

Reputation: 231

1pipe:1 vs -? - works on ffmpeg 2.8.6. – Ciro Santilli 新疆改造中心法轮功六四事件 – 2016-08-17T07:33:24.960

1thanks, 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.. – wim – 2011-08-18T03:09:24.170

Thanks. As I said, I've never used ffplay before, but I know ffmpeg. – matzahboy – 2011-08-18T13:17:35.763

In my man ffplay, I cannot see ffplay supporting the -i switch - is it maybe ffmpeg only? – sdaau – 2013-05-29T20:34:30.867

9

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...

ffmpeg -f dshow -i video=screen-capture-recorder -pix_fmt yuv420p -f mpegts - | ffplay -analyzeduration 10 -f mpegts -

is slightly faster startup

rogerdpack

Posted 2011-08-12T07:11:03.370

Reputation: 1 181

5I was getting Unable to find a suitable output format for 'pipe:' - I needed to specify a codec with -f. – i336_ – 2016-07-31T00:40:13.617

Works, but very low image quality – John – 2019-06-25T16:44:16.020

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... – rogerdpack – 2019-06-26T04:40:44.233