FFmpeg
| The instructions provided in this article or section are considered advanced. You are expected to be knowledgeable in the UNIX shell. |
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.
Contents |
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/ffmpegThe absolute path to the supporting libraries is:
/usr/lib/vhook
There is also a newer version installed at /usr/local/dh/bin/ffmpeg.
Manual Install of FFmpeg
If you'd like to download, compile, and install a more recent version of FFmpeg, follow these instructions carefully.
- 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.
- To see a list of files and directories in your home directory, type:
dir
- If the bin directory doesn't already exist, create it by typing:
mkdir bin
- Set the correct permissions for the bin directory by typing:
chmod 775 bin
- If the lib directory doesn't already exist, create it by typing:
mkdir lib
- Set the correct permissions for the lib directory by typing:
chmod 775 lib
- If the tmp directory doesn't already exist, create it by typing:
mkdir tmp
- Set the correct permissions for the tmp directory by typing:
chmod 775 tmp
- Type:export TMPDIR=/home/username/tmpwhere username is the same username you used to log into the SSH session
- Download the latest version of FFmpeg into a new temporary directory called ffmpeg by typing:
svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
- 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
- Next, compile the FFmpeg program by typing:
make
- Install FFmpeg by typing:
make install
- Return to your home directory by typing:
cd ..
- Remove the temporary ffmpeg directory by typing:
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:The absolute path to the supporting libraries is:/home/username/bin/ffmpegwhere username is the same username you used to log into the SSH session.
/home/username/lib/vhookwhere 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: Flash Media. 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:
--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:
- Move to home folder:
cd ~
- Create the folder for source files:
mkdir libx264-source
- Move to source files folder:
cd libx264-source
- Download files via git:
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:
- Move to source folder:
cd libx264-source
- Configure application (remember to replace <USERNAME> with your SSH login name)
./configure --enable-shared --disable-asm --prefix=/home/<USERNAME>
- Compile:
make
- Install:
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:
- Make sure we're in home folder:
cd ~
- Move to bin folder:
cd bin
- Ask x264 to help us!
./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:
./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:
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:
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:
./ffmpeg -i input.file -y -ar 44100 -pass 2 -vcodec libx264 -b 810k -vpre normal -threads 0 output.fileThe output will be something like
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
-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.
External Links
- Original source of this information
- FFmpeg web site
- Gallery web site
- WinFF A free cross-platform ffmpeg GUI for those of you who want to convert videos locally