Converting Video Files for iPod/iPhone/iPad

Posted on In Linux, Software

We usually have video files in .wmv .mpg .rmvb or .mkv formats. The iPod, iPhone or iPad only accept a limited number of video file types, such as .mov and .mp4. To play these video files in .wmv .mpg or .rmvb format, we should first convert them to .mov or .mp4 files that can played by iTune or other video players on these Apple devices that use the same codec engine. We may possibly convert video files for iPod or iPhone with mplayer/mencoder but it may have some problems, such as the audio and video do not synchronize very well for some videos.ffmpeg can convert video files from various formats to others and most of the time ffmpeg works very well. This post introduces how to convert the video files in common formats (.wmv, .mpg, .rmvb, .mkv, .etc.) to .mp4 format for iPod/iPhone/iPad.

Install ffmpeg

First, we should install the ffmpeg package. The Fedora Linux does not include ffmpeg in its repository for some reasons but the RPM Fusion repository provides it for us. To install the ffmpeg package, [[go:enable-rpmfusion|add RPM Fusion repository first]].

The install the ffmpeg package:

# yum install ffmpeg

Convert video file format with ffmpeg

The basic command to convert video file input.wmv to onput.mp4 is as follows.

# ffmpeg -i input.wmv -strict -2 output.mp4

Or other format (such as .mov) by:

# ffmpeg -i input.wmv -strict -2 output.mov

ffmpeg determines the output video’s format by its file name extersion.

Convert video file format with ffmpeg for iPod/iPhone/iPad

The files in .mp4 format can be played on Apples devices. The iPod/iPhone/iPad have specific resolution, so we need to to convert the video files to a very high resolution since the devices can only display a limited one. We use the iPod generation 2 as the example, its screen resolution is 480×320. Hence, we can only convert the video to this resolution for smaller video file size. Similarly, the bitrate can also be set accordingly. The default one of ffmpeg (200 kb/s) is too low. To improve the quality of the converted video, we can set it to a larger one.

One good configuration for me is:

# ffmpeg -i input.wmv -s 480x320 -b 1000k -strict -2 output.mp4

-s sets the frame size of the video. -b sets the bitrate of the video.

Convert video file format with ffmpeg for iPod/iPhone/iPad in one command

More conveniently, we can form this command to a script convert2mp4.sh:

#!/bin/bash
ffmpeg -i $1 -s 480x320 -b 1000k -strict -2 /tmp/$1.mp4

Each time to convert a video file video.wmv, we can simply run:

$ convert2mp4.sh video.wmv

and the converted file is /tmp/video.wmv.mp4 after the script finishes.

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

4 comments

    1. Sems ffmpeg is developed quite actively with version 1.0 just released. What’s the benefit from moving to avconv. From its description, seems avconv is faster?

  1. Thanks, tested many ffmpeg posts on many sites, none of them worked.
    The one you posted works like a charm, well done.

Leave a Reply

Your email address will not be published. Required fields are marked *