‹ USB Soundcards Modunder the hood changes 2 ›

Cheap 4-channel Videoplayer

2013-07-30 00:18:16 visuals

For the dance piece Ich(a) by Zufit Simon I constructed a system with four Raspberry Pi mini-computers and buttons to trigger playback of four video streams. As the videos didn't need to run in exact frame-by-frame sync, this was a very cheap way to get four channel high-quality video playback. Total cost was about (RPi 28 * 4) + (SD card 6 * 4) + (5V power 1 * 7) ≈ 141 Euro. I chose the model A of the Raspberry Pi to keep the cost and power consumption down. The four computers share a 5V power supply of 2 amps and are powered over the GPIO pins. Video cables run 50 meters down to the stage and into separate flat-screen monitors. The monitors are built into boxes that can be piled up or rolled around independently.

The videos are stored on the 4 GB SD cards that also holds the Linux operating system. I converted the videos from DVD to MP4 using ffmpeg with the following settings...

ffmpeg -i concat:"/Volumes/MONITOR01_may2012_DVD/VIDEO_TS/VTS_01_1.VOB|/Volumes/MONITOR01_may2012_DVD/VIDEO_TS/VTS_01_2.VOB" -an -vcodec libx264 -profile:v high -preset fast -crf 18 -b-pyramid none -f mp4 MONITOR01_may2012.mp4

That'll take two chapters and convert to a single MP4 and skip the audio track (-an flag).

The Python program running on each computer is here below. It plays a video to the end and waits for a button trigger. If a button is pressed before the video is finished, it'll stop and jump to the next video - all in a cyclic fashion.

#f0videoplayer.py
#for a Raspberry Pi running Raspbian
#this script will cycle through videos in sequence when a GPIO pin is grounded

#pinSwi (pulled up internally) - GND this pin to switch to the next video
#pinOff (pulled up internally) - GND this to shut down the system

#--settings
videos= ['/home/pi/ICHA1.mp4', '/home/pi/MONITOR01_may2012.mp4', '/home/pi/BLACK.mp4', '/home/pi/FLESH.mp4', '/home/pi/TESTBILDER.mp4']
delays= [0, 0, 0, 0, 0]  #extra start delay time in seconds - one value for each video
pinSwi= 23
pinOff= 24

#--
import pexpect
from time import sleep
import RPi.GPIO as GPIO
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(pinSwi, GPIO.IN, pull_up_down= GPIO.PUD_UP)
GPIO.setup(pinOff, GPIO.IN, pull_up_down= GPIO.PUD_UP)

def main():
  os.system("clear && tput civis")  #clear and hide cursor
  index= 0  #keeps track of which video to play
  while True:
    sleep(delays[index])
    omx= pexpect.spawn('/usr/bin/omxplayer -rp '+videos[index])
    omx.expect('Video')  #play
    while(GPIO.input(pinSwi)==True):
      sleep(0.1)
      if GPIO.input(pinOff)==False:
        omx.send('q')  #quit
        os.system("tput cnorm && sudo halt")
        exit()
    omx.send('q')  #quit
    sleep(0.5)  #safety
    while(GPIO.input(pinSwi)==False):
      sleep(0.01)
    index= (index+1)%len(videos)

if __name__ == "__main__":
  main()

Instructions for installing

(you'll need a model B to prepare an SD card, but then move it over to the model A Raspberry Pi)

prepare the RPi

  • use Pi Filler to transfer 2013-05-25-wheezy-raspbian.img to the SD card
  • put the SD card in RPi model B
  • select 'Expand Filesystem' in and enable SSH under advanced in config menu
  • select 'Finish' and reboot
  • log in with pi/raspberry
  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get install python-pexpect avahi-daemon

copy files from macOS

  • open a terminal window on the main computer
  • cd to folder with videos
  • edit the file f0videoplayer.py and select which videos to use
  • optionally add delay times if some videos should start later
  • scp f0videoplayer.py MONITOR01_may2012.mp4 ICHA1.mp4 BLACK.mp4 FLESH.mp4 TESTBILDER.mp4 pi@raspberrypi.local:/home/pi/

back to model B

  • sudo pico /etc/rc.local
  • add the following before the exit line: (sleep 1; python /home/pi/f0videoplayer.py) & # autostart video player
  • press ctrl+o to save and ctrl+x to exit
  • sudo halt

start model A

  • take out the SD card from model B and put it in model A
  • connect HDMI or composite video, GPIO pins and apply power - the first video should start
  • ground pin 23 to cycle through the videos
  • ground pin 24 to turn off the computer

Useful commands

(connect a keyboard to RPi model A, type pi/raspberry to log in)

sudo pkill omxplayer.bin #might need to write this without the terminal being visible

if you get "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!"

ssh-keygen -R raspberrypi.local     #useful for resetting ssh/scp after changing SD cards

It's not pretty but it's working. Some day I'll build it into a real rackmount box.

f0videoplayer photo

References

www.raspberrypi-spy.co.uk/2013/06/playing-videos-on-the-raspberry-pi-command-line

www.raspberrypi.org/phpBB3/viewtopic.php?f=38&t=47520

‹ USB Soundcards Modunder the hood changes 2 ›