Difference between revisions of "How to Install ffmpeg and ffmpeg-php"

From Acenet Knowledgebase
Jump to: navigation, search
(test)
 
Line 1: Line 1:
<html>Installing FFMPEG<br /> <br /> <br /> This guide will show you step by step how to install ffmpeg. First, you will want to connect to your server's shell as root. Once you are connected, you will <br /> <br /> want to ensure that your /tmp partition is writeable so you can properly compile the modules. Use this command:<br /> <br /> <strong>mount -o defaults,remount,rw /tmp</strong><br /> <br /> <br /> <br /> Next we will begin installing the individual components that FFMPEG needs to operate properly. First, we will want to download and install libogg using the <br /> <br /> following commands:<br /> <br /> <strong>wget http://downloads.xiph.org/releases/ogg/libogg-1.1.3.tar.gz<br /> tar -xzvf libogg-1.1.3.tar.gz<br /> cd libogg-1.1.3<br /> ./configure --prefix=/usr and  and  make<br /> make install<br /> cd ../<br /> rm -rf libogg*</strong><br /> <br /> <br /> <br /> Next, we will be downloading and installing libvorbis:<br /> <br /> <br /> <strong>wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.2.0.tar.gz<br /> tar -xzvf libvorbis-1.2.0.tar.gz<br /> cd libvorbis-1.2.0<br /> ./configure --prefix=/usr and  and  make<br /> make install<br /> cd ../<br /> rm -rf libvorbis*</strong><br /> <br /> <br /> Next we will be downloading and installing LAME, which ffmpeg uses for handling the audio components. <br /> <br /> <br /> <strong>wget http://internap.dl.sourceforge.net/sourceforge/lame/lame-398.tar.gz<br /> tar -xzvf lame-398.tar.gz<br /> cd lame-398<br /> ./configure --enable-shared --prefix=/usr<br /> make<br /> make install<br /> cd ..<br /> rm -rf lame*</strong><br /> <br /> <br /> <br /> After LAME is installed, we can install ffmpeg itself by running these commands:<br /> <br /> <strong>wget http://ffmpeg.mplayerhq.hu/releases/ffmpeg-export-snapshot.tar.bz2<br /> tar -xjvf ffmpeg-export-snapshot.tar.bz2<br /> cd ffmpeg-export-XXXXXXX<br /> ./configure --enable-libmp3lame --enable-libvorbis --enable-shared<br /> make clean  and  and  make<br /> make install<br /> mkdir /usr/local/include/ffmpeg<br /> cp libavformat/avio.h /usr/local/include/ffmpeg<br /> cp libavformat/avformat.h /usr/local/include/ffmpeg<br /> cp libavcodec/avcodec.h /usr/local/include/ffmpeg<br /> cd ..<br /> rm -rf ffmpeg*</strong><br /> <br /> <br /> <br /> The base ffmpeg component is now installed, but we arent done yet! Next up is ruby, which is required for ffmpeg to function properly. Install it with these <br /> <br /> commands:<br /> <br /> <strong>wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7.tar.gz<br /> tar -xzvf ruby-1.8.7.tar.gz<br /> cd ruby-1.8.7<br /> ./configure; make; make install;<br /> cd ..<br /> rm -rf ruby*</strong><br /> <br /> <br /> After ruby we need to install FLVTool2, which lets ffmpeg interact with flash based video files.<br /> <br /> <strong>wget http://rubyforge.org/frs/download.php/17497/flvtool2-1.0.6.tgz<br /> tar -xzvf flvtool2-1.0.6.tgz<br /> cd flvtool2-1.0.6<br /> ruby setup.rb config<br /> ruby setup.rb setup<br /> ruby setup.rb install<br /> cd ..<br /> rm -rf flvtool2*</strong><br /> <br /> <br /> <br /> Next we have to download and install the ffmpeg-php module. Do so with these commands:<br /> <br /> <strong>wget http://internap.dl.sourceforge.net/sourceforge/ffmpeg-php/ffmpeg-php-0.6.0.tbz2<br /> tar -xjvf ffmpeg-php-0.6.0.tbz2<br /> cd ffmpeg-php-0.6.0<br /> phpize<br /> ./configure  and  and  make<br /> make install<br /> cd ..<br /> rm -rf ffmpeg*</strong><br /> <br /> <br /> <span style="color: #990000;">!!!IMPORTANT!!!</span> There will be a PHP extensions folder output to the screen. Save it for later.            <span style="color: #990000;">!!!IMPORTANT!!!</span><br /> <br /> <span style="color: #990000;">!!!IMPORTANT!!!</span><br /> "/usr/local/lib/php/extensions/no-debug-non-zts-20060613/" <--- looks something like this <span style="color: #990000;">!!!IMPORTANT!!!</span><br /> <br /> <br /> <br /> We have one more thing to install, thats thats the MPlayer/Mencoder application. Do so with these commands:<br /> <br /> <strong>wget http://www4.mplayerhq.hu/MPlayer/releases/MPlayer-1.0rc2.tar.bz2<br /> tar -xjvf MPlayer-1.0rc2.tar.bz2<br /> cd MPlayer-1.0rc2<br /> ./configure  and  and  make; make install<br /> cd ..<br /> rm -rf MPlayer*</strong><br /> <br /> <br /> <br /> Now that we have all the required components installed, we need to change /tmp back to normal with this command:<br /> <br /> <strong>mount -o defaults,remount /tmp</strong><br /> <br /> After that, we need to open up the global php.ini file ( /usr/local/lib/php.ini ) so we can change a couple of settings. You can use whatever text editor you <br /> <br /> like, but I recommend nano:<br /> <br /> <strong>nano /usr/local/lib/php.ini</strong><br /> <br /> You will want to scroll down until you locate these lines:<br /> <br /> <strong>; Directory in which the loadable extensions (modules) reside.<br /> extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"</strong><br /> <br /> <br /> You will want to replace the extensions_dir value with the extensions folder that we saved earlier. <br /> <br /> <span style="color: #990000;">!!!IMPORTANT!!!</span><br /> If you are using any other custom .so modules, you will want to copy them into this folder.     <span style="color: #990000;">!!!IMPORTANT!!!</span><br /> <br /> <br /> Scroll down to the "Dynamic Extensions" section, and add this line:<br /> <br /> <strong>extension = ffmpeg.so</strong><br /> <br /> <br /> Save your work, ( ctrl O if you are using nano ) and exit. FFMPEG is now installed and ready for use.<br /></html> [[Category:FFMPEG]]
+
<p>In our testing, ffmpeg-php failed to install properly against the newest version of ffmpeg. &nbsp;Since lots of scripts which manipulate video &nbsp;typically use the ffmpeg-php API to accesss ffmpeg functions, we recommend installing the exact versions referrenced in this guide. &nbsp;If you choose to install a later version of ffmpeg, please be aware you may have difficulties installing ffmpeg-php (if you can at all). &nbsp;&nbsp;</p>
 +
<p>In this guide, we will assume you are running CentOS 5.x. &nbsp;These instructions may work for other distributions as well. &nbsp;Before you begin ensure you've installed these necessary prerequisite packages using yum:</p>
 +
<p>wget<br />gcc<br />make<br />pkgconfig<br />php-devel<br />autoconf<br />libtool</p>
 +
<p>1) Connect to your server's via SSH as root.</p>
 +
<p>2) Create a new executable directory by running these commands:</p>
 +
<div class="code_style">export TMPDIR=/root/tmp-ffmpeg<br /> mkdir /root/tmp-ffmpeg</div>
 +
<p>3) Let's create a directory for all of our install files. &nbsp;When we're done we can delete this entire directory to clean things up:</p>
 +
<div class="code_style">mkdir /root/ffmpeg-install-files/<br /> cd /root/ffmpeg-install-files/</div>
 +
<p>4) &nbsp;We will begin installing the individual components that ffmpeg needs to operate properly. Let's start by downloading and installing libogg:</p>
 +
<div class="code_style">wget http://downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.gz<br /> tar -zxf libogg-1.3.0.tar.gz<br /> cd libogg-1.3.0/<br /> ./configure --prefix=/usr<br /> make<br /> make install<br /> ldconfig<br /> cd ..</div>
 +
<p>5) Install libvorbis:</p>
 +
<div class="code_style">wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.gz<br /> tar -zxf libvorbis-1.3.3.tar.gz<br /> cd libvorbis-1.3.3<br /> ./configure --prefix=/usr<br /> make<br /> make install<br /> cd ..</div>
 +
<br />6) Install LAME:&nbsp;<br /> <br />
 +
<div class="code_style">wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz<br /> tar -zxf lame-3.99.5.tar.gz<br /> cd lame-3.99.5<br /> ./configure --enable-shared --prefix=/usr<br /> make<br /> make install<br /> cd ..</div>
 +
<p>7) Install YASM</p>
 +
<div class="code_style">wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz<br /> tar -zxf yasm-1.2.0.tar.gz<br /> cd yasm-1.2.0<br /> ./configure<br /> make<br /> make install<br /> cd ..</div>
 +
<p>8) We'll now install ffmpeg itself. &nbsp;As noted above, we recommend using the exact version listed here to ensure ffmpeg-php installs properly later on:</p>
 +
<div class="code_style">wget http://ffmpeg.org/releases/ffmpeg-0.6.1.tar.gz<br /> tar -zxf ffmpeg-0.6.1.tar.gz<br /> cd ffmpeg-0.6.1<br /> ./configure --enable-libmp3lame --enable-libvorbis --enable-shared<br /> make<br /> make install<br /> cd ..</div>
 +
<p>9) At this point, you should verify that ffmpeg is working by running ffmpeg from the command line. &nbsp;You should see something similar to this:</p>
 +
<div class="code_style">[root@ ]# ffmpeg<br /> FFmpeg version 0.6.1, Copyright (c) 2000-2010 the FFmpeg developers<br /> built on Sep 26 2012 17:11:54 with gcc 4.1.2 20080704 (Red Hat 4.1.2-52)<br /> configuration: --enable-libmp3lame --enable-libvorbis --enable-shared<br /> libavutil    50.15. 1 / 50.15. 1<br /> libavcodec    52.72. 2 / 52.72. 2<br /> libavformat   52.64. 2 / 52.64. 2<br /> libavdevice  52. 2. 0 / 52. 2. 0<br /> libswscale    0.11. 0 / 0.11. 0<br /> Hyper fast Audio and Video encoder<br /> usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...<br /> <br /> Use -h to get full help or, even better, run 'man ffmpeg'</div>
 +
<p>If you see an error similar to:</p>
 +
<div class="code_style">ffmpeg: error while loading shared libraries: libavdevice.so.52: cannot open shared object file: No such file or directory</div>
 +
<p>you may need to help ffmpeg locate libavdevice.so.52. &nbsp;To do so, we're going to open up our favorite text editor (nano, vim, etc.) and edit this file:</p>
 +
<div class="code_style">/etc/ld.so.conf</div>
 +
<p>Add in the following line to the bottom:</p>
 +
<div class="code_style">/usr/local/lib</div>
 +
<p>Save the file and then run:</p>
 +
<div class="code_style">ldconfig</div>
 +
<p>You should now be able to execute ffmpeg from the command line as shown above&nbsp;and see the version information.</p>
 +
<p>The base ffmpeg component is now installed, but ffmpeg is typically used on websites (like YouTube) for converting user content into the web-friendly flash format. &nbsp;To do this, FLVTool2 must be installed which relies on Ruby for installation.</p>
 +
<p>10) Let's install Ruby:</p>
 +
<div class="code_style">wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz<br /> tar -zxf ruby-1.9.3-p194.tar.gz<br /> cd ruby-1.9.3-p194<br /> ./configure<br /> make<br /> make install<br /> cd ..</div>
 +
<p>11) &nbsp;With Ruby installed, we can now install FLVTool2:</p>
 +
<div class="code_style">wget http://rubyforge.org/frs/download.php/17497/flvtool2-1.0.6.tgz<br /> tar -xzvf flvtool2-1.0.6.tgz<br /> cd flvtool2-1.0.6<br /> ruby setup.rb config<br /> ruby setup.rb setup<br /> ruby setup.rb install<br /> cd ..</div>
 +
<p>12) &nbsp;We now have ffmpeg and its necessary libraries installed. &nbsp;To allow many web scripts to make use of ffmpeg, we'll need to install the ffmpeg-php API:</p>
 +
<div class="code_style">wget http://sourceforge.net/projects/ffmpeg-php/files/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2/download<br /> tar -jxf ffmpeg-php-0.6.0.tbz2<br /> cd ffmpeg-php-0.6.0</div>
 +
<p>Before we proceed to compile ffmpeg-php, we need to make some adjustments to ffmpeg-php's source code. &nbsp;Within the 0.6.0 version of ffmpeg-php, there are coding errors that must be corrected. &nbsp;In a text editor, open up this file:</p>
 +
<div class="code_style">ffmpeg_frame.c</div>
 +
<p>Replace all instances of the PIX_FMT_RGBA32 with PIX_FMT_RGB32 and save. &nbsp;We're now going to compile ffmpeg-php. &nbsp;Run:</p>
 +
<div class="code_style">phpize<br /> ./configure<br /> make<br /> make install</div>
 +
<p>Immediately after installing ffmpeg-php, you should see a path where it was installed similar to:</p>
 +
<div class="code_style">Installing shared extensions:  /usr/local/lib/php/extensions/no-debug-non-zts-20060613/</div>
 +
<p>Take note of this path.  We're going to need it later when we load the ffmpeg.so module into your php.ini.</p>
 +
<p>13) &nbsp;Let's load the ffmpeg.so module for PHP so that web scripts have access to the ffmpeg-php API. &nbsp;Open up your server's php.ini file. &nbsp;If you're on a cPanel server, it's usually located at:</p>
 +
<div class="code_style">/usr/local/lib/php.ini</div>
 +
<br /> &nbsp;Within the php.ini locate these lines:<br /> <br />
 +
<div class="code_style">; Directory in which the loadable extensions (modules) reside.<br /> extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"</div>
 +
<br /> Usually the extension_dir already matches the path we saved in step 12. &nbsp;If it's not correct, update it. &nbsp;If you are using any other custom .so modules, you will want to copy them into that folder so that PHP can find them.<br /> <br /> 14) Scroll down to the "Dynamic Extensions" section, and add this line:<br /> <br />
 +
<div class="code_style">extension = ffmpeg.so</div>
 +
<p>Save your php.ini and exit the editor.</p>
 +
<p>15) We can now remove the source and tmp files we used during the installation and clear the TMPDIR variable by running these commands:</p>
 +
<div class="code_style">rm -rf /root/ffmpeg-install-files/<br /> rm -rf /root/tmp-ffmpeg/<br /> export TMPDIR=</div>
 +
<p>ffmpeg and ffmpeg-php are now installed and ready for use.</p>

Revision as of 14:22, 5 October 2012

In our testing, ffmpeg-php failed to install properly against the newest version of ffmpeg.  Since lots of scripts which manipulate video  typically use the ffmpeg-php API to accesss ffmpeg functions, we recommend installing the exact versions referrenced in this guide.  If you choose to install a later version of ffmpeg, please be aware you may have difficulties installing ffmpeg-php (if you can at all).   

In this guide, we will assume you are running CentOS 5.x.  These instructions may work for other distributions as well.  Before you begin ensure you've installed these necessary prerequisite packages using yum:

wget
gcc
make
pkgconfig
php-devel
autoconf
libtool

1) Connect to your server's via SSH as root.

2) Create a new executable directory by running these commands:

export TMPDIR=/root/tmp-ffmpeg
mkdir /root/tmp-ffmpeg

3) Let's create a directory for all of our install files.  When we're done we can delete this entire directory to clean things up:

mkdir /root/ffmpeg-install-files/
cd /root/ffmpeg-install-files/

4)  We will begin installing the individual components that ffmpeg needs to operate properly. Let's start by downloading and installing libogg:

wget http://downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.gz
tar -zxf libogg-1.3.0.tar.gz
cd libogg-1.3.0/
./configure --prefix=/usr
make
make install
ldconfig
cd ..

5) Install libvorbis:

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


6) Install LAME: 

wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar -zxf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure --enable-shared --prefix=/usr
make
make install
cd ..

7) Install YASM

wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar -zxf yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure
make
make install
cd ..

8) We'll now install ffmpeg itself.  As noted above, we recommend using the exact version listed here to ensure ffmpeg-php installs properly later on:

wget http://ffmpeg.org/releases/ffmpeg-0.6.1.tar.gz
tar -zxf ffmpeg-0.6.1.tar.gz
cd ffmpeg-0.6.1
./configure --enable-libmp3lame --enable-libvorbis --enable-shared
make
make install
cd ..

9) At this point, you should verify that ffmpeg is working by running ffmpeg from the command line.  You should see something similar to this:

[root@ ]# ffmpeg
FFmpeg version 0.6.1, Copyright (c) 2000-2010 the FFmpeg developers
built on Sep 26 2012 17:11:54 with gcc 4.1.2 20080704 (Red Hat 4.1.2-52)
configuration: --enable-libmp3lame --enable-libvorbis --enable-shared
libavutil 50.15. 1 / 50.15. 1
libavcodec 52.72. 2 / 52.72. 2
libavformat 52.64. 2 / 52.64. 2
libavdevice 52. 2. 0 / 52. 2. 0
libswscale 0.11. 0 / 0.11. 0
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

If you see an error similar to:

ffmpeg: error while loading shared libraries: libavdevice.so.52: cannot open shared object file: No such file or directory

you may need to help ffmpeg locate libavdevice.so.52.  To do so, we're going to open up our favorite text editor (nano, vim, etc.) and edit this file:

/etc/ld.so.conf

Add in the following line to the bottom:

/usr/local/lib

Save the file and then run:

ldconfig

You should now be able to execute ffmpeg from the command line as shown above and see the version information.

The base ffmpeg component is now installed, but ffmpeg is typically used on websites (like YouTube) for converting user content into the web-friendly flash format.  To do this, FLVTool2 must be installed which relies on Ruby for installation.

10) Let's install Ruby:

wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
tar -zxf ruby-1.9.3-p194.tar.gz
cd ruby-1.9.3-p194
./configure
make
make install
cd ..

11)  With Ruby installed, we can now install FLVTool2:

wget http://rubyforge.org/frs/download.php/17497/flvtool2-1.0.6.tgz
tar -xzvf flvtool2-1.0.6.tgz
cd flvtool2-1.0.6
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install
cd ..

12)  We now have ffmpeg and its necessary libraries installed.  To allow many web scripts to make use of ffmpeg, we'll need to install the ffmpeg-php API:

Before we proceed to compile ffmpeg-php, we need to make some adjustments to ffmpeg-php's source code.  Within the 0.6.0 version of ffmpeg-php, there are coding errors that must be corrected.  In a text editor, open up this file:

ffmpeg_frame.c

Replace all instances of the PIX_FMT_RGBA32 with PIX_FMT_RGB32 and save.  We're now going to compile ffmpeg-php.  Run:

phpize
./configure
make
make install

Immediately after installing ffmpeg-php, you should see a path where it was installed similar to:

Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20060613/

Take note of this path. We're going to need it later when we load the ffmpeg.so module into your php.ini.

13)  Let's load the ffmpeg.so module for PHP so that web scripts have access to the ffmpeg-php API.  Open up your server's php.ini file.  If you're on a cPanel server, it's usually located at:

/usr/local/lib/php.ini


 Within the php.ini locate these lines:

; Directory in which the loadable extensions (modules) reside.
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"


Usually the extension_dir already matches the path we saved in step 12.  If it's not correct, update it.  If you are using any other custom .so modules, you will want to copy them into that folder so that PHP can find them.

14) Scroll down to the "Dynamic Extensions" section, and add this line:

extension = ffmpeg.so

Save your php.ini and exit the editor.

15) We can now remove the source and tmp files we used during the installation and clear the TMPDIR variable by running these commands:

rm -rf /root/ffmpeg-install-files/
rm -rf /root/tmp-ffmpeg/
export TMPDIR=

ffmpeg and ffmpeg-php are now installed and ready for use.