PHP exec() Not Working With ffmpeg

21,882

Solution 1

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?

Solution 2

get the stderr will give the result

try

ffmpeg -i inputfile [more_params] 2>&1

Solution 3

Use this

$ffmpeg = "ffmpeg Installed path";
$flvfile = "source video file with root path";
$png_path " "Destination video file with root path and file type";


exec("$ffmpeg -y -i $flvfile -vframes 1 -ss 00:01:60 
     -an -vcodec png -f rawvideo -s 110x90 $png_path");

Solution 4

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.

Solution 5

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

Share:
21,882
Dodinas
Author by

Dodinas

Updated on July 29, 2020

Comments

  • Dodinas
    Dodinas almost 4 years

    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.

  • Dodinas
    Dodinas about 14 years
    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
    Dodinas about 14 years
    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?
  • geocar
    geocar about 14 years
    @Dodinas : you would write strace -ff php file.php > log.txt 2>&1 and upload that log someplace (after looking at it carefully) Also, if php is in safe mode when run from apache, the script might not run; check your apache error log.
  • geocar
    geocar about 14 years
    @Dodinas : Does apache have write access to the /var/www directory?
  • keji
    keji over 10 years
    funny I get an array from exec