Created
August 4, 2023 13:47
-
-
Save esnho/5df5f0752c787a14ef2a50f70a08f8fa to your computer and use it in GitHub Desktop.
Configure Raspberry PI to loop a video
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Raspberry PI 3B | |
# OS Version: Debian Buster (Raspberry PI OS Legacy) | |
# Configure your PI then open a terminal | |
# here you should set your preferences, I usually start HDMI in safe mode | |
sudo nano /boot/config.txt | |
# paste below script in videoloop file, source: https://community.spiceworks.com/how_to/135908-loop-a-single-video-on-a-raspberry-pi | |
sudo nano /etc/init.d/videoloop | |
##### SCRIPT START ##### | |
#!/bin/bash | |
### BEGIN INIT INFO | |
# Provides: omxplayer | |
# Required-Start: | |
# Required-Stop: | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Displays video file in a loop using omxplayer | |
# Description: https://community.spiceworks.com/how_to/135908-loop-a-single-video-on-a-raspberry-pi | |
### END INIT INFO | |
# Video (replace with the path and file name of your video) | |
video_path=/media/pi/USBKEY/output.mp4 | |
#---- There should be no need to edit anything below this line ---- | |
# Start displaying the video loop | |
case "$1" in start) | |
screen -dmS videoloop sh -c "omxplayer -o both $video_path -b --loop --no-osd" | |
echo "Video Playback Started" | |
;; | |
# Stop displaying video loop | |
stop) | |
sudo killall omxplayer.bin | |
echo "Video Playback Stopped" | |
;; | |
# Restart video loop if it died | |
repair) | |
if !(ps -a | grep omx -q) | |
then | |
screen -dmS videoloop sh -c "omxplayer -o local $video_path -b --loop --no-osd" | |
echo "The Video is now running" | |
fi | |
;; | |
*) | |
echo "Usage: /etc/init.d/videoloop {start|stop|repair}" | |
exit 1 | |
;; | |
esac | |
##### SCRIPT END ##### | |
# make the script executable | |
sudo chmod 755 /etc/init.d/videoloop | |
# setup a cronjob to restore the video if there's any problem | |
crontab -e | |
##### CRON LINE ##### | |
*/4 * * * * /etc/init.d/videoloop repair | |
##### EO CRON LINE ##### | |
# I increase GPU memory to 128 here | |
sudo raspi-config | |
# Update the system and install omxplayer and screen (used by the script) | |
sudo apt update | |
sudo apt upgrade | |
sudo apt install omxplayer | |
sudo apt-get install screen | |
# Autostart the video, add below lines before "exit 0" | |
sudo nano /etc/rc.local | |
##### RC CONFIG ##### | |
sleep 10 | |
/etc/init.d/videoloop repair | |
##### EO RC CONFIG ##### | |
# reboot ;) | |
sudo reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment