Convert any video file for an iPod
Problem
You want to use your fancy new Apple iPod Video, but you don't know how to convert video so it will play.Keywords
apple, ipod, linux, ffmpeg, convert, avi, mpg, mpeg, asf, video, 320x240, mp4, resolution, aspect ratio.Solution
Other people solved this problem, also. You can start out by reading some related pages.First, install some packages required to compile ffmpeg. Add the following to your /etc/apt/sources.list:
deb http://ftp.debian-unofficial.org/debian unstable main contrib non-free restrictedThen install some packages:
sudo aptitude install liba52-dev libdts-dev libgsm1-dev libvorbis-dev \
libxvidcore4 libxvidcore-dev libdc1394-dev libfaac-dev
You need to configure and install the latest version of ffmpeg as follows:(this worked for ffmpeg-0.cvs20070307)
./configure --enable-gpl --enable-pp --enable-pthreads \
--enable-libvorbis --enable-libogg --enable-liba52 \
--enable-libdts --enable-libgsm --enable-dc1394 \
--disable-debug --enable-shared --enable-xvid \
--enable-libfaac --prefix=/usr/local
make
sudo make install
Note that you may have to set LD_LIBRARY_PATH to
/usr/local/lib/ to run ffmpeg.
If you don't want to pollute your machine with manually compiled and installed software, you can build a modified package yourself, as follows:
sudo aptitude install debhelper quilt zlib1g-dev libsdl1.2-dev \
libfreetype6-dev libimlib2-dev texi2html \
libtheora-dev fakeroot
apt-get source ffmpeg
Now modify debian/rules (around line 9) such that:
confflags += --enable-libvorbis --enable-libtheora --enable-libogg \
--enable-libgsm --enable-xvid --enable-libfaac
Then create the package:
dpkg-buildpackage -rfakeroot -bThen install the resulting .deb files in the parent directory (you can skip the -dev packages, but they don't really hurt either):
sudo dpkg -i *.debAssuming your movie is called "some_movie.avi" and ignoring the aspect ratio, you can convert it to an mp4 file naively as follows:
# this messes up the aspect ratio!
ffmpeg -i some_movie.avi -f mp4 -vcodec xvid -maxrate 1000 \
-qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac \
-s 320x240 -ab 128 -b 400 some_movie.mp4
If you get an error, "Unknown codec 'xvid'", try changing "-vcodec xvid" to
"-vcodec libxvid". (The automatic script will try "xvid"
and "libxvid".)
If you get an error, "Unknown encoder 'aac'", try changing "-acodec aac" to "-acodec libfaac". (The automatic script will try "aac" and "libfaac".)
The only real thing to watch out for is, as mentioned, the aspect ratio. My iPod video comes with a 320x240 display. You can figure out the aspect ratio of an existing video file as follows:
ffmpeg -i some_movie.aviThere should be a line somewhere that sort of looks as follows:
Stream #0.0: Video: mpeg4, yuv420p, 624x352, 23.98 fps(r)The aspect ratio is the first number (before the 'x') divided by the second number (right after the 'x'). You need to adjust the height of the generated movie appropriately. Assuming an iPod with a 320 pixel wide display, the height can be computed as:
new_height = (320 / (movie_width/movie_height))You should compensate the height you lose (i.e., 240 - new_height) by padding it with black bars. Each bar gets (240 - new_height) / 2 pixels.
You can pass the desired width and height to ffmpeg using the -s parameter. You can also pass a -padtop and -padbottom flag to insert the black bars. For example, for a 16:9 movie:
# this maintains the proper aspect ratio for a 16:9 video
ffmpeg -i some_movie.avi -f mp4 -vcodec xvid -maxrate 1000 \
-qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac \
-s 320x180 -padtop 30 -padbottom 30 \
-ab 128 -b 400 some_movie.mp4
This ruby script does all of this automatically for you.
It figures out the aspect ratio of the movie you're trying to convert and
inserts the blacks bars at the top and bottom. If the movie is narrower than
it is high, it inserts the padding on the sides. You should use the script as
follows:
mp4ize movie1.avi movie2.asf movie3.mpg ...In this example, the output files will be named movie1.mp4, movie2.mp4, and movie3.mp4.
