7

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.

Rio
  • 14,182
  • 21
  • 67
  • 107

2 Answers2

7

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.

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

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

  3. 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';
Yes Barry
  • 9,514
  • 5
  • 50
  • 69
  • 2
    Yeah, I ended up making a copy of ffmpeg and storing it in my own local folder. I think it was what you said with 3. – Rio Nov 07 '12 at 04:18
  • @Rio indeed. Sometimes (depending on your server/hosting env) it's just much easier to do that. It's the exact same reason I did it that way. I am glad you got this resolved though! Question: Did you call it using a full absolute path or relative path? – Yes Barry Nov 07 '12 at 04:19
-2

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] =>
)
davejal
  • 6,009
  • 10
  • 39
  • 82
  • 1
    Is this an answer or a question? This is the place for answers. If you tried this solution and it did not work for you, you may open another question with a good description of your problem. – havakok Feb 11 '20 at 14:35