How to convert a video to Itunes

Why is it so hard to find a free/effective solution to convert video to Itunes (H.264/MPEG-4 AVC)
Most paying solution are just limited GUI linked to FFmpeg & they charged 30$ for that.

I explain here how to install FFmpeg on a Mac OS X Snow Leopard,
and how to use it to convert divx movie for an Ipad.

The document is split in 5 parts:

Xcode/MacPorts

MacPorts is an easy to use system for compiling, installing, and managing open source software.
We will use it to install FFmpeg.

But first, we have to install Xcode, Macports will need it.

Xcode

Macports

We can install Macports!

Now, if you type “xterm” in Terminal, ou should see this

And the command “port” is avaible.

If you need more info, the Macports documentation is here

Update Macports

We have to update the MacPorts ports repository.

in a terminal, type: (you may have to give your admin password)

sudo port selfupdate

Password:
—-> Updating the ports tree
—-> Updating MacPorts base sources using rsync
MacPorts base version 1.9.1 installed,
MacPorts base version 1.9.1 downloaded.
—-> MacPorts base is already the latest version

The ports tree has been updated. To upgrade your installed ports, you should run port upgrade outdated

Install FFmpeg

Now, we are ready to install FFmpeg.

in a terminal, type: (you may have to give your admin password)

sudo port install ffmpeg


—-> Computing dependencies for ffmpeg
—-> Dependencies to be installed: XviD bzip2 dirac cppunit faac autoconf help2man gettext expat libiconv gperf ncurses ncursesw p5-locale-gettext perl5 perl5.8 m4 automake libtool faad2 gmake lame libogg libsdl xorg-libXext pkgconfig xorg-libX11 xorg-bigreqsproto xorg-inputproto xorg-kbproto xorg-libXau xorg-xproto xorg-libXdmcp xorg-util-macros xorg-xcmiscproto xorg-xextproto xorg-xf86bigfontproto xorg-xtrans xorg-libXrandr xorg-randrproto xrender xorg-renderproto libtheora libvorbis libvpx yasm schroedinger orc speex texi2html x264 zlib
—-> Fetching XviD
—-> Attempting to fetch xvidcore-1.2.2.tar.bz2 from http://lil.fr.distfiles.macports.org/XviD
—-> Verifying checksum(s) for XviD
—-> Extracting XviD
—-> Applying patches to XviD
[...]
—-> Extracting ffmpeg
—-> Applying patches to ffmpeg
—-> Configuring ffmpeg
—-> Building ffmpeg
—-> Staging ffmpeg into destroot
—-> Installing ffmpeg 0.6_2 ---> Activating ffmpeg 0.6_2

*******

  • This build of ffmpeg includes nonfree code as follows:
*******
  • libfaac
*******
  • The following libraries and binaries may not be redistributed:
*******
  • ffmpeg
  • libavcodec
  • libavdevice
  • libavfilter
  • libavformat
  • libavutil
*******
  • To remove this restriction use variant +no_nonfree
*******

—-> Cleaning ffmpeg

FFmpeg is now installed :)

Convert a video to MPEG4

FFmpeg options

to encode a video in another format, the command is

ffmpeg -i movie.avi test.mp4

you can choose the audio & video codec with options -vcodec & -acodec
to see a list of availables codecs, type

ffmpeg -formats

to make my test, I add those 3 options:

-ss 00:10:00 -t 60 -y

FFmpeg will read from the 10th to the 11th minute. -y means it will overwrite the output file.

you can also get a description of the current video file:

ffmpeg -i video.avi

FFmpeg has lots of options, here’s a link to the complete doc

Ipad

the Ipad needs an H264 video up to 1024×728 (or 720p) at 30fps with AAC sound at 160Kbps, 48kHz.

there is several way to encode a video with ffmpeg, I decided to use the quality-based encoding (-crf option).
(to avoid a 2-pass encoding & it gets better result than a constant bitrate)

for FFmpeg, it becomes:

ffmpeg -i video.avi -r 30 -vcodec libx264 -acodec libfaac -threads 0 -ar 48000 -ab 128k -ac 2 -y -crf 21 -vpre default Ipad.mp4

if you want a faster encoding, you can change the vpre option: “-vpre fast” for example.
but it will make bigger file & will increase the bitrate. But the quality will stay the same.
(with superfast & ulrafast, the quality decrease)

To improve or decrease the quality, you can change the option crf. 18 will give a better result, 25 a less good result.
If you increase quality, the encoding time will increase & the file size too.

IpadConverter script

I wrote a little script to do this encoding automatically.
You can download it here: IpadConverter.command

Just copy the script in your Movies directory.
Run it a first time, it will create 2 directories: IpadConverterIN & IpadConverterOUT

To convert one or more video, move them in IpadConverterIN & run the script.
It will convert each video, push the mp4 version into Itunes and then move the original file to IpadConverterOUT.

Others alternatives

Airvideo

Airvideo will stream your video from your mac to your iphone/ipad.
It can encode them on fly or you can pre-encode them.

the quality is really good & you have access to all your Mac’s movies but

for me, it’s more complicate than a ffmpeg encoding.

CineXPlayer

It’s a Divx player for the IPad.

it seems perfect, but