Quickly dispatching between `fbi` and `omxplayer`

179 Views Asked by At

I have a script running on a RaspberryPi Zero, which is waiting for the press of a button to then display a video through HDMI:

  1. Script is waiting and displaying an the waiting image
  2. The button is pressed and a loading-video image is shown
  3. As soon as the video is loaded using omxplayer the loading-video image is "overwritten" with the video playback.
  4. When the video is over the loading-video image is shown for another 500ms before
  5. The waiting image is shown again.

Loading the video takes several seconds to the point where it's almost unusable. So feel of this application is quite slow and I'm looking for an option to A preload the video in another process that is then somehow activated. B detect the video playback so I can in the background already switch to the waiting image.

Maybe screen could be used to preload the video in paused mode, but as soon as the omxplayer is started it takes over the screen. I'm very glad for any help on this.

Here is my code (also on github):

wait.py

from gpiozero import LED, Button
from signal import pause
import subprocess

button = Button(21)


subprocess.call(['sudo', 'bin/show_waiting.sh'])


def pressed():
    print("pressed")
    subprocess.call(['sudo', 'bin/show_loading.sh'])
    subprocess.call(['omxplayer', 'assets/video.mp4'])
    subprocess.call(['sudo', 'bin/show_waiting.sh'])

button.when_pressed = pressed

pause()

bin/show_loading.sh

killall -TERM fbi
fbi -T 1 assets/loading.jpg -a -noverbose

bin/show_waiting.sh

killall -TERM fbi
fbi -T 1 assets/waiting.jpg -a -noverbose

enter image description here

0

There are 0 best solutions below