Looping video playlist with OMXPlayer on the Raspberry Pi

The Raspberry Pi comes with an awesome little video player called OMXPlayer that is very capable of playing back full 1080p video perfectly when encoded correctly in H.264/AAC.
OMXPlayer is a commandline OMX player for the Raspberry Pi. It was developed as a testbed for the XBMC/Kodi Raspberry Pi implementation and is quite handy to use standalone.
One problem is the current lack of playlist support in omxplayer. This post explains how to create a bash script that will permanently loop through and play a directory of videos.



To install the Omxplayer on Raspbian

sudo apt-get install omxplayer


Playing a movie with OMXPlayer

[email protected]:~$ omxplayer --help
Usage: omxplayer [OPTIONS] [FILE]
Options :
         -h / --help                          print this help
         -i / --info                          dump stream format and exit
         -s / --stats                         pts and buffer stats
         -p / --passthrough             audio passthrough
         -d / --deinterlace              deinterlacing
         -w / --hw                         hw audio decoding
         -3 / --3d                          switch tv into 3d mode
         -t / --sid index                  show subtitle with index
         -r / --refresh                     adjust framerate/resolution to video


HDMI cable for video output and standard 3.5 mm for audio output:

omxplayer -o local /VideoFileLocation/VideoFileName.videoextension


Send audio through the HDMI cable with video:

omxplayer -o hdmi /VideoFileLocation/VideoFileName.videoextension


Create script for looping video playlist
Create the following script and save a name e.g. “videoloop.sh”


setterm -cursor off

# set here the path to the directory containing your videos

# you can normally leave this alone

# now for our infinite loop!
while true; do
        sleep 1;
        for entry in $VIDEOPATH/*

                # -r for stretched over the entire screen
                omxplayer -r $entry > /dev/null


Save the script and make it executable

sudo chmod +x videoloop.sh


Then run it as follows



Obviously this is fairly basic; just loops through a directory of videos and plays them one after another.