On Friday I went through the process of installing ffmpeg on dreamhost. Ffmpeg is a free, open source multimedia system and command line tool that can be used to encode and decode from and to several different sources. My interest in using FFmpeg, as aformentioned, is to be able to convert incoming 3gp video from mobile phones to flash video and extract thumbnails of each video uploaded. In order to use ffmpeg to convert to Flash video, however, you also have to download and install LAME, an open source MP3 encoder (which may be illegal…but does it really matter?). Ffmpeg does not support MP3 audio, which is what flash uses. Before installing ffmpeg, you should download and install lame.
As a rule, dreamhost does not allow individuals to install anything with the path /usr/local/lib/ so you have to use the –exec-prefix and –prefix command in the configuration: ./configure –exec-prefix=/home/username/lame –prefix=/home/username/lame to install it to a local folder. This is the same with the ffmpeg instalation, however there are a few differences. You have to enable lame as well as amr_nb, amr_nb_fixed, amr_wb and amr_if2. Amr is apparently the audio codec for certain kinds of mobile phone video. We were testing using video from a Nokia 6682 but further testing needs to be done to see what codecs are used by other phones/carriers. In order to enable Amr you have to download the amr software. Unfortunately, I didn’t write down the download urls for amr, but once you issus the following command: ./configure –prefix=/home/username/ffmpeg –enable-mp3lame –extra-cflags=-I/home/username/lame/include –extra-ldflags=-L/home/username/lame/lib –enable-amr_nb –enable-amr_nb-fixed –enable-amr_wb –enable-amr_if2 a message comes up that instructs you on where to go and what location to install the necessary files to.
Unfortunately we ran into a problem early on. The C compiler was failing to compile because it was trying to install ffmpeg to a tmp folder instead of to the ffmpeg folder we had created. In order to prevent this, we had to comment out this section of the configure file:
# set temporary file name
#if test ! -z “$TMPDIR” ; then
#elif test ! -z “$TEMPDIR” ; then
You also have to make the following changes to the makefile:
CFLAGS = -Wall -I. $(CFLAGS_$(MODE)) -D$(VAD) -DMMS_IO and
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/catmindeye/lame/lib (which tells ffmpeg where to find the lame files).
With ffmpeg successfully installed, our next step is to include code in our perl popper that converts the incoming video to flash and stores it in the database. Calling ffmpeg from perl can be done using the exec function which allows you to issue a system command. You then can incorporate the following commands: (from Shawn’s Producing Participatpry Media class handout)
ffmpeg -i inputfile -t 0.001 -ss 10 -s 100×100 outputfile%d.jpg (creataes thumnbnails- replace inputfile with the name of your movie file, the number after -t is the duration (in seconds), the number after -ss is the starting point in seconds, the value after -s is the width x height and outputfile is the name of the outputfile. This command will create as many frames of JPEGs as it needs to meet the assigned duration)
ffmpeg -i inputfile -acodec mp3 -ab 32 -ac 1 outputfile.flv (replace inputfile with the name of your movie file, the 32 is the bitrate of the audio, the 1 is the number of audio channels and outputfile.flv is the output file name- make sure you keep .flv)
Once we have tested the converting of video on the fly we will post code.
One thing I forgot to mention…in order for the audio to play correctly when uploaded and converted from 3gp (mobile phones) you have to include -ar 44100 in the following command:
ffmpeg -i inputfile -acodec mp3 -ab 32 -ac 1 outputfile.flv
This was discovered as a result of testing from a Nokia 6682.