Skip to content

Instantly share code, notes, and snippets.

@ryanlong1004
Created March 6, 2025 17:59
Show Gist options
  • Save ryanlong1004/3aa85c9d155a8ad112bb17843323f9ce to your computer and use it in GitHub Desktop.
Save ryanlong1004/3aa85c9d155a8ad112bb17843323f9ce to your computer and use it in GitHub Desktop.
Pi Zero Video Loop on Boot

Install libraries

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install omxplayer (this can take about 10 minutes..)
sudo apt-get install screen

Create Bash Script

— Create a file called videoloop in the /etc/init.ddirectory: sudo nano /etc/init.d/videoloop — Copypaste the content for the script below — Change the permissions of the script to allow writing and execution: sudo chmod 755 /etc/init.d/videoloop

Run the following commands

— Start the video loop: /etc/init.d/videoloop start — Close the video loop: /etc/init.d/videoloop stop — Re-open the video loop if it closes: /etc/init.d/videoloop repair

Last step: Enable auto play whenever the Pi boots: sudo update-rc.d videoloop defaults

Now reboot your Pi to see if the video plays automatically: sudo reboot

#!/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: Starts and stops video playback in a loop using omxplayer.
### END INIT INFO

# Video file path (update accordingly)
video_path="/home/pi/video.mp4"

# Ensure screen and omxplayer exist
if ! command -v screen &>/dev/null || ! command -v omxplayer &>/dev/null; then
    echo "Error: Required packages (screen, omxplayer) are missing."
    exit 1
fi

# Start or stop video playback
case "$1" in
    start)
        echo "Starting video playback..."
        screen -dmS videoloop sh -c "omxplayer -o both '$video_path' -b --loop --no-osd"
        echo "Video playback started."
        ;;
    
    stop)
        echo "Stopping video playback..."
        screen -S videoloop -X quit
        sudo killall omxplayer.bin 2>/dev/null
        echo "Video playback stopped."
        ;;
    
    *)
        echo "Usage: $0 {start|stop}"
        exit 1
        ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment