atomic3
Posts: 99
Joined: Thu Jan 17, 2013 4:31 pm

Run omxplayer from PHP

Sat Jan 26, 2013 5:13 am

So I want to play my movies from the web instead of using SSH as I am currently.

I've tried creating a bash file that gets called by PHP shell_exec and for some reason it's not working. Also tried putting in the entire omxplayer string into the shell_exec() and still no luck. Can anyone help me with this?

I am using wheezy if that matters with apache and php5.

Thank you.

atomic3
Posts: 99
Joined: Thu Jan 17, 2013 4:31 pm

Re: Run omxplayer from PHP

Thu Jan 31, 2013 4:42 pm

I found some info that says I should use pipes but it doesn't work for me.

When I create mkfifo and do command omxplayer -o path/to/video > /home/pi/fifo_file nothing happens on the screen.

Anything wrong I may be doing?

Thanks.

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: Run omxplayer from PHP

Thu Jan 31, 2013 5:31 pm

You would use pipes or fifo files to communicate between processes through the stdin&stdout - you could send command to omxplayer from your php script, provided that it accepts commands from stdin and sends meaningful info to stdout... basically the command should be something along: 'commands_in | omxplayer ... > info_out' (where commands_in would be a (fifo) file you feed your command to omxplayer and info_out is the player output you then read. In your example above, you just redirect the omxplayer output to the fifo file, but are you reading from it?

If you just want to start the player without further control, you should be able to do it with the shell_exec() - possibly need to add the path to omxplayer and most likely run it in the background? So '/path/to/omxplayer <params> /path/to/videofile &'

You could try to narrow down the issue by running a script that writes something to a debug file:

Code: Select all

#!/bin/bash
echo Testing >/home/pi/test.log
...and make your PHP script to exec that.
Then (re-)create a shell script for running the omxplayer:

Code: Select all

#!/bin/bash
omxplayer ... >/home/pi/test.log
...and check if any errors output into the file ...I assume your server does some sort of logging as well?
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: Run omxplayer from PHP

Fri Feb 01, 2013 1:52 pm

Hmm, one thing popped to my head... Could this (too) be the case of permissions? Does the omxplayer require some special permission (maybe 'video' group)? Might want to try adding the user the PHP server runs on to the video group...
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

atomic3
Posts: 99
Joined: Thu Jan 17, 2013 4:31 pm

Re: Run omxplayer from PHP

Fri Feb 01, 2013 11:31 pm

Thanks, that has been very helpful I will try this when I get home.

At this current stage I just want to start the movie, create a sort of movie database. Later I plan on expanding the concept to a web player.

Again thank you.

atomic3
Posts: 99
Joined: Thu Jan 17, 2013 4:31 pm

Re: Run omxplayer from PHP

Sat Feb 02, 2013 6:31 pm

Ok, so still no luck,

when I run omxplayer from php this is the output I get on the webpage

Code: Select all

* failed to open vchiq instance
If this is the case with special permissions, how do I see what user is php using?

Just in case my movie and the directory is set to 777.

thanks.

atomic3
Posts: 99
Joined: Thu Jan 17, 2013 4:31 pm

Re: Run omxplayer from PHP

Sat Feb 02, 2013 7:15 pm

You were right, it was the permissions.

What I did was create a test php file with the following command:

Code: Select all

<?php echo shell_exec('whoami');
which gave me the user www-data.

I went into /etc/apache2/envvars and changed the user to pi. Restarted apache service and now I am able to execute omxplayer. Not sure if I went about this the correct way, maybe I should have just added www-data to allow and run omxplayer but this is my current setup.

Next I'd like to test out my mkfifo and see if I can control the player from the web :).

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: Run omxplayer from PHP

Mon Feb 04, 2013 11:42 am

If you open up your RPi server to the internet, there may be some security concerns - but if you only use it within your home network, it should be fine. In general it would be better to find which permission (group) it needs to run and add the group to the user ('add user to the group' would sound more logical to me) - for example, if the required permission is 'video':

Code: Select all

useradd -G video www-data
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

Return to “General programming discussion”