Delving the depths of computing,
hoping not to get eaten by a wumpus

By Timm Murray

Running VLC Automatically on a Headless Raspberry Pi

2013-11-07


I’ve been setting up a living room stereo with playback with Raspberry Pi. The server runs headless and uses the HTTP interface. Here’s what I did:

  1. Install vlc with apt-get install vlc

  2. Pick a port and allow it with iptables:

iptables -A INPUT -p tcp --dport 43822 -j ACCEPT

  1. Go into your network’s router and give your Raspberry Pi’s MAC address a static DHCP assignment

  2. Edit /etc/vlc/lua/http/.hosts to allow connections from the local network (this will depend on your network’s address settings)

  3. Generate an M3U playlist and save it to /etc/vlc/playlist.m3u

  4. Test vlc by running:

cvlc -I http --http-port 43822 /etc/vlc/playlist.m3u

Using cvlc here will run it purely on the command line. You should now be able to open up a web browser on another machine, go to http://<raspbery pi IP>:43822, and be able to control it from there.

  1. VLC refuses to run as root, so create a vlc user with no homedir, password, or shell:

sudo adduser --no-create-home --shell /bin/false --disabled-password vlc

  1. Create a script at /etc/vlc/start.sh:

#!/bin/sh VLC_PORT=43822 VLC_USER=vlc sudo -u vlc cvlc --http-port ${VLC_PORT} /etc/vlc/streaming.m3u > /dev/null

Make sure to set it chmod +x

(I choose to redirect its output to /dev/null because the SD card that the Raspberry Pi runs off of isn’t going to last long with a lot of log writes.)

  1. Run the script command into /etc/rc.local:

/etc/vlc/start.sh &

  1. Restart the Raspberry Pi. When it’s finished, you should be able to browse to the same location above and get the controls again.

You can then install an app on your phone like “Remote for VLC” to control it from there, or just use the raw HTML interface in a browser.



Copyright © 2024 Timm Murray
CC BY-NC

Opinions expressed are solely my own and do not express the views or opinions of my employer.