PHP exec not executing command

前端 未结 4 1287
故里飘歌
故里飘歌 2021-01-06 09:21

I have used php\'s exec to execute FFmpeg command but its not woking when I open it in browser. But when i run this php file script in terminal it works fine.And my php safe

相关标签:
4条回答
  • 2021-01-06 10:04

    try giving full path where the ffmpeg application is located.

    e.g.

    /usr/bin/ffmpeg
    

    So your function might look like:

    $output=exec("/usr/bin/ffmpeg -f image2 -i /home/phedra/imgs/image/img%03d.png -r 12 -s 610x489 /home/phedra/imgs/video/out.avi", $out);
    

    You must check what is the location of "ffmpeg".

    0 讨论(0)
  • 2021-01-06 10:13

    I had this problem and it turned out it was Apache's permission on the public directory.

    Note: I am running Ubuntu 14 on AWS

    After installing FFmpeg I had to change the /var/www/* ownership to www-data.

    sudo chown -R www-data:root /var/www
    

    (the www-data is the important part here)

    Then I had the following code running, and it works when I access it via URL (Apache)

    // test.php
    
    $run = system("/opt/ffmpeg/bin/ffmpeg -i /var/www/html/input.mp4 -vf scale=640:480 /var/www/html/output.mp4 &");
    
    if($run) {
        echo "success";
    } else {
        echo "failed";
    }
    

    The /opt/ffmpeg/bin/ffmpeg is where my FFmpeg is running from. Yours might be /usr/bin/ffmpeg or something else. You can locate it by typing locate ffmpeg in the command line and looking through the list it gives you.

    The input file was a public .mp4 file and the output.mp4 file was going to the same location.

    Run this in your command line: php test.php - works Run this from your browser: yourwebsite.com/test.php - works

    0 讨论(0)
  • 2021-01-06 10:17

    Note that if you are on windows you must use COMMAS. I.E:

    $output=exec('"/usr/bin/ffmpeg" -f image2 -i /home/phedra/imgs/image/img%03d.png -r 12 -s 610x489 /home/phedra/imgs/video/out.avi', $out);
    
    0 讨论(0)
  • 2021-01-06 10:22

    Like @Arfeen mentioned in his answer, you should execute the command with the path of ffmpeg, but, the given path in the answer "/usr/bin/ffmpeg" is not always the same.

    First locate your ffmpeg by using the command :

    which ffmpeg
    

    The result in my case is :

    /usr/local/bin/ffmpeg

    Then go back to your php code and replace "ffmpeg" in the command by the path of ffmpeg (which is /usr/local/bin/ffmpeg in my case).

    0 讨论(0)
提交回复
热议问题