Casey Anderson, 2022
Note OMXPlayer
is being "phased out" in favor of VLC
, this tutorial assumes usage of Raspbian Buster Lite (Legacy)
, under which OMXPlayer
is still available via aptitude
The Raspberry Pi is an excellent low-cost video looper, particularly for situations in which the video needs to "loop forever" and do so automatically on boot. Below are instructions for running the raspberry pi over the command line (via ssh
or screen
), also known as running "headless."
OMXPlayer
is the recommended command line video player for raspbian
. One can download and install it via aptitude
: sudo apt-get install omxplayer
Two quick changes to one config file: /boot/config.txt
-
Uncomment (delete the
#
) the line reading#hdmi_force_hotplug=1
-
Uncomment
hdmi_group
andhdmi_mode
and use the following numbers to set HDMI and 1080p at 60Hz as default (if you need a different default in the future it is simply a matter of updating with different values):hdmi_group=1 hdmi_mode=16
-
Save and exit the file
- Download and install
youtube downloader
via their manual installation instructions, also include below:sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl
- Confirm that it is working with
youtube-dl --version
- (optional) Run the following to update
youtube-dl
to the latest version (might not be necessary):sudo youtube-dl -U
- Locate a short video on youtube to act as a test file. for example, one can download the "original" Nyan Cat animation from youtube (as of 03/14/2017) via:
youtube-dl https://www.youtube.com/watch?v=QH2-TGUlwu4&t=4s
- Use the Unix command
mv
to change the Nyan Cat video filename (which is obnoxious) to simplynyan_cat.mp4
:mv Nyan\ Cat\ \[original\]-QH2-TGUlwu4.mp4 nyan_cat.mp4
- Play the video:
omxplayer nyan_cat.mp4
omxplayer player has built-in looping functionality: omxplayer --loop nyan_cat.mp4
omxplayer also has a bunch of parameters to customize the specifics of the loop playback. try running the following (replace nyan_cat.mp4
with whatever your video is called): omxplayer -b --loop --no-osd -o hdmi nyan_cat.mp4
more specifically:
-b
: forces omxplayer to create a black background behind the video--loop
: the normal command to force omxplayer to loop a video file--no-osd
: hides the on-screen dialogue messages (like "Seeking..." when looping back to the beginning of the video)-o hdmi
: forces audio output via the HDMI cable-r
: not used in the command above but can force the video to fill the screen
With minimal alterations, and a bit of setup, one can make a bash
file that runs the omxplayer loop command:
-
On your raspberry pi make a file called
loop-one.sh
:nano loop-one.sh
(you couldvi
if you prefer) -
Copy the following code and paste it all into your
loop-one.sh
file (then save and exit):#!/bin/sh omxplayer -b --loop --no-osd -o hdmi /home/pi/FILENAME.mp4
-
Make
loop-one.sh
executable withchmod
:chmod +x loop-one.sh
-
Run
loop-one.sh
with the following command./loop-one.sh
-
Control-C
(KeyboardInterrupt) to exit loop
- On your pi open
rc.local
withnano
:sudo nano /etc/rc.local
- Scroll until you see
exit 0
at the bottom of the file and add two new lines aboveexit 0
(exit 0
has to be the last line in this file) - Assuming you want to loop one video forever configure
rc.local
to runloop-one.sh
withbash
as a background process on boot (the&
at the end of the loop is mission critical here):su -c "sh /path/to/file/loop-one.sh" pi &
- Save and exit
- Test that we configured
rc.local
correctly (the video should start playing):sudo /etc/rc.local
- Control-C to cancel playback (assuming it's working)
- Reboot:
sudo reboot now
- Confirm that the looper starts up shortly after the login prompt appears. if not happen make sure
loop-one.sh
has been made executable (chmod +x loop-one.sh
) - Since the line in
rc.local
ends with an&
one can login back into the pi and, among other things, stop the looping process from launching automatically on boot: comment out (add a#
in front of) the line we just added torc.local
in order to revert to non-looping functionality. save, exit, and reboot to confirm non-looping behavior.