Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP exec not executing command

Tags:

php

exec

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 mode is off. please help me to get it solved. my php code is

<?php
$output=exec("ffmpeg -f image2 -i /home/phedra/imgs/image/img%03d.png -r 12 -s 610x489 /home/phedra/imgs/video/out.avi", $out);
echo $out;
echo $output;
?>
like image 296
Ali faizan Avatar asked Feb 16 '23 09:02

Ali faizan


2 Answers

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".

like image 70
Arfeen Avatar answered Feb 24 '23 18:02

Arfeen


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

like image 35
Kalob Taulien Avatar answered Feb 24 '23 17:02

Kalob Taulien