Clay Chaplin
  • Home
  • Bio
  • Calendar
  • Blog
  • Artist Statement
  • Audio Engineering

Raspberry Pi – Gallery Video Player

  • February 16, 2014
  • Raspberry Pi

This tutorial will turn your Raspberry Pi into a simple video player. The Raspberry Pi will automatically begin playing a folder of video files when it starts. The files in the folder will randomly repeat until the script is stopped or the Pi is turned off. To see a demonstration video please go here.The following instructions assume you are logged in to your Pi from a remote computer.

Create a folder and copy video files to your Pi

To create a new folder named videos for your video files type:

mkdir videos

To move into the newly created videos directory type:

cd videos

Open a new “local” terminal window. You’ll run the next command on the “local” terminal and not the terminal window connected to your Pi
To copy a folder of video files from your laptop’s desktop to your Pi type :

scp /Users/[your username]/Desktop/[folder name>]/* pi@[your Pi's ip address]:/home/pi/videos

The command looked like this on my computer:

scp /Users/dwingus/Desktop/vids/* pi@10.0.1.9:/home/pi/videos

Type your Pi’s password, press return and wait for videos to transfer. The next step is to create a shell script using the nano text editor.

Shell Script to play videos in a folder

Log in to your Pi. and type:

sudo nano playseries

Copy the following into the Nano text editor:

#!/bin/bash
if [ x"$1" = x"help" -o x"$1" = x"--help" -o x"$1" = x"-help" ];then
echo "Usage: playseries [folder path]"
echo "Audio mode can be either 'hdmi' or 'local'."
echo "Folder path is the full path to folder full of video files."
echo "This script will try to play all files in the video folder regardless of file type"
exit
fi
while true
do
for file in $2/*
do
omxplayer -o $1 $file
done
done

 

Save the script file by typing control-x
Make the script executable by typing:

sudo chmod +x playseries

Move the file to the /usr/bin folder by typing:

sudo mv playseries /usr/bin

 

Running the script

The script follows the format:

[scriptname] [audio-output] [path_to_directory]

To run the script using the HDMI audio out type:

playseries hdmi /home/pi/videos

To run the script using the local audio out type:

playseries local /home/pi/videos

Blanking the Pi's screen between video files

You'll notice when you run the script that OmxPlayer pauses between video files and there is text that is displayed on the video monitor. To eliminate the text you need to basically tell the Pi to make the screen black.
To fix this edit the file here:

sudo nano /etc/kbd/config


In the config file change "BLANK TIME" to a value of 2 and save the file
Then restart your Pi by typing:

sudo reboot

Automatic Login and Running the Script on Boot

To get your Raspberry Pi to automatically login when booted and to call the playseries script complete the following steps:
- Type:

sudo nano /etc/inittab

- Scroll to the line: #1:2345:respawn:/sbin/getty 115299 tty1 and put a # in front of it to comment out the line of code
- Add a new line underneath:

1:2345:respawn:/bin/login -f pi tty1/dev/tty1 2>&1

- Save the file. This will make your Pi automatically login when booted.
- To start the playseries script automatically on boot edit your .bash_profile file by typing:

sudo nano ~/.bash_profile

- Add the following line to the file:

playseries local /home/pi/videos

- Save the file. Commands located in the .bash_profile file will be executed when the Pi boots
- To reboot your pi type

sudo reboot

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)

Related

Tags:

© 2022 Clay Chaplin