Challenge: Find a low cost way to seamlessly loop high resolution video.
Version 3 of RPiLooper for RPi2 is here: http://curioustechnologist.com/post/118279299189/rpilooper-v3-image-for-raspberry-pi-2-available
Features: support of Raspberry Pi 2, B+, and B, along with all features of previous versions.
RpiLooper v2 for Raspberry Pi B+ is here: http://curioustechnologist.com/post/104242571716/rpilooper-v2-b-seamless-video-looper-for
Version 2 of RPiLooper is available here: http://curioustechnologist.com/post/88679377976/seamlessly-looping-raspberry-pi-video-kiosk
Features: auto-mounting USB drive, easier method for changing video loops, and a downloadable, ready-to-run image. Version 2 is much simpler, and I recommend heading straight on over there instead of using the instructions here.
(Spoiler: we did! Check this video to see if this is what you’re looking for.)
We looked at some options, and decided that the Raspberry Pi would be our platform of choice, based primarily on cost (we would need about 15 different looping videos). We did find quite a few options out there. There are a few Pi distributions out there doing a great job of making a Pi-powered kiosk easy to pull off, but all of them share a glaring flaw: big gaps between video loops. For our purposes, we needed our video to instantly restart when it ended with no indication of an interruption. This is useful for art installations and emulating video sources for demos, among other things. As a result, the ready-to-go options weren’t suitable so we rolled our own*.
*This is based primarily on colbyparson’s instructions from this thread: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=8042
The instructions there are spread through the thread and a little difficult to piece together. Also, this method didn’t work for Raspbian releases after Squeeze (debian6-13-04-2012). However Colby, his son, and other contributors on this thread did the heavy lifting without a doubt, and the bulk of the steps below come from their work.
These are instructions for creating a video kiosk with Raspbian (2014-01-07-wheezy-raspbian), resulting in seamless video loops with no gap.
Step 1 – Install Raspbian
Start with the Raspbian distro from the raspberrypi.org downloads page: http://downloads.raspberrypi.org/raspbian_latest
Raspbian setup instructions:
To use an image file, you will need to unzip it and write it to a suitable (2GB or larger, 4GB or larger for Raspbian) SD card using the UNIX tool dd. Windows users should use Win32DiskImager. Do not try to drag and drop or otherwise copy over the image without using dd or Win32DiskImager – it won’t work. If you’re still not clear on what to do, the community on the Raspberry Pi Wiki has written a guide for beginners on how to set up your SD card.
Go ahead and boot up your fresh Raspbian install. Make sure to connect a network cable to your DHCP enabled network, along with a monitor, mouse, and keyboard prior to booting. You’ll get a configuration screen the first time which will let you change the password and make some other changes.
Go ahead and expand the filesystem (since we’re planning on dropping video files on the SD Card).
Do the Change User Password thing too. Remember, you’re changing the password for the “pi” user here.
Hit Finish, and when it asks if you want to reboot, hit Yes.
Once you’re booted up, go ahead and run ifconfig and record the ip address (which you’ll have only if you’ve connected your raspberry pi to a network with a DHCP server). You will want to know this later to SSH in to your pi to make changes, if necessary.
Step 2 – Rebuild hello_pi code examples
Navigate to the /opt/vc/src/hello_pi directory and run the rebuild.sh script as follows:
Step 3 – Update hello_video.bin
Update the hello_video source code to loop any video played with hello_video.bin:
sudo pico video.c
Scroll down to around line 120, and look for the following lines of code:
Replace the above with this:
fseek(in, 0, SEEK_SET);
Note that correct capitalization is important. Use Ctrl+O to save, and Ctrl+X to exit.
Now, while still in the /opt/vc/src/hello_pi/hello_video/ directory, use the make command to compile the code:
Step 4 – Create video folder
Create a video for your videos to live at your Pi’s root:
sudo mkdir /video
Change ownership of the /video directory. This is important, as this allows you to modify files in this folder through SFTP/FTP:
sudo chown -R pi /video
Now you’ll want to get some video into that folder and test out your code. You can only use .h264 or .m4v video files with this solution. As with others in the thread referenced above, I suggest using Yamb to rip the video out of the container. Once finished with Yamb, you will have a file with an .h264 or .m4v suffix. Let’s say this video of yours is called testvideo.h264.
Step 5a – Dropping video into your Pi – SFTP/FTP
If your Pi is on a network, the easiest way to do this is using another computer on the same network to connect using SFTP or FTP. On a Windows machine you can use WinSCP.
Fire up WinSCP, connect to your Pi’s ip address, navigate to the /video folder, and drag your video over.
Step 5b – Dropping video into your Pi – USB drive
If you have this video on a thumb drive, use these instructions to mount it: http://elinux.org/RPi_Adding_USB_Drives
Here’s an example:
sudo mkdir /mnt/usb
sudo mount /dev/sda1 /mnt/usb
Copy your file from your mounted usb drive to the video folder:
sudo cp /mnt/usb/testvideo.h264 /video/
Step 6 – Play a test video
Now try playing your video with your updated hello_video code:
You should see your video, and it should loop seamlessly. A shorter video is going to be easier to test with, unless you want to sit through a movie to test it.
You can kill the process with Ctrl+C.
Step 7 – Start the video loop on boot
This bit starts the video loop on boot, before the login screen.
Create a file called seamless_video.sh in etc/init.d, and populate it as follows:
sudo pico seamless_video.sh
Type in or paste the following
Save and close the file with Ctrl+O and then Ctrl+X
Change the permissions on your seamless_video.sh script to allow it to be executed, and add symbolic links to force it to start when the system boots:
sudo chmod 755 seamless_video.sh
sudo update-rc.d seamless_video.sh defaults
This will play the first video (sorted alphabetically) in your /video folder that is in .h264 or .m4v format. Also, there is no way to stop the loop once it starts – this is where SSH comes in. If you want to change the video or stop the loop, you’ll want to SSH (or FTP/SFTP) in to the ip address you recorded earlier. Removing the videos from the /video folder will stop the loop from starting.
If you try testing at this stage by rebooting, you’ll end up with any bootup messages showing up in the “black bars” of the video, if it doesn’t completely fill the screen. So, we’ll want to hide those messages.
Step 8 – Hide boot messages on screen
Edit the /boot/cmdline.txt file:
sudo pico /boot/cmdline.txt
Make these changes:
– Replace “console=tty1” with “console=tty3” to redirect boot messages to the third console.
– Add “logo.nologo” to remove the Raspberry Pi logo
– Add “loglevel=3” to disable non-critical kernel log messages.
– Add “vt.global_cursor_default=0” to disable the blinking cursor.
Here’s an example /boot.cmdline.txt file:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty3 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait logo.nologo loglevel=3 vt.global_cursor_default=0
That’s it – reboot your Pi and you should have a fullscreen, seamlessly looping video! Just replace the videos in your /video/ directory to update your kiosk using SSH/FTP/SFTP.
This technique will play and loop the first video found (alphabetically) in the /video folder.
To change the video that’s looping, you’ll need to place a new video in the /video folder, and ensure that it is the first video that appears in alphabetical order. Easiest way to do this is to use WinSCP to access your Pi (use the IP address you recorded earlier, and connect with the pi username and the password that you created), drag over a new .h264 or .m4v video, and delete any other videos in the directory. If you have problems adding, modifying, or deleting files through WinSCP, make sure that you’ve changed the ownership of the /video folder to the pi user:
sudo chown pi /video
Video demo of seamless transition: https://www.youtube.com/watch?v=owwmkfBxZpg
Disclaimer: This is nasty, get-it-done scripting, and in no way follows best practices for a production level solution. If anyone has updates, suggestions, alternatives, or a nicely packaged and cleaner version of this, please share! Hope this helps someone looking for a similar solution.
Future points – It would be great to mount a usb thumb drive and play videos from that instead. This would make it much easier to switch out which videos to play if the use case required that. If we decide to go in that direction, we’ll post an updated version.
For those who can use it, here’s a test video in the correct format for testing and troubleshooting purposes: https://dl.dropboxusercontent.com/u/10245008/RPiLooper/Coffee-53s-slomo.h264
I bought my Raspberry Pi’s from Amazon: http://bit.ly/1p3480x
I recommend using these cases, as they stack well (enclosures with the ribbon cable connector cutout don’t stack): http://bit.ly/1oAoTgm
If you’re having trouble converting videos into a format that’s agreeable with RPiLooper, here are some instructions that I follow: http://curioustechnologist.com/post/88672278836/converting-video-for-rpilooper-with-avidemux-one