Search code examples
phpmacosffmpegmampphp-extension

FFMPEG command doesn't work in PHP. (Incompatibilty with MAMP)


I'm a bit of a beginner when it comes to PHP, and I'm trying to create a simple(ish) system where files are input, and then converted to html5 video in various resolutions.

I've sorted out how to handle multiple file uploads etc, but now I'm having a problem.

I can't seem to get exec to execute FFMPEG in PHP.

For example, if I type this into my command line (Terminal on Mac OSX 10.8), It converts the video correctly:

ffmpeg -i /Users/charlieryan/Desktop/MOV01785.MPG websample.mov

This correctly outputs the converted video file into my home directory.

However if I run this in PHP as follows:

exec('ffmpeg -i /Users/charlieryan/Desktop/MOV01785.MPG websample.mov');

Absolutely nothing happens ... my stat monitor doesn't register any change in processor use, and I can't find the output file anywhere on my system.

Since I'm a bit of a noob at this, I'm assuming I'm doing something wrong, but what is it?

Thanks,

Charlie


Solution

  • After alot of help from birgire and a lot of fiddling around I've sorted it.

    This problem comes from an incompatibility with the MAMP sandbox. Which can be solved as follows:

    Go to Terminal and type:

    sudo nano /Applications/MAMP/Library/bin/envvars
    

    Then comment out the following lines with a hash (#)

    # DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
    # export DYLD_LIBRARY_PATH
    

    And then add the following line to the file

    export PATH="$PATH:/opt/local/bin"
    

    Then, go back to MAMP and restart your servers, navigate back to the page, and you'll be good to go.