ffmpeg-php on dreamhost shared host

Please use the server setup page to request a quote.

How to install ffmpeg-php on a dreamhost shared host under a users account

This HOWTO now includes setup instructions for the following stuff:

  • autoconf
  • LAME
  • ffmpeg
  • GD2
  • mplayer+mencoder
  • Ruby
  • flvtool2
  • libogg
  • libvorbis
  • PHP
  • ffmpeg-php

Disclaimer: Some of you might not be able to make it all work due to various reasons, that does not mean it cannot be done.

For installation assistance please also read The install prerequisites page where we list the requirements for the server setup. Clip-share, vshare, alstrasoft, social media are all scripts which we have setup successfully on Dreamhost, Bluehost, godaddy and many other shared hosting environments (as on 10May2007)

Rayzz, PHPMotion and OSTube also successfully deployed on shared hosts (as on 10August 07)

Prepare the directory
structure
mkdir bin
mkdir lib
mkdir tmp
chmod 777 tmp
chmod 775 bin
chmod 775 lib

Export some environment
variables
export TMPDIR=$HOME/tmp
export PATH=$HOME/bin:$PATH
export LD_LIBRARY_PATH=$HOME/lib:/usr/local/lib:$LD_LIBRARY_PATH
export CPATH=$HOME/include:/usr/local/include:$CPATH
export LIBRARY_PATH=$HOME/lib:/usr/local/lib:$LIBRARY_PATH
mkdir src
cd src

AUTOCONF
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.60.tar.gz
tar -zxf autoconf-2.60.tar.gz
cd autoconf-2.60
./configure "--prefix=$HOME"
make
make install

LAME

wget http://nchc.dl.sourceforge.net/sourceforge/lame/lame-3.97.tar.gz
tar -zxvf lame-3.97.tar.gz
cd lame-3.97
./configure "--prefix=$HOME" "--enable-shared"
make
make install

LIBOGG

wget http://downloads.xiph.org/releases/ogg/libogg-1.1.3.tar.gz
tar -zxf
libogg-1.1.3.tar.gz
cd libogg-1.1.3
./configure --prefix=$HOME
make
make install

LIBVORBIS

wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.1.2.tar.gz
tar -zxf libvorbis-1.1.2.tar.gz
cd libvorbis-1.1.2
./configure --prefix=$HOME
make
make install

FFMPEG

svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
cd ffmpeg/
./configure "--prefix=$HOME" "--cross-compile" "--enable-shared" "--enable-mp3lame" "--extra-cflags=-I$HOME/include" "--extra-ldflags=-L$HOME/lib"
make
make install

GD2

wget http://www.boutell.com/gd/http/gd-2.0.33.tar.gz
tar -zxf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure --prefix=$HOME
make
make install

MPlayer + Mencoder

wget http://www3.mplayerhq.hu/MPlayer/releases/codecs/essential-20061022.tar.bz2
bunzip2 essential-20061022.tar.bz2
tar -xf essential-20061022.tar
mv essential-20061022 $HOME/lib
wget http://www3.mplayerhq.hu/MPlayer/releases/MPlayer-1.0rc1.tar.bz2
bunzip2 MPlayer-1.0rc1.tar.bz2
tar -xf MPlayer-1.0rc1.tar
cd MPlayer-1.0rc1
./configure --prefix=$HOME --with-codecsdir=$HOME/lib/essential-20061022
make
make install

RUBY
cd $HOME/src
wget ftp://ftp.ruby-lang.org/pub/ruby/stable-snapshot.tar.gz
tar -zxf stable-snapshot.tar.gz
cd ruby
make distclean
./configure --prefix=$HOME
make
make install

FLVTOOL2

wget http://rubyforge.org/frs/download.php/9225/flvtool2_1.0.5_rc6.tgz
tar -zxvf flvtool2_1.0.5_rc6.tgz
cd flvtool2_1.0.5_rc6
ruby setup.rb config –prefix=$HOME
ruby setup.rb setup
ruby setup.rb install

PHP
wget http://us2.php.net/distributions/php-4.4.4.tar.bz2
bunzip2 php-4.4.4.tar.bz2
tar xf php-4.4.4.tar
cd php-4.4.4
./configure --prefix=$HOME --libdir=$HOME/lib --bindir=$HOME/bin --with-ffmpeg=$HOME
make
make install

FFMPEG-PHP
wget http://superb-east.dl.sourceforge.net/sourceforge/ffmpeg-php/ffmpeg-php-0.5.0.tbz2
bunzip2 ffmpeg-php-0.5.0.tbz2
tar -xf ffmpeg-php-0.5.0.tar
cd ffmpeg-php-0.5.0
phpize
./configure "--prefix=$HOME" "--libdir=$HOME/lib" "--bindir=$HOME/bin" "--with-ffmpeg=$HOME"
make clean
make install

Setup users environment
to use the php installed earlier

cd $HOME/lib
cp $HOME/lib/php/extensions/no-debug-non-zts-20020429/ffmpeg.so ./
cp $HOME/src/php-4.4.4/php.ini-recommended php.ini
vi php.ini (add extension= /home//lib/ffmpeg.so)</STRONG>< /STRONG>

To enable site:
cp $HOME/bin/php $HOME/cgi-bin/php.cgi

add a .htaccess with following content

AddHandler phpFive .php
Action phpFive /cgi-bin/php.cgi

You might need to also run the following

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/lib
” export LIBRARY_PATH=
$HOME/lib:$LIBRARY_PATH”
“export
CPATH=$HOME/include/:$HOME/include/lame/”

as well as put it ahead of any
call to ffmpeg in your PHP code. Please send questions through the sitecontact form
.-Imtiaz (khanimtiaz at gmail dot com)

We have got this procedure working on a variety
of shared hosts besides dreamhost. For installation assistance please also read
the install prerequisites page

73 thoughts on “ffmpeg-php on dreamhost shared host”

  1. Hello
    BIG THANKS to all of you for your information.
    I have just ONE question.

    When I hit my “test_ffmpeg.php” in my browser and I get THIS ERROR . . .

    Can’t load extension /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/ffmpeg.so

    But the .so EXISTS at /home/cooolest/lib/php/extensions/no-debug-non-zts-20060613/ffmpeg.so location!

    What’s up with that???????
    Anyone can help????

  2. Hi jigs,
    The reason that happened is because the version of ffmpeg you are using is different from what I used. Please replace –cross-compile with –enable-cross-compile to make it work

    Also if you run into similar problems run a ./configure –help to see a list of all options available.

    ffmpeg.so wont happen because the ffmpeg failed to compile to begin with and so the extension cant be built.

  3. Hi I try to install ffmpeg when i use this command “./configure –prefix=$HOME –cross-compile –enable-shared” I am getting this message Unknown option “–cross-compile”., can you tell me why i got this error? i also try to install ffmpeg-php
    after install i didnt find ffmpeg.so file i check all folder but i didnt find it anywhere. how ca i fix this?

  4. Hi Rasengan,
    You will need to tell the shell to look at the installed PHP in your home dir.
    This you can do by setting the PATH system variable.
    So if /home//bin is where you have all the binaries(php, phpize, php_config etc) then run the following:

    export PATH=/home/user/bin:$PATH

    To check run:
    which phpize

    This should return /home/user/bin/phpize

    then do the phpize etc.

    Also as listed here you will need the auto conf setup to make it all work.

    Cheers

  5. I’m having problems with the same problems with the phpize/autoconf step for FFMPEG-PHP.

    I just noticed that when I run phpize, I get this:

    [xxxxxx]$ phpize
    Configuring for:
    PHP Api Version: 20020918
    Zend Module Api No: 20020429
    Zend Extension Api No: 20050606
    Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF
    environment variable is set correctly and then rerun this script.

    But, in from phpinfo(), I get this:
    PHP API 20041225
    PHP Extension 20060613
    Zend Extension 220060519

    So, obviously, phpize is looking at the wrong version of php (I compiled php5 with FastCGI support using this: http://wiki.dreamhost.com/Advanced_PHP_configuration

    So, can anyone tell me how I can make it pick up my new php, and use it to compile ffmpeg-php? It’s the only thing I still need to get a video mod of mine working

  6. Just a few days ago i had ffmpeg-php working. then i got the bright
    idea to try to add a codec to ffmpeg. so i re-installed ffmpeg and
    then ffmpeg-php. i then noticed this error which i did NOT get before.

    Fatal error: Call to a member function togdimage() on a non-object

    $movie = new ffmpeg_movie(“testmovie.wmv”);
    $cap = $movie->getFrame(1);
    $img = $cap->togdimage();

    that is my php code. (i have also tried MANY different movie types)
    now i have figured out that all functions called from $cap return that
    error, $cap returns false, but am not sure why. i have not changed
    this code at all, yet it worked before this.

    I have the latest ffmpeg, the latest ffmpeg-php, the latest php, and
    the latest gd library installed.
    also, in an outputted phpinfo() page, it says that ffmpeg-php is
    installed correctly. i also printed out:

    get_class_methods(“ffmpeg_frame”)
    and
    get_class_methods(“ffmpeg_movie”)

    and that returns all the functions, they are all there, including
    togdimage.

    when configuring php, i have read mixed ideas. some say to use –with-
    gd, and some say –with-gd=shared. i have tried both, with no success
    with either.

    here is my configuration command for “ffmpeg” TMPDIR=”/tmp2″ ./configure –enable-libmp3lame –enable-libvorbis –disable-mmx –enable-shared

    a) if i don’t have the TMPDIR=”/tmp2″ there, it will say “Unable to
    create and execute files in /tmp. Set the TMPDIR environment
    variable to another directory and make sure that /tmp is not mounted
    noexec. Sanity test failed.”. but the /tmp2 dir does exist and is
    chmodded 7777.
    b) i have installed libOGG many times but when i have –enable-libogg
    as an option it says “Unknown option..” so i just take it out.

    and for ffmpeg-php i dont use any configuration parameters. once
    ffmpeg-php is installed, i go to “/usr/local/lib/php/extensions/no-debug-non-zts-20060613/” and copy ffmpeg.so to “/usr/local/lib/php/extensions/” (one directory up), and in my php.ini file i have:

    extension_dir = “/usr/local/lib/php/extensions/”
    extension=ffmpeg.so

    in my phpinfo(), it DOES recognize ffmpeg-php. but the functions out
    of the class wont work.

    Can anyone further help me debug this problem?

  7. hey – you are a genius! this is brilliant, i have it working on bluehost, kind of…

    i want to script the conversion of .amr to .mp3s using shell scripts.

    have found that i do need to export the environment variables to avoid error executing ffmpeg.

    however when i script this it doesn’t seem to have any effect. If you could help i’d really appreciate it – i have a .sh file which has been chmod 755ed and in it is:

    #!/bin/bash

    export TMPDIR=$HOME/tmp
    export PATH=$HOME/bin:$PATH
    export LD_LIBRARY_PATH=$HOME/lib:/usr/local/lib:$LD_LIBRARY_PATH
    export CPATH=$HOME/include:/usr/local/include:$CPATH
    export LIBRARY_PATH=$HOME/lib:/usr/local/lib:$LIBRARY_PATH

    as i say, when i execute is i get no output to screen and ffmpeg still doesn’t work…

    thanks again…

    nick

  8. I followed instruction and it is terrific.

    I used this to configure,

    ./configure “–prefix=$HOME” “–cross-compile” “–enable-shared” “–enable-libamr-nb” “–enable-libamr-wb” “–enable-libmp3lame” “–enable-libvorbis” “–enable-libxvid” “–extra-cflags=-I$HOME/include” “–extra-ldflags=-L$HOME/lib” “–enable-gpl” “–enable-nonfree”

    and make / make install runs smoothly.

    But when I use this command
    ffmpeg -i source target.flv to convert movie, I met this error:

    Compiler did not align stack variables. Libavcodec has been miscompiled
    and may be very slow or crash. This is not a bug in libavcodec,
    but in the compiler. You may try recompiling using gcc >= 4.2.
    Do not report crashes to FFmpeg developers.
    Input #0, mpeg, from ‘MOV01615.MPG’:
    Duration: 00:01:07.2, start: 0.110000, bitrate: 2913 kb/s
    Stream #0.0[0x1c0]: Audio: mp2, 32000 Hz, mono, 64 kb/s
    Stream #0.1[0x1e0]: Video: mpeg1video, yuv420p, 640×480 [PAR 1:1 DAR 4:3], 104857 kb/s, 25.00 tb(r)
    Output #0, flv, to ‘demo3.flv’:
    Stream #0.0: Video: flv, yuv420p, 640×480 [PAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25.00 tb(c)
    Stream #0.1: Audio: libmp3lame, 32000 Hz, mono, 64 kb/s
    Stream mapping:
    Stream #0.1 -> #0.0
    Stream #0.0 -> #0.1
    [libmp3lame @ 0x2aadd5ebf800]flv does not support that sample rate, choose from (44100, 22050, 11025).
    Could not write header for output file #0 (incorrect codec parameters ?)

    And output file has no sound. Any idea? What GCC 4.2 means to me? I installed on the bluehost account.

    Thanks.

  9. after installed php version 4.4.4 I came this error 🙁

    [pandora]$ php -r ‘phpinfo();’ | grep ffmpeg
    PHP Warning: Unknown(): Unable to load dynamic library ‘.//home/vietpro/lib/ffmpeg.so’ – .//home/vietpro/lib/ffmpeg.so: cannot open shared object file: No such file or directory in Unknown on line 0
    Error in argument 1, char 2: option not found r

    thanks

  10. I think it should be --prefix=$HOME --cross-compile --enable-shared --enable-mp3lame --extra-cflags=-I$HOME/include -–extra-ldflags=-L$HOME/lib

  11. Hi,

    I’m on the part on installing ffmpeg after entering this line

    ./configure “–prefix=$HOME” “–cross-compile” “–enable-shared” “–enable-mp3lame” “–extra-cflags=-I$HOME/include” “–extra-ldflags=-L$HOME/lib”

    I’m getting an error:
    Unknown option “-prefix=

    please help 🙁

  12. Thanks for this. I am creating a new site with a section for uploading videos. I am using Drupal and its FlashVideo Module.

    I just installed lame+ffmpeg and it works! My project site is hosted over at Site5 with a shared hosting account.

  13. Hi , it’s me again, I think I resolve the problem ,’of provisional form’, when I do a new ssh conection to my server i have to declare this variable:

    export TMPDIR=$HOME/tmp
    export PATH=$HOME/bin:$PATH
    export LD_LIBRARY_PATH=$HOME/lib:/usr/local/lib:$LD_LIBRARY_PATH
    export CPATH=$HOME/include:/usr/local/include:$CPATH
    export LIBRARY_PATH=$HOME/lib:/usr/local/lib:$LIBRARY_PATH

    the quiestion here , is , how can I to leave these declared variables of permanent form

  14. Hi Imtiaz, I have a problem when I close my ssh conection , because before that I can encode and use the ffmpeg program very well. but when I close my ssh conection after I install and play with ffmpeg , and I try to use it again the following error outputs:

    error while loading shared libraries: libavformat.so.51: cannot open shared object file: No such file or directory

    but the libavformat.so.51 already exists in the lib folder.

    When I run the ffmpeg program succesfully a litle notice outputs :
    Compiler did not align stack variables. Libavcodec has been miscompiled
    and may be very slow or crash. This is not a bug in libavcodec,
    but in the compiler. Do not report crashes to FFmpeg developers.
    frame= 456 fps=120 q=31.0 Lsize= 406kB time=30.4 bitrate= 109.3kbits/s

    but it works, the real missworking happens when I close the ssh conection

    I will apriciatte your help

    sorry form my bad english

    Regards!

  15. Thanks to your excellent instructions I have a fully working version of ffmpeg and ffmpeg-php on my Bluehost shared hosting account.

    I can now transcode well and make thumnails using ffmpeg and ffmpeg-php

    Just one thing..the enable falg on ffmpeg compilation is
    –enable-libmp3lame

    Thanks a tonne ..and i would recommend Bluehost to get all this compiled.

    HJ

  16. I followed this tutrial and everything went well.
    Towards the end I needed to hire Imtiaz to get everything to work with my script.

    Within 24 hours of contacting Imtiaz I had my script up and running with no further issues.
    He quoted me a fair price for the work that I needed and I would highly recomend him and his services to anyone wishing to set up FFMPEG etc.

    I told Imtiaz exactly how I wanted things to run and that’s exactly what I got.
    No messing, No Misunderstandings, No confusion.

    Take my advice, stop strugling and get a professional on the case.
    I am more than happy with the services and the speed of the services and would gladly recomend Imtiaz to anyone wishing to install all these things.
    http://blog.netbrix.net/archives/39

    Without a doubt, If I ever need anything in this are of expertise doing again, I know who I’m gonna call!

    Stop pulling your hair out, spend a few bucks and get it done right!

    Thanks again Imtiaz!
    Great work!!!!

    Mike (Completely 101% Happy Customer)

  17. Hello Imtiaz,
    thanks for the information I was able to install every thing but I switched php4.4 with php5.2 and got every thing installed. I installed mplayer last as I missed it. Will it be a problem.

    My question is on dreamhost you have separate folders per each domain. So where should I create cgi-bin directory and where should I place the .htaccess file.
    Can I put the environment variables somewhere so that I need not edit all the php files where ffmpeg is called?

  18. hey hi guys,

    first of thanks to you guys! good informations, but I am having a problem installing ffmpeg-php, however I have installed everything else succesesfuly! 🙂 but the only problem that cost me lost of heachache is that when i try to run the phpize command, it says ” -bash: phpize: command not found” I serached on google, nothing usefull found so far. I have a VPS server, which is alrady php1, php4, php5 is installed by the defult, i try to cantact my hosting comapny, they denied to assist me, due the VPS server is a unmanaged, but anyway, if you guys hahve any sulotion, or any other alternative, or knowing any other command insted of phpize, help me. I will be obliged.
    thanks

  19. under Setup users environment

    cp $HOME/lib/php/extensions/no-debug-non-zts-20020429/ffmpeg.so ./

    the extensions dir inside $HOME/lib/php/ is not cretade during installation!! wht did I missed??

  20. Hi Daniel,
    Try looking at the autoconf setup. If you do not see a autoconf binary in $HOME/bin (assuming shared host) then you probably need to install autoconf and make sure it works before proceeding.

    also check the environment variables specifically PATH and LD_LIBRARY_PATH

    If all else fails browse over to http://blog.netbrix.net/archives/39 😉

    Warm Regards
    Imtiaz

Leave a Reply

Your email address will not be published. Required fields are marked *