Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full update #1

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
# videolooper-raspbian
Automatically play full screen videos on a Raspberry Pi (2).
The original by Tim Schwartz, http://www.timschwartz.org/raspberry-pi-video-looper/
#Video Looper for Raspbian
Automatically play and loop fullscreen videos on a Raspberry Pi 2 or 3.

This system uses a basic bash script to play videos with [omxplayer](http://elinux.org/Omxplayer), it simply checks if omxplayer isn't running and then starts it again. This simple method seems to work flawlessly for weeks on end without freezing or glitches. The only caveat of this method is that there are approximately 2-3 seconds of black between each video. If you are looking to do something with gapless looping on Raspberry Pi, try [Slooper](https://github.com/mokafolio/Slooper) by [Matthias Dörfelt](http://www.mokafolio.de/), though currently it needs a few updates to work without a remote (as of May 15, 2016).

There is a [videolooper](https://github.com/adafruit/pi_video_looper) written in python that uses omxplayer by [Adafruit](http://www.adafruit.com), but unfortunately on testing looping videos for more than a day it froze (as of May 15, 2016).

The script will look for videos either in:
* the `video` directory in the home directory of the pi user
* a usb stick plugged in before startup (this will not be remounted if you pull it out and plug it back in)

#Installation

##Grab 'n Go
Copy the [prebuilt img](http://timschwartz.org/downloads/2016-05-10-raspbian-jessie-lite-video-looper.img.zip) to a micro SD card using [these instructions](https://www.raspberrypi.org/documentation/installation/installing-images/). The img was setup using the steps below and `2016-05-10-raspbian-jessie-lite` was used as the base raspbian image.

##Roll Your Own
Start with a [raspbian img](https://www.raspberrypi.org/downloads/raspbian/), install it on the pi, and follow the steps below to install the videolooper.

###Install omxplayer
```
sudo apt-get update
sudo apt-get -y install omxplayer
```

###Setup auto mounting of usb stick
```
sudo mkdir -p /mnt/usbdisk
sudo echo \"/dev/sda1 /mnt/usbdisk vfat ro,nofail 0 0\" | sudo tee -a /etc/fstab
```

###Create folder for videos in home directory
`mkdir /home/pi/video`

###Download startvideo.sh and put it in /home/pi/
```
cd /home/pi
wget https://raw.githubusercontent.com/timatron/videolooper-raspbian/master/startvideo.sh
chmod uga+rwx startvideo.sh
```

###Add startvideo.sh to .bashrc so it auto starts on login
`echo \"/home/pi/startvideo.sh" | tee -a /home/pi/.bashrc`

###Make system autoboot into pi user
`sudo raspi-config`
* Select option: "3 Boot Options"
* Select option: "B2 Console Autologin"

###Expand your root partition if you want to
`sudo raspi-config`
* Select option: "1 Expand Filesystem"
46 changes: 31 additions & 15 deletions startvideo.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,44 +1,60 @@
#!/bin/bash
# Bash script by Tim Schwartz, http://www.timschwartz.org/raspberry-pi-video-looper/ 2013
# Comments, clean up, improvements by Derek DeMoss, for Dark Horse Comics, Inc. 2015
# Added USB support, full path, support files with spaces in names, support more file formats - Tim Schwartz, 2016

declare -A VIDS # make variable VIDS an Array

FILES=~/video/ # A variable of this folder
LOCAL_FILES=~/video/ # A variable of this folder
USB_FILES=/mnt/usbdisk/ # Variable for usb mount point
CURRENT=0 # Number of videos in the folder
SERVICE='omxplayer' # The program to play the videos
PLAYING=0 # Video that is currently playing
FILE_FORMATS='.mov|.mp4|.mpg'

getvids () # Since I want this to run in a loop, it should be a function
{
unset VIDS # Empty the VIDS array
CURRENT=0 # Reinitializes the video count

for f in `ls $FILES | grep .mp` # Step through the file in ~/video/
IFS=$'\n' # Dont split up by spaces, only new lines when setting up the for loop
for f in `ls $LOCAL_FILES | grep -i -E $FILE_FORMATS` # Step through the local files
do
VIDS[$CURRENT]=$f # add the filename found above to the VIDS array
VIDS[$CURRENT]=$LOCAL_FILES$f # add the filename found above to the VIDS array
# echo ${VIDS[$CURRENT]} # Print the array element we just added
let CURRENT+=1 # increment the video count
# echo ${VIDS[$CURRENT]} # Print the array element we just added
done
if [ -d "$USB_FILES" ]; then
for f in `ls $USB_FILES | grep -i -E $FILE_FORMATS` # Step through the usb files
do
VIDS[$CURRENT]=$USB_FILES$f # add the filename found above to the VIDS array
#echo ${VIDS[$CURRENT]} # Print the array element we just added
let CURRENT+=1 # increment the video count
done
fi
}


while true; do
if ps ax | grep -v grep | grep $SERVICE > /dev/null # Search for service, print to null
then
echo 'running'
else
getvids # Get a list of the current videos in the folder
let PLAYING+=1
if [ $PLAYING -ge $CURRENT ] # if PLAYING is greater than or equal to CURRENT
if [ $CURRENT -gt 0 ] #only play videos if there are more than one video
then
PLAYING=0 # Reset to 0 so we play the "first" video
let PLAYING+=1
if [ $PLAYING -ge $CURRENT ] # if PLAYING is greater than or equal to CURRENT
then
PLAYING=0 # Reset to 0 so we play the "first" video
fi

#echo ${VIDS[$PLAYING]}
if [ -f ${VIDS[$PLAYING]} ]; then
/usr/bin/omxplayer -r -o hdmi ${VIDS[$PLAYING]} # Play video
fi
# echo "Array size= $CURRENT" # error checking code
else
echo "Insert USB with videos and restart or add videos to /home/pi/video and run ./startvideo.sh"
exit
fi

/usr/bin/omxplayer -r -o hdmi $FILES${VIDS[$PLAYING]} # Play video
# echo "Array size= $CURRENT" # error checking code
fi
done