Piping video device over SSH or tcptunnel?

You can use netcat.

cat /dev/video0 | nc -l 1234

This will open a server on one host listening on port 1234 and sending uncompressed and unencrypted data from /dev/video0 to any client that connects. You can receive the data on other host by invoking:

nc videohost 1234 | mplayer tv://device=/dev/stdin

where videohost is the host sending data from /dev/video0.


The netcat solution didn't work for me. It either shows a pipe error, or cat reporting Invalid input.

This is the only solution that worked for me:

ssh user@host "ffmpeg  -r 14 -s 640x480 -f video4linux2 -i /dev/video0 -f matroska -" | mplayer - -idle

This has the benefit of it being encoded, so you save bandwidth as a bonus.


Combine with tee and you can watch and record at the same time:

ssh user@host "ffmpeg  -r 14 -s 640x480 -f video4linux2 -i /dev/video0 -f matroska -" | tee $(date +%Y-%m-%d_%H-%M-%S)_recording.mkv | mplayer - -idle

This will open mplayer for live streaming and save it to a file containing the current datetime at the same time (example filename: 2018-11-22_01-22-10_recording.mkv).


Replace -f matroska with -f avi to use the more compressed avi format. This will save a lot of CPU resources on the source and a lot of bandwidth for a more lag free experience.


I would seriously advise you against this. I recently tried streaming avi videos over an ssh:// file access and its painful. You have to remember that the video is being encrypted and then decrypted during this process.

If your computer cannot handle compressing the stream then it certainly will not be able to handle encrypting it.

Really you want to just have a tcp tunnel the raw data:

http://www.vakuumverpackt.de/tcptunnel/