Ali faizan
Ali faizan

Reputation: 93

PHP exec not executing command

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;
?>

Upvotes: 4

Views: 12241

Answers (4)

Zakaria
Zakaria

Reputation: 599

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

Upvotes: 0

Kalob Taulien
Kalob Taulien

Reputation: 1918

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

Upvotes: 3

marco burrometo
marco burrometo

Reputation: 1135

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);

Upvotes: 0

Arfeen
Arfeen

Reputation: 2623

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

Upvotes: 6

Related Questions