adventures with microcomputers prototyping with raspberry pi

9. Fixed Media (Video, Sound)

Note: mad props to this article, which was a crucial source of inspiration/help for what follows.

The Raspberry Pi is an excellent low-cost, reliable 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

config file changes

Two quick changes to one config file: /boot/config.txt

  1. Uncomment (delete the #) the line reading #hdmi_force_hotplug=1
  2. Uncomment hdmi_group and hdmi_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):

  3. Save and exit the file.

acquiring and playing a video

  1. download and install youtube downloader via apitutude: sudo apt-get install youtube-dl
  2. 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
  3. use the Unix command mv to change the Nyan Cat video filename (which is obnoxious) to simply nyan_cat.mp4: mv Nyan\ Cat\ \[original\]-QH2-TGUlwu4.mp4 nyan_cat.mp4
  4. play the video: omxplayer nyan_cat.mp4

looping a video file

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

looping one video forever

With minimal alterations, and a bit of setup, one can make a bash file that runs the omxplayer loop command:

  1. on your raspberry pi make a folder called videolooper in your home directory: mkdir videolooper
  2. cd into videolooper: cd videolooper
  3. make a video folder inside videolooper (videos will be stored here): mkdir video
  4. on your mac make a new file called wherever you want (we are going to set this up and then send it to the raspberry pi via scp): touch
  5. open up in whatever text editor you like (remember, we are still on our mac at this point). i like Atom : atom
  6. Copy the following code and paste it all into your file (then save and exit):

    omxplayer -b --loop --no-osd -o hdmi /home/pi/nyan_cat.mp4
  7. use scp to send to your raspberry pi (note, this requires knowledge of your pi's ip address): scp pi@<PI_IP_ADDRESS>:/home/pi/

  8. back on your pi, make executable with chmod: chmod +x

  9. run with the following command ./

  10. Control-C (KeyboardInterrupt) to exit loop

looping all videos in a playlist forever

  1. on your mac make a new file called touch
  2. open it with your preferred text editor (again, I use Atom so it looks like this when I do it): atom
  3. Copy the code from this file and paste it all into your file (then save and exit)
  4. send to your raspberry pi: scp pi@<PI_IP_ADDRESS>:/home/pi/
  5. move the file into the videolooper directory: mv videolooper/
  6. update to include the correct path and filename information (via nano or vi) stored at VIDEOPATH
  7. make executable with chmod: chmod +x
  8. run with the following command ./
  9. Control-C (KeyboardInterrupt) to exit loop

running loop script on startup

There are lots of ways to run a file on startup. Regardless of whether one needs to loop one video forever on boot or loop several videos in a folder forever on boot, its simply a matter of specifying which script (file) one wants to use with rc.local (the service which will launch the script on boot):

  1. on your pi open rc.local with nano or vi: sudo nano /etc/rc.local
  2. scroll until you see exit 0 at the bottom of the file and add two new lines above exit 0 (exit 0 has to be the last line in this file)
  3. assuming you want to loop all folders in a directory, configure rc.local to run with bash as a background process on boot (the & at the end of the loop is mission critical here): su -c "sh /path/to/file/" pi &
  4. save and exit
  5. reboot: sudo reboot now
  6. confirm that the looper starts up shortly after the login prompt appears. if not happen make sure has been made executable (chmod +x
  7. 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 to rc.local in order to revert to non-looping functionality. save, exit, and reboot to confirm non-looping behavior.

alternately, if one wanted to use the script and not, or even to some other bash script, one would simply point rc.local to, resulting in the following line: su -c "sh /path/to/file/" pi &