FFmpeg

FFmpeg is a program that can record, convert and stream digital audio and video in numerous formats. Its most widely used to convert video files to the popular FLV format for playback using a Flash video player in a web browser. On Dreamhost, it can be used with Gallery to create movie thumbnails.

Shared Installation
By default, Dreamhost users have access to a shared installation of FFmpeg.

In web applications, such as Gallery, the absolute path to the shared installation of FFmpeg is:/usr/bin/ffmpeg

The absolute path to the supporting libraries is:/usr/lib/vhook

There is also a newer version installed at.

Manual Install of FFmpeg
If you'd like to download, compile, and install a more recent version of FFmpeg, follow these instructions carefully.


 * 1) Make sure you are using a username that shell access to your account. Using an SSH client (such as PuTTY), open a session with the machine that hosts your website.  EXAMPLE: flamenco.dreamhost.com  Log in using your username and password.  When logged in, you will be automatically placed in your home directory.
 * 2) To see a list of files and directories in your home directory, type:dir
 * 3) If the bin directory doesn't already exist, create it by typing:mkdir bin
 * 4) Set the correct permissions for the bin directory by typing:chmod 775 bin
 * 5) If the lib directory doesn't already exist, create it by typing:mkdir lib
 * 6) Set the correct permissions for the lib directory by typing:chmod 775 lib
 * 7) If the tmp directory doesn't already exist, create it by typing:mkdir tmp
 * 8) Set the correct permissions for the tmp directory by typing:chmod 775 tmp
 * 9) Type:"export TMPDIR=/home/username/tmp where username is the same username you used to log into the SSH session"
 * 10) Download the latest version of FFmpeg into a new temporary directory called ffmpeg by typing:svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
 * 11) Navigate to this new directory by typing:cd ffmpeg
 * Now, configure some options by typing:./configure --prefix=$HOME --enable-cross-compile --enable-shared --arch=amd64 --target-os=linux
 * 1) Next, compile the FFmpeg program by typing:make
 * 2) Install FFmpeg by typing:make install
 * 3) Return to your home directory by typing:cd ..
 * 4) Remove the temporary ffmpeg directory by typing:<blockquote style="font-family:Courier New,courier;font-weight:bold;">rm -rf ffmpeg

If no errors occur, FFmpeg should now be installed.

Configuring Web Applications
In web applications, such as Gallery, the absolute path to your manual installation of FFmpeg is:"<div style='font-family:Courier New,courier;font-weight:bold;'>/home/username/bin/ffmpeg where username is the same username you used to log into the SSH session."

The absolute path to the supporting libraries is:"<div style='font-family:Courier New,courier;font-weight:bold;'>/home/username/lib/vhook where username is the same username you used to log into the SSH session."

However, you need to update gallery's LD_LIBRARY_PATH environment variable to include the new path to the lib folder to allow gallery to use FFMPEG correctly.

Open up the root folder of your gallery installation.

Edit config.php.

Find the following statement: if (!isset($gallery) || !method_exists($gallery, 'setConfig')) { exit; }

After the above statement, place the following line:

putenv('LD_LIBRARY_PATH=/home/USERNAME/lib');

In this example USERNAME is your linux username, and /home/USERNAME/lib is the full path to the lib folder that was filled with shared libraries by the make command above.

Now, when you configure the new path to ffmpeg on the gallery site admin page, the ffmpeg test will work. After you configure gallery to use the new path for ffmpeg, the new build of ffmpeg can be used in gallery.

Php Script For Converting Videos
for a php script, see the wiki article on php-ffmpeg here: php-ffmpeg

Also note that Dreamhost has a Flash video converter built into the Panel:. See Flash Media Player for details, and Converter settings for the ffmpeg settings which it uses internally.

Installing libx264 on Private Servers using your ffmpeg installation
In order to compile your ffmpeg with the libx264 enabled, you have to use the following parameter:

<blockquote style="font-family:Courier New,courier;font-weight:bold;">--enable-libx264

This requires the lib264 installed on your system. The instructions to compile your own libx264 are described below.

First, you need to download the libx264 source. It's available to download via GIT. You can use the following commands:


 * 1) Move to home folder: <blockquote style="font-family:Courier New,courier;font-weight:bold;">cd ~
 * 2) Create the folder for source files: <blockquote style="font-family:Courier New,courier;font-weight:bold;">mkdir libx264-source
 * 3) Move to source files folder: <blockquote style="font-family:Courier New,courier;font-weight:bold;">cd libx264-source
 * 4) Download files via git: <blockquote style="font-family:Courier New,courier;font-weight:bold;">git clone git://git.videolan.org/x264.git

These commands will download the libx264 source files to /home/<USERNAME>/libx264-source folder.

In order to compile and install your libx264 to your home folder (/home/<USERNAME>), follow these steps:


 * 1) Move to source folder: <blockquote style="font-family:Courier New,courier;font-weight:bold;">cd libx264-source
 * 2) Move to x264 folder: <blockquote style="font-family:Courier New,courier;font-weight:bold;">cd x264
 * 3) Configure application (remember to replace <USERNAME> with your SSH login name)<blockquote style="font-family:Courier New,courier;font-weight:bold;">./configure --enable-shared --disable-asm --prefix=/home/<USERNAME>
 * 4) Compile: <blockquote style="font-family:Courier New,courier;font-weight:bold;">make
 * 5) Install: <blockquote style="font-family:Courier New,courier;font-weight:bold;">make install

Note: you don't need to use --prefix as /home/<USERNAME>/bin because libx264 will create if it doesn't exist, and will also create a /lib and /include folders inside your home directory to keep other necessary files, including the x264.h header file. You can check if libx264 was installed successfully by running the following commands:


 * 1) Make sure we're in home folder: <blockquote style="font-family:Courier New,courier;font-weight:bold;">cd ~
 * 2) Move to bin folder: <blockquote style="font-family:Courier New,courier;font-weight:bold;">cd bin
 * 3) Ask x264 to help us! <blockquote style="font-family:Courier New,courier;font-weight:bold;">./x264 --help

This should display the libx264 help text.

Now that we have the libx264 installed, we can compile ffmpeg using it. Problem is: by default, ffmpeg will look for the header files (the x264.h file mentioned above) in the /usr/lib folder. So you will have to run this following command when configuring your ffmpeg installation instead:

<blockquote style="font-family:Courier New,courier;font-weight:bold;">./configure --prefix=/home/<USERNAME> --enable-cross-compile --enable-shared --arch=amd64 --target-os=linux --enable-libx264 --disable-yasm --extra-cflags=-I/home/<USERNAME>/include --extra-ldflags=-L/home/<USERNAME>/lib

This will tell ffmpeg builder where your include and lib files can be found (other than the usual folders).

Hopefully, we now have ffmpeg compiled and libx264 enabled. You may (and probably will) receive an error message like this:

<blockquote style="font-family:Courier New,courier;font-weight:bold;">error while loading shared libraries: libavdevice.so.52: cannot open shared object file: No such file or directory

This is because ffmpeg is looking for it's libraries in the usual place (most probably /usr/lib). In order to get it working, you have to set the enviroinment variable LD_LIBRARY_PATH TO /home/<USERNAME>/lib. This can be done via command line with the following command:

<blockquote style="font-family:Courier New,courier;font-weight:bold;">export LD_LIBRARY_PATH=/home/<USERNAME>/lib

Now you should be able to convert videos using the x264 library. Remember that the libx264 library requires you to parametrize the encoding using a preset file. In my case, i had _serious_ problems using the usual procedure, which would be something like this:

<blockquote style="font-family:Courier New,courier;font-weight:bold;">./ffmpeg -i input.file -y -ar 44100 -pass 2 -vcodec libx264 -b 810k -vpre normal -threads 0 output.file

The output will be something like <blockquote style="font-family:Courier New,courier;font-weight:bold;">File for preset 'normal' not found

So I used -fpre instead of -vpre, which accepts a file as parameter, so I can use something like

<blockquote style="font-family:Courier New,courier;font-weight:bold;">-fpre "/home/<USERNAME>/libx264-medium.ffpreset"

Note: the main reason for me to use a custom ffmpeg and libx264 installation is that the ffmpeg version installed does not accept the -fpre parameters, only the -vpre, so I could not find the preset files. Searched a lot and it'd never for for me.