Looping video playlist with Omxplayer on the Raspberry Pi
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. One problem is the current lack of playlist support in omxplayer, so this post explains how to create a bash script that will permanently loop through and play a directory of videos.
First install omxplayer:
sudo apt-get install omxplayer
Now create this script named for example “videoplayer.sh”:
#!/bin/sh
# 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
VIDEOPATH="/mnt/storage/videos"
# you can normally leave this alone
SERVICE="omxplayer"
# now for our infinite loop!
while true; do
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
sleep 1;
else
for entry in $VIDEOPATH/*
do
clear
omxplayer $entry > /dev/null
done
fi
done
Save the script, make it executable, and then run it as follows:
./videoplayer.sh
Obviously this is fairly basic – it just loops through a directory of videos and plays them one after another but in our case this was exactly what we wanted. It doesn’t even check that the files are actually video files although it would be easy to add this in. Regardless, it is hopefully a good starting point for more complex scripts.
Enjoy!
14 thoughts on “Looping video playlist with Omxplayer on the Raspberry Pi”
The movie was not stretched over the entire screen so the upper and lower part of the screen could be seen.
I changed an entry and got it to stretch all the way.
Hope this helps someone.
#!/bin/sh
# 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
VIDEOPATH=”/mnt/storage/videos”
# you can normally leave this alone
SERVICE=”omxplayer”
# now for our infinite loop!
while true; do
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
sleep 1;
else
for entry in $VIDEOPATH/*
do
clear
omxplayer -r $entry > /dev/null
done
fi
done
I’d like a modified script that will be able to loop and start playing new files from that folder if video files are added into the folder while the script is already running. Can anyone help me please? I’m no good at programming and scripting
I am experimenting with the Raspberry Pi, and would like to shuffle the playlist items, so the next time the player runs the playlist, the items will run in a different sequence.
I went over OMXPlayer command options and Key Bindings, but found nothing helpful. any idea?
Thanks in advance, George
But the problem is, that the audio output is only via the 3,5mm jack. Is there any way to give audio out via HDMI?
thanks
I got everything working just how you explained above. When I SSH to my RPI and run the scripts as ./videoplayer.sh it plays the movies just fine but when I close the terminal window on the remote machine the video stops playing and I get a black screen.Any thoughts?
How can i pause,stop,play the video using Script?
please help me…
Thanks and regards
sunil
VIDEOPATH=”http://mydomain.com/videos”
??
I have tested ‘omsplayer’ using web adress and works, but with simple command line
example:
omsplayer -o hdmi http://domain.com/videos/video.mp4
So Im wonder if We can use HTTP adress as path…