tags:

views:

735

answers:

5

Hello all,

I'm attempting to run the following command in PHP (on Ubuntu):

<?php
 if (exec("/home/johnboy/ffmpeg/ffmpeg -i test1.mp4 -acodec aac -ab 128kb -vcodec mpeg4 -b 1220kb -mbd 1 -s 320x180 final_video.mov")) 
      { echo "Success"; }
      else { echo "No good"; }

And I always get "No good" echoed back, and no file created.

Interestingly, if I run the same exact command in Shell, it works, no problems.

Also, when I run the same code above, but subsitute "whoami" instead of the ffmpeg stuff, it works. (It echoes back "Success")

Any ideas on why this wouldn't be working? Thanks.

A: 

You are using relative paths to the file names. Are you sure you are executing the command in the right directory?

Lukáš Lalinský
Yes, because in shell, I cd to /var/www (the location of the php file) and execute the command there. As a result, it successfully creates the final_video.mov in the director /var/www/
Dodinas
+1  A: 

Can the apache/web user reach /home/johnboy/ffmpeg/ffmpeg? That is, perhaps /home/johnboy is 0700 instead of 0755?

Perhaps there are resource limits affecting loading of such a large program and all its libraries?

If you run the script to the php cli sapi, does it behave correctly? Even when running as the apache user?

What does strace -ff show when the apache web user runs the php script through the php cli?

geocar
Thanks for your reply. Do I made sure that ffmpeg and johnboy were chmod at 755. Also, I ran the php test.php command from shell, and it worked fine. So I know the script works. It just won't run from the web browser. I'm not sure what strace -ff is, or where I'd need to run it?
Dodinas
@Dodinas : you would write strace -ff php file.php > log.txt 2> check your apache error log.
geocar
@Dodinas : Does apache have write access to the /var/www directory?
geocar
A: 

The function exec() only returns the last line of output, I suspect that the last line of that command is blank. if you want the entire contents of the command you should use shell_exec().

Also keep track of where the command is executing, try: print(shell_exec("pwd"));

Rook
+1  A: 

There would be some issues if you want to execute something that way.
1. Maybe you have some permission issue, the webserver have limitation to handle some execution to the system.
2. Maybe your path file is incorrect.
3. you can try to use shell_exec to perform the execution to the system.

Anyway, what I would do to make my execution would go smoothly are, I will write 2 programs with message passing included between them, for example client server program. The server would wait some messages from the client to execute some command (all of the command, it would be no permission issues). All you have to do in you web is to call your client application.

What I emphasize is to build some interface from web and the system. It would solve a lot of problem with permission issues.

hope this help.

deddihp
A: 

get the stderr will give the result

try ffmpeg -i inputfile [more_params] 2>&1