written by cail • posted in How-To • 2,132 views 1 comment

I used to use some Windows applications. After I abandoned my home Windows Server (converted to a terabyte OpenSolaris file server), it is time to find a way to do this job in Linux. Here is the solution by using the powerfull ffmpeg tool.

1. Modify the ffmpeg to enable x264 and xvid support. I followed the instruction here.

remove the system installed version and prepare for compiling

sudo apt-get purge ffmpeg x264 libx264-dev
sudo apt-get update
sudo apt-get install build-essential subversion git-core checkinstall yasm texi2html libfaad-dev libfaac-dev libfaad-dev libschroedinger-dev libmp3lame-dev libtheora-dev libvorbis-dev libxv-dev libxvmc-dev

Also, find the name of package libavcodec libavdevice libavutil installed in the system and purge them - to prevent linking issues caused by conflicting library versions! You should not find any file started with libavc* libavf* libavd* libavu* in either /usr/lib or /usr/local/lib. Clean them if necessary to avoid trouble later.

install libamr from mediaubuntu

sudo wget http://www.medibuntu.org/sources.list.d/hardy.list --output-document=/etc/apt/sources.list.d/medibuntu.list
sudo apt-get update && sudo apt-get install medibuntu-keyring && sudo apt-get update
sudo apt-get install libamrnb-dev libamrwb-dev

install nut from svn

svn co svn://svn.mplayerhq.hu/nut/src/trunk/ nut
cd nut
sudo checkinstall --fstrans=no --install=yes

install x264 from git

sudo apt-get install libgpac-dev
git clone git://git.videolan.org/x264.git
cd x264
./configure --prefix=/usr/local --enable-shared
sudo checkinstall --fstrans=no --install=yes
sudo ldconfig

install libxvid from source

sudo apt-get install nasm
wget http://downloads.xvid.org/downloads/xvidcore-1.2.1.tar.gz
tar xvfz xvidcore-1.2.1.tar.gz
cd xvidcore/build/generic
./configure --prefix=/usr/local
sudo make install

install ffmpeg from svn

svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
cd ffmpeg
./configure --enable-gpl --enable-postproc --enable-pthreads --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libx264 --enable-nonfree --enable-libvorbis --enable-libgsm --enable-libxvid --prefix=/usr/local
sudo checkinstall --fstrans=no --install=yes

lock the local version

sudo aptitude hold x264 ffmpeg nut

2. Use Thomer's mp4ize to do the rest.

mp4ize --iphone movie1.avi movie2.asf movie3.mpg

In this example, the output files will be named movie1.mp4, movie2.mp4, and movie3.mp4.

The script above is using xvid to encode the mp4 file. How does x264 behave? I don't know. Can I change the xvid in the script to x264 to test it? On the net, I found a post about how to use x264 with ffmpeg to encode files for iPod/iPhone:

-vcodec libx264 -vpre hq
default - x264 CLI default values
fastfirstpass - disables options unnecessary for first pass, recommend choice for first passes
normal - Dark Shikari’s Q55 preset
hq - Dark Shikari’s Q75 preset, recommend choice for single pass or the second pass of two passes
max - all options maxed out

More to play with!


Leave a Reply

You must be logged in to post a comment.