Streaming over ssh with mplayer+mpd
From WorldWiki
Streaming over ssh with mplayer and mpd
Posted on: 2009/12/24 Tagged with: ssh, mplayer, mpd and posted in categories: technology, music, frontpage.
So while experimenting today, I figured out how to do something really cool: stream my music from mpd over ssh!
The tl;dr version: cat a fifo over ssh and then use mplayer on stdin with the 'rawaudio' demuxer.
The longer version:
MPD, which some of you may be familiar with, is my music player of choice. It does basically exactly what I want: stay out of the way, let me control from afar, and play just about everything. That being said, I've never been too happy with the streaming options it provided me, because I usually sit behind NAT and such -- so I have to do everything through ssh tunnels. What I really wanted was a way to just stream raw audio through my ssh tunnel and then pick it up on the other side. None of this re-encoding stuff solutions like Icecast require. Today, I found the way.
MPD has one audio output that can be configured which is a FIFO (first-in-first-out) file. This just puts the raw audio data into the file in order such that another program can pick up exactly what MPD is playing at any given time. I use this already, since the frontend I use for MPD, ncmpcpp, has a visualizer which uses the fifo. The question is how to actually play this audio data.
Enter mplayer. This has a convenient demuxer called 'rawaudio' which just assumes it's being thrown pure audio data to play. After some tweaking, I discovered that using the option '-rawaudio rate=22050' was also necessary for my setup. Your mileage may vary.
Third question, of course, is how to do this over the network. Here's where ssh and good old 'cat' come into play. With "ssh host 'cat /path/to/mpd.fifo'" piped to mplayer with a - (the conventional read-from-stdin marker), suddenly I have music over the network through ssh! Latency is great; I'm streaming through two SSH tunnels between Massachusetts and Arizona, and I'm still getting nearly-skipless playback. To recap, here's what you need:
Set up a fifo in mpd.conf -- see the mpd site for details. Then:
ssh host 'cat /path/to/fifo' | mplayer -demuxer rawaudio -rawaudio rate=22050 -
enter in any ssh credentials you might need to, and you should have music!
Enjoy!
Feedback
| Draft | false + |
| Post category | frontpage +, music +, and technology + |
| Post date | 24 December 2009 + |
| Post permalink | http://wiki.ianmcorvidae.net/wiki/Streaming%20over%20ssh%20with%20mplayer%2Bmpd + |
| Post summary | So while experimenting today, I figured out how to do something really cool: stream my music from mpd over ssh! |
| Post tag | ssh +, mplayer +, and mpd + |
| Post title | Streaming over ssh with mplayer and mpd + |
| Type | blog post + |

