Piping video device over SSH or tcptunnel?

3

I want to attach an analog camera to an old linux computer and directly pipe the /dev/video0 to another computer, where I can use it as a device again (so /dev/video0 should go to /dev/remote0, for example)

(Reason for doing this is that the computer does not have enough power to encode the video)

Is that possible? I've seen people can pipe the data directly from the device over ssh into mplayer, but I need to have some sort of reference point for Zoneminder.

  • Edit: As Phil Hannent said: SSH would probably also be too resource intensive for the hardware as it has to encrypt the data it sends. So is this also possible over a program like tcptunnel?

  • Edit2: On the Unix & Linux stackexchange site I found a question that uses this for piping over ssh: ssh localhost dd if=/dev/video0 | mplayer tv://device=/dev/stdin can that be done over tcptunnel?

skerit

Posted 2011-08-11T09:14:07.880

Reputation: 746

Answers

5

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.

Paweł Nadolski

Posted 2011-08-11T09:14:07.880

Reputation: 966

1"nc videohost 1234 | mplayer tv://device=/dev/stdin" output error "Playing tv://device=/dev/stdin. The filename option must be an integer: dev/stdin Struct tv, field filename parsing error: dev/stdin". I think this problem in my webcam or in my mplayer. "nc videohost 1234 | vlc - " work for me. – user3439968 – 2016-02-22T20:24:11.033

1Tried this - cat: /dev/video0: Invalid argument – Ryan – 2018-12-07T19:43:14.853

1

@Ryan, try netcat (see https://stackoverflow.com/questions/15534994/dev-video0-invalid-argument)

– Paweł Nadolski – 2018-12-08T06:56:12.617

Nice! Is it possible to pipe the data into a /dev/file first, and then separately opening it in mplayer? – skerit – 2011-08-12T11:25:17.723

I think creating device would be too complicated, but if you need something file-like you could try a fifo pipe (mknod /tmp/videofifo p) write the stream to it and pipe it's contents to mplayer using cat. Not sure how the pipe would behave if you don't read the data from it though. – Paweł Nadolski – 2011-08-12T11:42:20.740

I'll give it a try tonight. Very interested to see how it'll turn out! – skerit – 2011-08-12T11:50:06.967

2I'd also like to point out ipusb: it probably works even better than this. It lets you mount a usb device over the network. – skerit – 2011-09-07T21:51:41.550

2

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.

confetti

Posted 2011-08-11T09:14:07.880

Reputation: 1 625

2

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/

Phil Hannent

Posted 2011-08-11T09:14:07.880

Reputation: 1 080

1Right, I forgot about that. But how would you pipe device data over this? – skerit – 2011-08-11T09:31:07.453