3

If I execute a Ffmpeg command from terminal, I get the desired result:

ffmpeg  -i src.mp4 -ar 22050 -ab 32 -f flv -s 320x240 video.flv

Terminal's output:

...
video:3404kB audio:1038kB global headers:0kB muxing overhead 2.966904%

And video.flv is created correctly.

Then, if called via PHP exec:

exec("ffmpeg  -i src.mp4 -ar 22050 -ab 32 -f flv -s 320x240 video.flv", $o, $v);
var_dump($o);
var_dump($v);

The output is this:

array(0) { } int(1)

And no file is created. Any thoughts on how to approach this?

I can exec('whoami') with no problems and I have used the FFmpeg full path as well: /usr/local/bin/ffmpeg

3
  • Maybe exec() only captures stdout in output, not stderr. Commented Mar 24, 2012 at 17:29
  • FFmpeg produces very weird output — you have to redirect both stdout and stderr to get everything AFAIK.
    – slhck
    Commented Mar 24, 2012 at 17:32
  • I do not get the desired flv file created, so something is def. not working. Definitively the most urgent matter at this point ;)
    – goliatone
    Commented Mar 24, 2012 at 17:34

5 Answers 5

3

The problem is that you use exec instead of shell_exec the point is that environement of exec don't know about any FFmpeg executable, but shell_exec* does, becuase it uses env. of the bash/shell

Ths solution is to use the full path to FFmpeg executable, eg. /usr/bin/ffmpeg

3
  • No, the user said they tried /usr/local/bin/ffmpeg as well.
    – slhck
    Commented Jul 17, 2012 at 15:02
  • 2
    we had same issue half year ago, solution, described above, solved the problem, what about "/usr/local/bin/ffmpeg", maybe - bin folder is not correct !?.. Commented Jul 17, 2012 at 15:05
  • exec with full path /usr/local/bin/ffmpeg worked for me, i found the path using which ffmpeg Commented Jul 5, 2020 at 21:47
1

add 2>&1 to the end of the command and it will work:

exec("ffmpeg  -i src.mp4 -ar 22050 -ab 32 -f flv -s 320x240 video.flv 2>&1", $o, $v);
0

In addition to using the full path for ffmpeg, use /full/path/to/src.mp4 and /full/path/to/video.flv

0

I has the same problem, first make sure that the ffmpeg.exe or directory is in the windows path, then restart your apache server to ensure that php found the ffmpeg command. After this i can use ffmpeg with both options exec and shell_exec

0

In my case, due to using root user to create the folder, the php user didn't have write permission. Giving it write permission worked. For some reason I wasn't getting any output with shell_exec but the following shows everything and finds the ffmpeg binaries for you.

<?php
$dir = __DIR__;

//Find ffmpeg binaries
$ffmpeg =trim(shell_exec("which ffmpeg"));

//resize input.png to 120px width
$command = "$ffmpeg -i '$dir/input.png' -vf scale=120:-1 '$dir/output.png'";
echo $command . "<br>";

//run command and output streams to vars
exec("$command 2>&1", $o, $v);

echo "<pre>";
print_r($o);
print_r($v);
echo "</pre>";

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .