FFmpeg works on terminal not with PHP exec

15,707

Solution 1

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

Solution 2

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);
Share:
15,707

Related videos on Youtube

InziKhan
Author by

InziKhan

Updated on September 18, 2022

Comments

  • InziKhan
    InziKhan almost 2 years

    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

    • Oliver Salzburg
      Oliver Salzburg over 12 years
      Maybe exec() only captures stdout in output, not stderr.
    • slhck
      slhck over 12 years
      FFmpeg produces very weird output — you have to redirect both stdout and stderr to get everything AFAIK.
  • slhck
    slhck almost 12 years
    No, the user said they tried /usr/local/bin/ffmpeg as well.
  • Rodislav Moldovan
    Rodislav Moldovan almost 12 years
    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 !?..
  • Rishiraj Purohit
    Rishiraj Purohit almost 4 years
    exec with full path /usr/local/bin/ffmpeg worked for me, i found the path using which ffmpeg