RASPBERRY PI VIDEOLOOPER

You are an artist and tired of having no access to expensive Brightsign Players or a dedicated Computer to loop your Full HD video? RaspberryPi micro-computers are cheap and well equipped for the job!

RASPBERRY PI VIDEOLOOPER

RASPBERRY PI VIDEOLOOPER

As a multimedia artist, you sometimes need a media-player that reliably loops a single video or a few video files in a playlist. Museums, mainstream exhibition venues and established artists usually use a dedicated computer or a Brightsign Player. Yet both options are quite expensive!

Maybe you are still a student, or you run an off-space with limited finances - maybe you are not (yet) very well established as an artist and you don't have a lot of budget. Then a Raspberry Pi micro-computer is a very good alternative! Depending on which model you choose you can easily loop videos in fullHD or even in 4K, at the time of writing for a cost of between approximately $10/€12.50 (Raspberry Pi Zero W - 512MB) and $80/€90 (Raspberry Pi 5 - 8GB).

In this tutorial we show you how to setup a Raspberry Pi as a simple VLC based videolooper. This setup will work with any Raspberry Pi micro-computer.

CAPABILITIES

what this videolooper can do

After the successful implementation of these instruction, when you boot your Raspberry Pi, it will look for all video files stored in an autoplay folder, add them to a playlist and loop this playlist indefinitely. Furthermore it will look for attached USB drives, search them for video files and add them to the playlist. The USB drive has to be attached to the Raspberry Pi when it boots up. The autoplay script can easily be tweaked to accomodate a wide variety of VLC command line options.


1) You can either transfer video files directly onto the Raspberry Pi's harddisk or connect a USB drive to one of its USB ports. When you boot your Raspberry Pi, our autoplay script will look for video files on any device attached to it, as well as in one secific folder location on its internal harddisk. It then automatically creates a playlist with all the files it found - before it proceeds to loop the entire playlist. This setup will play videos in fullHD (stereo audio via 3.5mm jack socket - can be forced through HDMI in the Rasperry Pi settings - sudo raspi-config). It works with any Raspberry Pi micro-computer.

2) Special use cases: Raspberry Pi OS (Bookworm) in combination with a Raspberry Pi 4 (we tested 4GB RAM) or a Raspberry Pi 5 results in a truly seamless loop of a single video file, both in fullHD and - with some additional tweaks - in 4K. However, the default setup and the scope of this tutorial is fullHD, because this tutorial is supposed to work with ANY Raspberry Pi!

3) This setup can be adjusted to meet different needs. I.e. you may want to attach an external soundcard for better audio quality. Maybe you want to make use of both HDMI ports of your Raspberry Pi 4 and play two videos simultaneously on two separate screens. All of it is possible, yet you then need to adjust the scripts and the configuration of your Raspberry Pi. You could even edit the autoplay script to use the GPIO pins of the Raspberry Pi, i.e. to start a stepper motor after video playback...

We may write one or the other tutorial about such special use-cases in the future...

PREREQUISITES

follow HEADLESS SETUP tutorial & additional performance tweaks

Install a fresh version of Raspberry Pi OS Lite. We want to keep this installation as lightweight and minimal as possible, so we choose a distribution that has no desktop environment. This tutorial works with both Raspberry Pi OS Lite 32-bit or 64-bit either on Bookworm or Bullseye (Legacy). However, if your Raspberry Pi allows it, we do recommend you choose a 64-bit distribution (better performance). Sometimes there are good reasons to pick Bullseye (Legacy), i.e. because there are quite a few breaking changes between Bullseye and Bookworm. If you have no special needs (i.e. the Pimoroni FanShim for cooling does work with Bullseye, but not with Bookworm), we recommend you install the latest version of Raspberry Pi OS Lite (Bookworm).

This tutorial assumes that you create an admin user account and a standard user account. Thus we highly recommend you follow our HEADLESS SETUP tutorial to setup your Raspberry Pi first, before you continue to follow this tutorial!

PLEASE NOTE: THE STANDARD USER WE USE FOR THIS TUTORIAL IS CALLED LOOPER (NOT TERM7). YOU CAN CHANGE YOUR USERNAME ACCORDINGLY.

HEADLESS SETUP: Basic configuration of a Raspberry Pi + hardened SECURITY
For a lot of projects we do use Raspberry Pi micro computers. This post is both, a short introduction and a quick first-time setup tutorial, focused on security, using MacOS.

MORE PERFORMANCE TWEAKS

Depending on your Raspberry Pi, there are different options to improve its performance. SSH into your Raspberry Pi:

# Replace the IP Address with your own local IP Address:ssh looper@192.168.1.123 -p 6666

Log into your admin account:

su admin

Then execute this command to enter the Raspberry Pi Software Configuration Tool:

sudo raspi-config

If you follow this tutrial with a Raspberry Pi 2, you can use this tool to overclock its CPU. We recommend to only do a modest setting that creates no overvoltage. In general, we do recommend you adjust the GPU memory in Performance Options (not relevant for Raspberry Pi 4 and Raspberry Pi 5. Depending on how much RAM you have in general, choose 256 or 512. Alsways under Advanced Options -> A8 Glamor enable glamor acceleration:

AUTOMOUNT

automatically mount USB devices

Raspberry Pi OS Lite doesn't automatically mount USB storage media by default. Since we want to be able to autoplay files from a USB drive, our next step is to enable this behavior. With a udev rule, systemd service, and a mount script, we can ensure that any attached USB stick is not just mounted at boot, but also assigned a predictable mount point.

Install required software package:

# Install pmount:sudo apt install pmount


Create a new UDEV rule:

# Install pmount:sudo nano /etc/udev/rules.d/usb_hook.rules

Insert:

# UDEV Rule:ACTION=="add", KERNEL=="sd[a-z][0-9]", TAG+="systemd", ENV{SYSTEMD_WANTS}="usbstick-handler@%k"


First, create the required folder locations:

# Prepare Script Location :mkdir ~/script && mkdir ~/script/automount && cd ~/script/automount

Write a script for the required mount points. Most Raspberry Pi's have 4 USB ports, so we define 4 mountpoints:

sudo nano usbmount

Copy & Paste the following content:

#!/bin/bash

if mountpoint -q /media/usb1
then
   if mountpoint -q /media/usb2
   then
      if mountpoint -q /media/usb3
      then
         if mountpoint -q /media/usb4
         then
             echo "No mountpoints available!"
             #You can add more if you need
         else
             /usr/bin/pmount --umask 000 --noatime -w --sync $1 usb4
         fi
      else
         /usr/bin/pmount --umask 000 --noatime -w --sync $1 usb3
      fi
   else
      /usr/bin/pmount --umask 000 --noatime -w --sync $1 usb2
   fi
else
   /usr/bin/pmount --umask 000 --noatime -w --sync $1 usb1
fi

To save, press [control] + X. Then press Y to confirm the changes and [ENTER] to close nano.

Make usbmount executable:

sudo chmod +x usbmount


Next, we need to create a special system service that runs in the background and that executes our script whenever a USB device is plugged in:

# usbstick-handler@.service:sudo nano /etc/systemd/system/usbstick-handler@.service

Copy & Paste the following content:

[Unit]
Description=Automount
BindsTo=dev-%i.device
After=dev-%i.device

[Service]
Type=oneshot
ExecStart=/home/admin/script/automount/usbmount /dev/%I
ExecStop=/usr/bin/pmount /dev/%I

Again, press [control] + X to save. Then press Y to confirm the changes and [ENTER] to close nano.

Now reboot your Raspberry Pi. Plug in a USB drive. After the reboot ssh into your Raspberry Pi and check if you can access its contents under /media/usb1:

List content of /media/usb1:ls /media/usb1

If you see usb1 and its content, then your USB drive has been automatically mounted successfully!


Sometimes you may want to play files that are larger than 4GB which is the file size limit for USB devices that are FAT32. You can get around this file size limit if you format your USB device using EXFAT. However, in order to add support for EXFAT on your Raspberry Pi, you have to install the following software package:

# EXFAT:sudo apt install exfat-fuse

AUTOPLAY

videolooper

Finally it is time to set up your Videolooper!

First log into your admin account and install the video player. We use VLC because it supports hardware acceleration, it does not need a graphical user interface (GUI) and it can be controlled via the command line (our autoplay script):

# Install VLC:sudo apt install vlc


We again need to create a system service that starts out Videolooper after every reboot:

# Videolooper Service:sudo nano /lib/systemd/system/autoplay.service

Insert:

[Unit]
Description=Autoplay
After=multi-user.target

[Service]
WorkingDirectory=/home/looper     
User=looper
Group=looper
Environment="DISPLAY=:0"
ExecStart=/bin/sh /home/looper/Script/autoplay.sh

[Install]
WantedBy=multi-user.target

Press [control] + X to save the file. Then press Y to confirm the changes and [ENTER] to close nano.

Next, with this command we enable the service to start with every reboot:

# Enable autoplay.service:sudo systemctl enable autoplay.service


For the next steps, make sure you are looged into your standard user account: in this example looper. If you named your standard user differently, please make sure you adjust the system service script and the folder paths in the autoplay script accordingly.

In your standard user's home directory, create the required folder structure:

mkdir ~/Videos && mkdir ~/Videos/autoplay
mkdir ~/Script && cd ~/Script

Finally we create the core of this project, our autoplay script. In this script you can define all paramaters and all options that the VLC command line has to offer. For example: we only want to play MP4, MOV and MKV files. What if you want to play an AVI? Just edit this script and add it to the list of filetypes that you want to play. Perhaps you want to rotate the video in your screen, mute the video or play a slideshow of images instead? In this script you can add the required parameters:

# Autoplay Script:sudo nano autoplay.sh

Insert the following content:

#!/bin/sh

# VLC OPTIONS:
# View all possible options: vlc -H

export AUTOPLAY=/home/looper/Videos/autoplay
export USB=/media/
export PLAYLIST=/home/looper/Videos/playlist.m3u

# Video Filetypes (you can add more filetypes):

FILETYPES="-name *.mp4 -o -name *.mov -o -name *.mkv"

# Playlist Options:
Playlist_Options="-L --started-from-file --one-instance --playlist-enqueue"

# Output Modules (edit and uncomment to add more options):
#Video_Output=--gles2 egl_x11 --glconv mmal_converter --mmal-opaque

Audio_Output=--stereo-mode 1

# Interface Options:
Interface_Options="-f --loop --no-video-title-show"


# Create Playlist File
# COMMENT: change sleep to 3 if you only want to play from the internal disk to start playback earlier, 25 is only necessary in order to find the USB drive after the Pi boots up, because otherwise the script may start before the USB drive is mounted and no files will be added from USB!

sleep 25
echo "#EXTM3U" > "$PLAYLIST"
find "$AUTOPLAY" ! -iname ".*" -type f \( $FILETYPES \)  >> "$PLAYLIST"
find "$USB" ! -iname ".*" -type f \( $FILETYPES \)  >> "$PLAYLIST"
sleep 1

# If Playlist exists, play Playlist

if [ "$(wc -l < /home/looper/Videos/playlist.m3u )" != "1" ]; then
    /usr/bin/vlc -I dummy -q $Video_Output $Audio_Output $Interface_Options $Playlist_Options "$PLAYLIST"
fi

Press [control] + X to save the file. Then press Y to confirm the changes and [ENTER] to close nano.

Also this script needs to be executable:

chmod +x autoplay.sh

Documentation:Command line - VideoLAN Wiki
VLC command-line help - VideoLAN Wiki

You can now test your Videolooper!

Use this command to transfer a file from your computer to the autoplay folder of your Raspberry Pi (adjust the variables to match your video file and your Pi's local IP address):

# Filetransfer via SCP:scp -P 6666 ~/Desktop/video.mp4 looper@192.168.1.123:/home/looper/Videos/autoplay

Prepare some files on a USB media storage and/or use this command to transfer a file from your computer to the autoplay folder of your Raspberry Pi (adjust the variables to match your video file and your Pi's local IP address):

sudo shutdown now

Attach a screen to your Pi's HDMI port, place some video files on a USB media storage and plug it into your Raspberry Pi (if you want you can also just play from the internal autoplay folder). Connect power to boot it. After a short while it should automatically loop the video you transferred to the autoplay folder and/or the files on your USB media storage.


Here you can download our two test files:


\(^0^)ノ

Congratulations! You now have a working SIMPLE VIDEOLOOPER!

We wish you a HAPPY NEW YEAR!

RECOMMENDATIONS

protection & cooling...

You should think about purchasing a protective case for your Raspberry Pi.

Depending on the model of your Raspberry Pi and on how 'heavy' your video files are, video playback can create quite some stress for your Pi's CPU and GPU. If your Pi overheats it will start to throttle its speed, which will result in stuttering video playback and glitches. Eventually it will crash if it becomes too hot!

This is why we do recommend you install a fan to cool down your Raspberry Pi. There are quite a few options out there that can be mounted on its GPIO pins. It will protect your Pi against overheating and increases its life span!


GitHub - term7/RaspberryPi-VLC_Videolooper: Versatile Videolooper based on VLC for the Raspberry Pi (2B, 3B, 3B+, 4B)
Versatile Videolooper based on VLC for the Raspberry Pi (2B, 3B, 3B+, 4B) - term7/RaspberryPi-VLC_Videolooper