Linux – pipe webcam video stream data for processing


I found that in linux you can use video4linux2 and ffmpeg to read the data from /dev/video0 and grab the video from webcam. ffmpeg output the data to a video file, which has a limited length. My question is:

Can I pipe the the video stream both to remote viewer and to a local program so that I can keep processing the stream data in real time?


Best Answer

This is possible with the tee muxer. Modified example from the documentation:

ffmpeg -f v4l2 -i /dev/video0 -c:v libx264 -c:a mp2 -f tee -map 0:v -map 0:a \

Note that the streams need to be explicitly mapped, so that is why -map is required.

Also see: