Many shows, events or set-ups benefit from having a video playing out on a rotation. The basics here are fairly simple and a Raspberry Pi 3 is a cheap way to build something basic. Uses could include a video menu rotating options, showing video clips or photos at a wedding, running an animated logo on screen at an event, etc.
Note that if this is for a gear bag or case, you can get away with a bare board and USB controller. If it’s a client installation you might want to consider a nice case and building a button to the GPIO – for the example here you’d need to modify the code and you can skip the qjoypad section. If you wire to the GPIO your button should connect to pins 5 and 6 for shutdown.
Along with playing a video on repeat, I use a USB game controller to allow me a little control. My main use here is to have a video with a count up that I can press a button to re-set. This can be used to time any part of your show, and the multi-view is a great place to display it, but it’s not hard to use this set up to have a little more control over the video. See the end of the post for more info on that.
This is assuming a basic Raspberry Pi build. I started with a fresh install of Raspian OS Full 32bit. I booted up, disabled bluetooth and set up wifi. I also made sure that my display settings were set to 1080p60. (may not be needed for you, but I had to also edit /etc/resolv.conf and add a google name server 22.214.171.124 as the one for my router doesn’t play nice with the Pi)
Once the software is all installed, you can set up ssh for changing the video source out but I’d strongly suggest disabling wifi before taking it to an event. If you’re installing at a client location you might want to research code to lock down the ethernet too, and change the login password.
Install all software:
Use Terminal to apt-get with the following commands :
sudo pip3 install pynput
sudo apt-get install qjoypad
Open and set the buttons for qjoypad.
This may take some trial and error. Open the app from the main menu – Games section. Save the profile as ‘video’
I set one button to be the key ‘n’ as this advances a video on VLC to next. The second button I set as ‘esc’ and will be used to shutdown the Pi safely. I close this key as I don’t need to use it if I need to log on and make changes to the set up in the future, and if I need the esc key I can turn off the script ahead of time. The esc key is used by VLC to exit fullscreen and isn’t something we need to do in normal operation.
Write python script for shutdowns
In Terminal use :
sudo nano /home/pi/scripts/shutdown.py
use the following code :
from pynput.keyboard import Key, Listener
if key == Key.esc:
os.system("sudo shutdown -h now")
# Collect events until released
on_release=on_release) as listener:
Save by pressing ctrl+x, y, return
Set the script, video and qjoypad to run at boot
in Terminal still, use :
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
At the bottom add :
@vlc path_to_video_file --loop --fullscreen
@sudo python3 /home/pi/scripts/shutdown.py
Save by pressing ctrl+x, y, return
Our end result: A small and cheap box that when it receives power will boot up, and start playing a video on repeat. Pressing one button on our controller will move to the next video (in this case the same one) and pressing another button will initiate a safe shutdown of the Pi.
Our magic is all in the code at the end here: we run our python script which is constantly checking for the ‘esc’ key which will initiate a safe shutdown. qjoypad is listening for button presses on the controller and translating them to keyboard presses. And VLC starts up on boot. We have set the options to fullscreen and also loop.
Make sure that path_to_video_file is set correct for you – my path is /home/pi/Desktop/Segment.mov
We can do a LOT more with VLC here if we wish. Listing several video files will make a playlist on start with the videos in that order and pressing next will advance to the next one in our playlist. If you have several, you can build a playlist in the VLC GUI and save the playlist file as an mu3 file and reference that on startup also.
Here is a full list of command line arguments you could use. https://wiki.videolan.org/Documentation:Command_line/
My name is Alan. I’m based just outside Toronto, Ontario.
My background is in digital media from video editing, live event production, photo editing and programming.
I can help with developing all kinds of events, including managing live audio, video and lighting, digital media for promotions and advertising, developing merchandise, building websites and online stores, and even post-production video work.
I offer significant discounts to charities and non-profit groups.