Linux – pipe webcam video stream data for processing

ffmpeglinuxstreamingvideowebcam

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?

Thanks.

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 \
"archive-20121107.mkv|[f=mpegts]udp://10.0.1.255:1234/"

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

Also see: