Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

FFmpeg works on terminal not with PHP exec

Writer Matthew Harrington

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

4 Answers

The problem is that you use exec instead of shell_execthe 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

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

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

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy