I'm trying to execute ffmpeg from PHP using shell_exec or exec but it fails. Why can this be? The command /usr/bin/ffmpeg
works from the terminal, so I tried
<?php
$cmd = "/usr/bin/ffmpeg";
exec($cmd." 2>&1", $out, $ret);
if ($ret){
echo "There was a problem!\n";
print_r($out);
}else{
echo "Everything went better than expected!\n";
}
?>
and I keep on getting
There was a problem! Array ( [0] => sh: /usr/bin/ffmpeg: not found )
Any help would be greatly appreciated.
Permission on the executable are
-rwxr-xr-x 1 root root 106552 Jun 12 09:53 ffmpeg
Running which /usr/local/bin/ffmpeg
into $cmd returns an empty Array.
The answer to your question might be simpler than expected. You're checking in both /usr/local/bin
and /usr/bin
. There are multiple solutions to this.
You can run $ whereis ffmpeg
and see what you get. Based on the results, change your $cmd
variable. If whereis
returns nothing, then your system doesn't know where it is. You can add it to your $PATH
environment variable and try again.
You can try to run $ find /usr -name "ffmpeg"
or something similar. By ensuring that this program is installed, it will help you resolve this quicker.
If there is some sort of restriction denying apache the ability to access/use ffmpeg, you can always store it in a bin folder within your document root. (something like /path/to/doc/root/bin/ffmpeg ) I have done this before so I know it works.
If you find that ffmpeg is actually located in /usr/local/bin
then you should just try changing your $cmd
to this:
$cmd = '/usr/local/bin/ffmpeg';
There was a problem!
Array (
[0] => FFmpeg version 0.6.5, Copyright (c) 2000-2010 the FFmpeg developers
[1] => built on Jan 29 2012 17:52:15 with gcc 4.4.5 20110214 (Red Hat 4.4.5-6)
[2] => configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64
--mandir=/usr/share/man --incdir=/usr/include --disable-avisynth
--extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions
-fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC'
--enable-avfilter --enable-avfilter-lavf --enable-libdc1394 --enable-libdirac
--enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm
--enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb
--enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora
--enable-libx264 --enable-gpl --enable-nonfree --enable-postproc --enable-pthreads
--enable-shared --enable-swscale --enable-vdpau --enable-version3 --enable-x11grab
[3] => libavutil 50.15. 1 / 50.15. 1
[4] => libavcodec 52.72. 2 / 52.72. 2
[5] => libavformat 52.64. 2 / 52.64. 2
[6] => libavdevice 52. 2. 0 / 52. 2. 0
[7] => libavfilter 1.19. 0 / 1.19. 0
[8] => libswscale 0.11. 0 / 0.11. 0
[9] => libpostproc 51. 2. 0 / 51. 2. 0
[10] => Use -h to get full help or, even better, run 'man ffmpeg'
[11] => Hyper fast Audio and Video encoder
[12] => usage: ffmpeg [options] [[infile options] -i infile]...
{[outfile options] outfile}...
[13] =>
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.