Page 1 of 1

Auto Updating Video Playback

Posted: Fri Mar 08, 2013 8:33 pm
by tufkal
The goal of my current project is to have Raspberry Pis replace dying DVD players in 50+ retail stores in my company, and adding the ability to update the videos they play. I want to be able to drop the video files on a server/share, and all of the Pis update themselves to the new videos automatically.
--
So far I have accomplished the following:

-Disabled X11 on boot
-Enabled auto-login in console
-Configured auto-run in bash
-Made a loop script that runs on startup

So now you turn on the PI, it boots, and immediately starts playing the video file in a loop forever, and looks great.

Then next trick is updating it. Here is my current loop script (taken from these forums originally), with no updating.

Code: Select all

#!/bin/sh
SERVICE='omxplayer'
while true; do
if ps ax | grep -v grep | grep $SERVICE > /dev/null
  then
    echo "running" # sleep 1
  else
    omxplayer -o hdmi /home/pi/test.mp4 &
fi
done
Here is my current working idea psuedo-code

Code: Select all

#!/bin/sh
SERVICE='omxplayer'
while true; do
if ps ax | grep -v grep | grep $SERVICE > /dev/null
  then
    echo "running" # sleep 1
  else
    rm /home/pi/pi.txt.old
    mv /home/pi/pi.txt.new /home/pi/pi.txt.old
    wget http://www.website.net/pi.txt /home/pi/pi.txt.new
    diff –s /home/pi/pi.txt.old /home/pi/pi.txt.new > result
    if statement to determine if the files were different, and if they are*
       wget http://www.website.net/pi.zip /home/pi/pi.zip
       rm –rf /home/pi/*.mp4
       unzip pi.zip
       rm pi.zip
    fi
    omxplayer -o hdmi *.mp4 &
fi
done
In this version, if it is not running, we download a tiny pi.txt file, which contains just the time and date that the video files were updated last. It then checks if the file it last got, is the same as the file it just got. If they are the same, nothing has changed, and start omxplayer again. If something has changed, download the new ZIP, remove the old videos, unzip the new videos, and then go on. This check would happen every time omxplayer finishes playing the file, so every 5 minutes maybe.

This is pseudo code btw, it will not run obviously, I probably have a few switches wrong and im not sure how I am going to grep the output of diff to see if they were the same yet.

Thoughts? Should I fight with SSH RSA keypairs and rsync over 50 devices? Should I use a scheduled cron task and find a way for it to kill playback during update? Am I insane? Is there a much better and easier way to do this?

Re: Auto Updating Video Playback

Posted: Sat Mar 09, 2013 9:53 am
by DBryant
I'd be looking at off-loading more work onto the server system; in my world this would be a Linux box, but you don't specify it. The server then pushes files onto Pis, whose only roll in life is to select the next file and play it, straightforward and simply and hopefully less prone to error.

The server might monitor a drop-box directory for changes in content i.e for the point at which you add an new DVD. On detection of a new file, it triggers the upload process to each an every Pi in the network and logs the successful upload. Of course you will have to ensure that this trigger is on complete files only.

You might also consider on the server side:
  • + have each Pi export its DVD directory as an NFS mount
    + ssh/scp and key exchange is straight forward and makes the thing secure
    + use rsync on on the server to copy into these locations
    + maintain a chksum on each DVD file, this will allow the file to be verified prior to any attempt to play
    + ordering of play lists. My choice might be for all directories to be used as drop-boxes. If you name them <number>-<title>, then may ease title selection, ordering and and so on.
    + management of remote filesystems to ensure filesystems are not full. Delete, reload and verify are likely useful operations
    + how you will determine the status of the Pi network, detection of malfunctioning Pis. You might implement a periodic ping from the server and/or accept an "I'm alive" message from each Pi
    + logging and alert system for those malfunctioning Pis - you might mail the sysadmin, how can then looks at the logs
    + how you roll software out to the 50-odd Pis in the network
On the client-side (Pi):
  • + NFS export of DVD directory
    + treat as a drop-in box, as in the Pi will simply cycle through the content of this directory
    + selection of next file (alphabetically, by date,... ), creation and validation of chksum and play of file
    + send a periodic "I'm alive" message
    + receive remote commands. For example, 'play next now', 'play this file', 'reboot'
    + maintain a log of activities. This might be written to the NFS-mounted area. It might be constrained to be only the last weeks record, with older ones gzipped or removed.
    + how this system will be updated. For example will it be a live update, or during a controlled re-boot
You can probably think of items for both lists. Prioritise them, and implement these key activities and then roll out the would-be-nice features.

Hope this is helpful.

Re: Auto Updating Video Playback

Posted: Sat Mar 09, 2013 10:43 am
by KenT
Instead of writing the code yourself why not look at Screenly OSE, Screenly Pro or Pi Presents using liveshow (blatant advertising for the latter on my part;-)