openmind ☃   April 07, 2008  ☃  Streaming Movies with netcat(1) and MPlayer(1)  (, , )

netcat_pipe I bought a hi-def projector a few months ago, and it’s in another room, away from my Linux server. I can connect my laptop to the projector, but I don’t want to actually store any of the movies on my laptop. Recently I figured out how to use the laptop as a streaming client using netcat to pipe data to an mplayer instance on the client end. The beauty of this is that it doesn’t use up any space on my laptop, as the data never gets written to disk.

First, on the server where the movie is located:

cat /path/to/yourmovie.avi | nc -v -l -p 6969

Here I am using port 6969 but in theory you could use any non-privileged port.

Second, on the client end, do:

nc $server_ip 6969 | mplayer -ni -

You may have to adjust the mplayer cache, which is in kilobytes. YMMV

e.g.,

cache = 524288 # 500MB
# Prefill 50% of the cache before starting playback.
cache-min = 50.0

The correct mplayer file to edit is distribution-specific, but on ArchLinux it was located in /etc/mplayer/mplayer.conf

In the coming weeks I will hack up some bash or ruby scripts to
automate this.

Edit: Mon Feb 9 07:32:43 CST 2009:
Here’s a client alias:

% alias streamproj
streamproj='nc 192.168.1.101 6969 | mplayer -vf scale=1280:800 -'

And here’s a server alias:

% alias stream
stream='nc -l -vvv -p 6969 <'

It works best if you start the server first.

blog comments powered by Disqus