How to Install ffmpeg and ffmpeg-php: Difference between revisions
Docs admin (talk | contribs) No edit summary |
Docs admin (talk | contribs) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 25: | Line 25: | ||
We will begin installing the individual components that ffmpeg needs to operate properly. | We will begin installing the individual components that ffmpeg needs to operate properly. | ||
== Install | == Install libogg == | ||
Let's start by downloading and installing libogg: | Let's start by downloading and installing libogg: | ||
Line 36: | Line 36: | ||
ldconfig | ldconfig | ||
cd ..</syntaxhighlight> | cd ..</syntaxhighlight> | ||
< | ==Install libvorbis== | ||
<syntaxhighlight lang="bash">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 ..</syntaxhighlight> | ||
< | ==Install LAME== | ||
< | <syntaxhighlight lang="bash">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 ..</syntaxhighlight> | |||
< | ==Install YASM== | ||
<syntaxhighlight lang="bash">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 ..</syntaxhighlight> | |||
< | ==Install ffmpeg== | ||
< | 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. | ||
< | |||
< | <syntaxhighlight lang="bash">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 ..</syntaxhighlight> | |||
==Verify ffmpeg is properly installed== | |||
At this point, you should verify that ffmpeg is working by running ffmpeg from the command line. You should see something similar to this: | |||
<syntaxhighlight lang="bash">[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'</syntaxhighlight> | |||
If you see an error similar to: | |||
<syntaxhighlight lang="bash">ffmpeg: error while loading shared libraries: libavdevice.so.52: cannot open shared object file: No such file or directory</syntaxhighlight> | |||
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: | |||
<pre>/etc/ld.so.conf</pre> | |||
Add in the following line to the bottom: | |||
<syntaxhighlight lang="bash">/usr/local/lib</syntaxhighlight> | |||
Save the file and then run: | |||
<syntaxhighlight lang="bash">ldconfig</syntaxhighlight> | |||
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. | |||
==Install Ruby== | |||
<syntaxhighlight lang="bash">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 ..</syntaxhighlight> | |||
==Install FLVTool2== | |||
With Ruby installed, we can now install FLVTool2. | |||
<syntaxhighlight lang="bash">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 ..</syntaxhighlight> | |||
==Install ffmpeg-php== | |||
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. | |||
===Download ffmpeg-php=== | |||
<syntaxhighlight lang="bash">wget http://sourceforge.net/projects/ffmpeg-php/files/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2/download | |||
tar -jxf ffmpeg-php-0.6.0.tbz2 | |||
cd ffmpeg-php-0.6.0</syntaxhighlight> | |||
===Correct PIX_FMT_RGBA32=== | |||
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: | |||
<pre>ffmpeg_frame.c</pre> | |||
Replace all instances of PIX_FMT_RGBA32 with PIX_FMT_RGB32 and save. | |||
We're now going to compile ffmpeg-php. | |||
===Installing ffmpeg-php on PHP 5.4=== | |||
If you are running PHP 5.3.x or below, you can skip this section. If you are attempting to install ffmpeg-php on PHP 5.4, the following changes need to be made. In a text editor, open up this file: | |||
<pre>ffmpeg_movie.c</pre> | |||
On line 311, change this: | |||
<syntaxhighlight lang="bash">list_entry *le;</syntaxhighlight> | |||
to: | |||
<syntaxhighlight lang="bash">zend_rsrc_list_entry *le;</syntaxhighlight> | |||
On line 346, change: | |||
<syntaxhighlight lang="bash">list_entry new_le;</syntaxhighlight> | |||
to: | |||
<syntaxhighlight lang="bash">zend_rsrc_list_entry new_le;</syntaxhighlight> | |||
On line 360, change: | |||
<syntaxhighlight lang="bash">hashkey_length+1, (void *)&new_le, sizeof(list_entry),</syntaxhighlight> | |||
to: | |||
<syntaxhighlight lang="bash">hashkey_length+1, (void *)&new_le,sizeof(zend_rsrc_list_entry),</syntaxhighlight> | |||
You can now proceed to compile ffmpeg-php. | |||
===Compile ffmpeg-php=== | |||
<syntaxhighlight lang="bash">phpize | |||
./configure | |||
make | |||
make install</syntaxhighlight> | |||
Immediately after installing ffmpeg-php, you should see a path where it was installed similar to: | |||
<syntaxhighlight lang="bash">Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20060613/</syntaxhighlight> | |||
Take note of this path. We're going to need it later when we load the ffmpeg.so module into your php.ini. | |||
===Adding ffmpeg-php to your php.ini=== | |||
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: | |||
<pre>/usr/local/lib/php.ini</pre> | |||
Within the php.ini locate these lines: | |||
<syntaxhighlight lang="bash"># Directory in which the loadable extensions (modules) reside. | |||
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"</syntaxhighlight> | |||
Usually the extension_dir already matches the path we saved above while compiling. 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. | |||
Scroll down to the "Dynamic Extensions" section, and add this line: | |||
<syntaxhighlight lang="bash">extension = ffmpeg.so</syntaxhighlight> | |||
Save your php.ini and exit the editor. | |||
==Cleaning Up== | |||
We can now remove the source and tmp files we used during the installation and clear the TMPDIR variable. | |||
<syntaxhighlight lang="bash">rm -rf /root/ffmpeg-install-files/ | |||
rm -rf /root/tmp-ffmpeg/ | |||
export TMPDIR=</syntaxhighlight> | |||
ffmpeg and ffmpeg-php are now installed and ready for use. |
Latest revision as of 18:37, 8 November 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
To start, connect to your server via SSH as root.
Create an executable directory
Create a new executable directory by running these commands:
<syntaxhighlight lang="bash">export TMPDIR=/root/tmp-ffmpeg mkdir /root/tmp-ffmpeg</syntaxhighlight>
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:
<syntaxhighlight lang="bash">mkdir /root/ffmpeg-install-files/ cd /root/ffmpeg-install-files/</syntaxhighlight>
We will begin installing the individual components that ffmpeg needs to operate properly.
Install libogg
Let's start by downloading and installing libogg:
<syntaxhighlight lang="bash">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 ..</syntaxhighlight>
Install libvorbis
<syntaxhighlight lang="bash">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 ..</syntaxhighlight>
Install LAME
<syntaxhighlight lang="bash">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 ..</syntaxhighlight>
Install YASM
<syntaxhighlight lang="bash">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 ..</syntaxhighlight>
Install ffmpeg
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.
<syntaxhighlight lang="bash">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 ..</syntaxhighlight>
Verify ffmpeg is properly installed
At this point, you should verify that ffmpeg is working by running ffmpeg from the command line. You should see something similar to this:
<syntaxhighlight lang="bash">[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'</syntaxhighlight>
If you see an error similar to:
<syntaxhighlight lang="bash">ffmpeg: error while loading shared libraries: libavdevice.so.52: cannot open shared object file: No such file or directory</syntaxhighlight>
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:
<syntaxhighlight lang="bash">/usr/local/lib</syntaxhighlight>
Save the file and then run:
<syntaxhighlight lang="bash">ldconfig</syntaxhighlight>
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.
Install Ruby
<syntaxhighlight lang="bash">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 ..</syntaxhighlight>
Install FLVTool2
With Ruby installed, we can now install FLVTool2.
<syntaxhighlight lang="bash">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 ..</syntaxhighlight>
Install ffmpeg-php
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.
Download ffmpeg-php
<syntaxhighlight lang="bash">wget http://sourceforge.net/projects/ffmpeg-php/files/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2/download tar -jxf ffmpeg-php-0.6.0.tbz2 cd ffmpeg-php-0.6.0</syntaxhighlight>
Correct PIX_FMT_RGBA32
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 PIX_FMT_RGBA32 with PIX_FMT_RGB32 and save.
We're now going to compile ffmpeg-php.
Installing ffmpeg-php on PHP 5.4
If you are running PHP 5.3.x or below, you can skip this section. If you are attempting to install ffmpeg-php on PHP 5.4, the following changes need to be made. In a text editor, open up this file:
ffmpeg_movie.c
On line 311, change this:
<syntaxhighlight lang="bash">list_entry *le;</syntaxhighlight>
to:
<syntaxhighlight lang="bash">zend_rsrc_list_entry *le;</syntaxhighlight>
On line 346, change:
<syntaxhighlight lang="bash">list_entry new_le;</syntaxhighlight>
to:
<syntaxhighlight lang="bash">zend_rsrc_list_entry new_le;</syntaxhighlight>
On line 360, change:
<syntaxhighlight lang="bash">hashkey_length+1, (void *)&new_le, sizeof(list_entry),</syntaxhighlight>
to:
<syntaxhighlight lang="bash">hashkey_length+1, (void *)&new_le,sizeof(zend_rsrc_list_entry),</syntaxhighlight>
You can now proceed to compile ffmpeg-php.
Compile ffmpeg-php
<syntaxhighlight lang="bash">phpize ./configure make make install</syntaxhighlight>
Immediately after installing ffmpeg-php, you should see a path where it was installed similar to:
<syntaxhighlight lang="bash">Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20060613/</syntaxhighlight>
Take note of this path. We're going to need it later when we load the ffmpeg.so module into your php.ini.
Adding ffmpeg-php to your php.ini
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:
<syntaxhighlight lang="bash"># Directory in which the loadable extensions (modules) reside. extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"</syntaxhighlight>
Usually the extension_dir already matches the path we saved above while compiling. 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.
Scroll down to the "Dynamic Extensions" section, and add this line:
<syntaxhighlight lang="bash">extension = ffmpeg.so</syntaxhighlight>
Save your php.ini and exit the editor.
Cleaning Up
We can now remove the source and tmp files we used during the installation and clear the TMPDIR variable.
<syntaxhighlight lang="bash">rm -rf /root/ffmpeg-install-files/ rm -rf /root/tmp-ffmpeg/ export TMPDIR=</syntaxhighlight>
ffmpeg and ffmpeg-php are now installed and ready for use.