How to display and capture webcam stream at the same time?

1

This command works perfectly for saving a webcam stream to a file:

ffmpeg -f alsa -i default -itsoffset 00:00:00 -f video4linux2 -s 1280x720 -r 25 -i /dev/video0  out.avi

How would I simultaneously display this captured stream on my computer screen?

12hys

Posted 2011-10-05T19:38:08.563

Reputation: 265

Answers

1

Use the tee muxer:

ffmpeg -f v4l2 -i /dev/video0 -map 0 -c:v libx264 -f tee "output.mp4|[f=nut]pipe:" | ffplay pipe:

llogan

Posted 2011-10-05T19:38:08.563

Reputation: 31 929

0

Just pipe it with ffplay which comes bundled with the ffmpeg package.

As llogan mentioned, use the tee muxer/demuxer (aka) container!

# Redirect the 'ffmpeg' ouput to 'ffplay' input
ffmpeg -f alsa -i default -itsoffset 00:00:00 -f video4linux2 -s 1280x720 -r 25 -i /dev/video0 -f tee "out.avi|[f=nut]-" | ffplay -

Quadcubic

Posted 2011-10-05T19:38:08.563

Reputation: 175

This won't capture the stream at the same time as requested by the question. – llogan – 2019-01-07T19:37:27.370

I just posted that what I know! What to Improve ? – Quadcubic – 2019-01-08T05:03:09.637

I added an answer that uses the tee muxer. – llogan – 2019-01-08T19:11:53.180

What special about it ? – Quadcubic – 2019-01-09T15:44:58.820

It uses one encoding to create multiple outputs (one for capture and one piped for display in this case). It is more efficient than encoding two separate outputs. – llogan – 2019-01-09T17:49:34.657

I think I could add as much pipes as I want ? – Quadcubic – 2019-01-13T03:24:22.607

Perhaps with named pipes (mkfifo command). – llogan – 2019-01-14T18:16:45.457