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
Here is a list of all the omxplayer options and a general how to use them.

pi@raspberrypi:~$ omxplayer --help
Usage: omxplayer [OPTIONS] [FILE]
Options :
         -h / --help                          print this help
         -a / --alang language          audio language        : e.g. ger
         -n / --aidx  index               audio stream index    : e.g. 1
         -o / --adev  device             audio out device      : e.g. hdmi/local
         -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
         -y / --hdmiclocksync         adjust display refresh rate to match video
         -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. “”


# get rid of the cursor so we don't see it when videos are running
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
        if ps ax | grep -v grep | grep $SERVICE > /dev/null
        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


Then run it as follows



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





scroll to top