4

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;
?>
8
  • My first guess is there is permission issue. Can you put your code here and the output of executing the command through exec Commented Sep 4, 2013 at 7:50
  • Yep, exec command issues are almost always permission problems. Commented Sep 4, 2013 at 7:54
  • @rakeshjain i Have included my php code and i have tried to get the output but it is not giving any result. check my code i have edited it. Commented Sep 4, 2013 at 7:59
  • you didn't get anything in $out array? Commented Sep 4, 2013 at 8:04
  • no its just printing 'Array' nothing else Commented Sep 4, 2013 at 8:06

4 Answers 4

6

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

Sign up to request clarification or add additional context in comments.

2 Comments

@Alifaizan Have you put the correct path since the one I gave you is just an example.
su www-data or whatever your apache user is and try to run ffmpeg from ssh it maybe a permission issue.
3

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

1 Comment

Dude you saved me a lot of headaches :D that worked for me on Ubuntu 18.04. I tried different options, but nothing worked until this.
0

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

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.