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
  • 1
    Can you try passing the full path to the mp4 file ? maybe its a issue of wrong working directory ... also noticed the first line says osxplayer.bin. i am assuming you mean omxplayer.bin (note the 's' instead of 'm') – Shreyas Murali May 26 '17 at 18:42
  • good catch for the path! I changed it to absolute path and still same behavior. Works when launching manually, but not on login. the osxplayer was just a typo when I wrote the question. – ESD May 26 '17 at 18:58

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,998
  • 14
  • 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
  • I'm working on an app that runs on boot instead of desktop environment (fullscreen app that is the only purpose of this RPi), and I couldn't get video playing from there. I just edited .xsessionrc and replaced exec /path/to/myapp with exec lxterminal -e /path/to/myapp and everything runs fine. Thanks ! – psycho Feb 09 '20 at 22:15
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
  • 5
  • One of the methods I tried to auto-start the script waits for the pi to auto-login into the user pi. – ESD May 26 '17 at 16:55
  • What exactly did you try? To help you further we need more info. Can you show us the exact command you are using to launch your python script? – otoomey May 26 '17 at 16:58
  • In my original question I state that I tried all the methods of the accepted answer with a link... – ESD May 26 '17 at 16:58
  • What command did you add to your bashrc file? Because if you are using the same one as from the link then it might not work, because he's trying to launch a browser and you're trying to launch a python script. – otoomey May 26 '17 at 17:02
  • python /absolute/path/to/script.py and in my python script there are the lines I posted in my question. – ESD May 26 '17 at 17:03
  • Ok, where is your python script on your system? – otoomey May 26 '17 at 17:04
  • /home/pi/DustBuster/DustBuster.py and the user that auto login is pi. The script and the video works perfectly when I run then in terminal with user pi using the same command than in the bashrc. – ESD May 26 '17 at 17:05
  • And where is your python installation? – otoomey May 26 '17 at 17:06
  • it's the default python installation from rasbpian. The script and the video works perfectly when I run them in terminal with user pi using the same command than in the bashrc. – ESD May 26 '17 at 17:06
  • Please see my updated answer – otoomey May 26 '17 at 17:10
  • I appreciate that you are trying to help me, but please read my question! The script runs when auto starting(I can make python do stuff)! It's the omxplayer that is not displaying the video. – ESD May 26 '17 at 17:13
  • Sorry, you're right. Try using -o HDMI flag when running your video. That will force it to use the HDMI output. – otoomey May 26 '17 at 17:15
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