0

I have a python script that needs to run the omxplayer after the pi is finished booting on the latest version of Raspbian whit Pixel.

I have tried the 3 different methods from the accepted answer here : Execute script on start-up

The script does execute, but the video player won't start. (Nothing appears on the screen)

If I run the script by hand, the video works. I have tried with both LXDE enabled and disabled.

How can I get omxplayer to display the video when executing after a reboot?

os.system(`killall omxplayer.bin`)
omxc = subprocess.Popen([`omxplayer`, `-b`, `dronesunset.mp4`])
ESD
  • 111
  • 1
  • 7

5 Answers5

1

You can absolutely do this without the need for a GUI desktop or logging in. I used this technique to have a RPi Zero 1.3 (no network) boot directly into omxplayer continually looping a video -- a 2 hour aquarium loop in my case. Here's how I did it using systemd:

  1. Create a file in /etc/systemd/system/omxplayer.service containing:

    [Unit]
    Description=Ambient scenery display
    Before=systemd-user-sessions.service
    
    [Service]
    TimeoutStartSec=0
    
    ExecStart=/usr/bin/omxplayer -r --loop --vol -6000 -o hdmi "/path/to/video.mp4"
    Type=simple
    User=youruser
    
    ExecStop=/usr/bin/killall omxplayer
    User=youruser
    
  2. Enable the service with sudo systemctl enable omxplayer.

The RPi should boot and launch omxplayer early in the boot process. The console is useless at this point, and the Pixel desktop inaccessible unless you add something to kill omxplayer when needed. The player runs in the background, so pressing [esc] won't exit it. If the RPi is networked, you can access it via the network normally.

Note the use of the omxplayer parameters: --vol -6000 for silent (change to suit), -r to adjust the framerate to the video, --loop to loop continuously (with a short blank between loops, unfortunately), and -o hdmi to force HDMI output.

bobstro
  • 3,978
  • 15
  • 27
1

omxplaer requires lxterminal to run, so:

In ~/.config/autostart/omxplayer.desktop:

[Desktop Entry]
Type=Application
Exec=lxterminal -l -e "omxplayer --loop --no-osd -o hdmi /home/pi/Videos/vid.mp4 > /dev/null"

Then:

reboot
sparanoid
  • 111
  • 2
0

I don't think that you can play videos without logging into an account first. However, you can create a new account with autologin to do it:

Add a new user if you don't want to put autologin on your personal account:
sudo adduser videouser

If your script needs root permissions: (skip if you are using your account)
sudo visudo

Then navigate to bottom and add/edit: (skip if you are using your account)
videouser ALL=(ALL) ALL

Once that's done, type nano ~/.bashrc (may need sudo). Go to the very bottom. Any valid bash that you put here will be run when the account has logged in:

omxplayer -b /absolute/path/to/video.mp4

otoomey
  • 166
  • 6
0

What I had to do to get it to work : instead of using .bashrc to start it, I had to :

run when booted into the LXDE environment see : Execute script on start-up

and thanks to Shreyas comment, make sure that the path to the video is absolute to prevent working directory confusion.

ESD
  • 111
  • 1
  • 7
0

Put the script in .config/lxsession/LXDE-pi/autostart

I've done something similar but with a bash script.

Kelsier
  • 11
  • 3