Skip to content

Instantly share code, notes, and snippets.

@anthonyray
Created September 6, 2019 15:45
Show Gist options
  • Save anthonyray/bb6fd7363cd99204330f17c54513f293 to your computer and use it in GitHub Desktop.
Save anthonyray/bb6fd7363cd99204330f17c54513f293 to your computer and use it in GitHub Desktop.
Turn your Raspberry Pi into a kiosk playing looping videos

An acquaintance needed a video kiosk that plays looping videos for an exposition booth. Since I have a bunch of Raspberry Pis lying around, I figured that it would be the perfect use case for using one of them.

Let's assume we start from scratch, with a unflashed, brand new SD card and your Raspberry Pi.

Installing the OS

Install a version of Raspbian that includes the desktop. You can head over to : https://www.raspberrypi.org/downloads/raspbian/ and follow the instructions.

Once the image is downloaded, you can burn it to your SD card with tools like Etcher (https://www.balena.io/etcher/)

Connect the device to your network

Let's configure your raspberry to connect automatically to your Wifi. Create a file named wpa_supplicant.conf that has the following content :

country=<COUNTRY_CODE>
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
    ssid="Your Wi-Fi network name"
    psk="Your Wi-Fi network password"
}

Make sure to update the country, ssid and psk keys.

Insert the SD card in your computer and copy the wpa_supplicant.conf file at the root of the boot volume of the SD card. To enable SSH access add an empty file ssh also placed at the root of the boot volume on your SD card.

Insert the SD card in your raspberry Pi : You should now have SSH access to your Raspberry Pi. By default, its hostname will be raspberrypi.local.

Copy your video to the Raspberry Pi.

Download the video you want to play on your booth. Since we will be using vlc (https://www.videolan.org/vlc/), your video should have a format that is supported by vlc.

Open up a terminal, and you can copy the video to your Pi with the following command :

scp path_to_your_video/your_video.mp4 [email protected]:~

This will copy your video to the home directory of your Raspberry Pi.

Create a background job that will start playing your video when booting your Pi

We are going to create a background job that your operating system will launch at each boot of your Pi. To do so, we are creating a systemd unit file that will have this content :

[Unit]
Description=videokiosk

[Service]
User=pi
Environment="DISPLAY=:0"
ExecStart=/usr/bin/vlc -Rf path_to_your_video.mp4
WorkingDirectory=/home/pi
Restart=always

[Install]
WantedBy=multi-user.target

We created a systemd service that we call videokiosk.

  • We add a User field as VLC is not supposed to be started as the root user.
  • We add an environment variable called DISPLAY so that the video plays on the HDMI output of the Pi.
  • We use the -Rf flag in the vlc command so that the video plays in full screen and on repeat.

Connect to your raspberry Pi over ssh :

ssh [email protected]

Use your favorite text editor to create the unit file :

sudo nano /etc/systemd/system/videokiosk.service

Copy/Paste the unit file we described earlier. Enable the service to auto-start on boot.

sudo systemctl enable videokiosk.service 

To start the service :

sudo systemctl start videokiosk.service 

To view the latest logs, use sudo journalctl -xfu videokiosk.service

To view the current service status, use sudo systemctl status videokiosk.service

You should be good to go !!

@siteswapjuggler
Copy link

Trying this on latest Bookworm Lite release and it doesn't start any video... Do you remember which version of Raspberry Pi OS you used for this installation ?

@anthonyray
Copy link
Author

I believe it was the Buster release, but it was a while ago !

@siteswapjuggler
Copy link

Thanks for your answer I finally found a solution by using basic.target and adding a restart delay of 1s... so far it seems to work.

@aptoumanoff
Copy link

Worked flawlessly with most recent version of bookworm (non-lite) for me. Thanks for a straightforward guide. Years ago I made a bunch of signage primarily in crontab. This is far better!

@principis
Copy link

principis commented Oct 13, 2024

I had to use cvlc, other than that it works perfectly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment