Encoding videos for iPhone

Many handheld devices such as the iPhone are now able to read videos. However, it is often required to reencode your videos in order to watch them on these constrainted devices videos.

In this tutorial I explain how to reencode a video with Datura in order to watch it on the iPhone.

New project, add input file(s)

First of all, create a new project in Datura (File, New). Then, drop your input files or click on "+". For the purpose of this tutorial, we suppose to have a single AVI file that contains one video stream (DivX) and one audio stream (MP3), and we want to produce a high quality video watchable on the iPhone.

Define output file

In the project window, click on the second icon in the toolbar called "Output". Set the output file by clicking the button "Choose" or by manually typing the path and name. iPhone videos normally have the extension m4v. If you choose another extension, you have to manually select the "iPod H.264 MP4 format" Muxer in the list. Be careful, if you do not use the m4v extension, iTunes could refuse to transfer it to your iPhone.

Define the video stream

Select the "Video" tab. Click on "+" to add a video stream. In the bottom part of the window, select the video input stream that will be used to produce this new stream. Then, select the "libx264" encoder in the list and click on "Tune". In the new window, select quality "hq" and profile "ipod640". If you plan a two-pass encoding, you can tune the first-pass parameters (slow for better quality). Close the "X264 parameters" window.

Now is the critical part: width, height, aspect ratio, bitrate and framerate of the video output stream. The IPhone supports videos up to 640x480, 1500 kbits/s, and 30 frames per second. If the size of your input video is below the maximum supported, just leave the blank the fields widht and height and Datura will not modify the original size. If your input video is too wide or too tall, enter width and height with respect to the original input ratio (new width/height ratio must be simply be the same as the ratio of original values). Then, set the bitrate and frame rate. In the same way as video size, if your input values are below maximum values, just let these fields blank, otherwise enter the maximal supported values.

Define the audio stream

Select the "Audio" tab. Click on "+" to add an audio stream. In the bottom part of the window, select the audio input stream that will be used to produce this new stream. Then, select the appropriate encoder, "Advanced Audio Coding". IPhone supports audio streams up to 160 kbits/s, 48000 Hz, two channels. If corresponding values for your input stream are below these values, just leave these fields blank, otherwise enter maximal supported values.

Launch the muxing

In the "Parameter" tab you can adjust the number of threads used for encoding to speed up encoding according to your computer. You can safely use two threads since most Intel Mac are dual core. If your computer has more core, set the number of threads used to the number of cores your computer has. You can now click on "Encode" to launch the muxing process. The "Operations" window then opens with your job queued. Simply click on "Start" icon to launch the process. When encoding is finished, simply drop the resulting video on iTunes. Enjoy !