1. Andrew's Corner :

Encoding Video for the iRiver X20

Recently I acquired an iRiver X20 which I have been using to store my music collection in Ogg Vorbis format. This little player also does a fairly spectacular job playing movies, despite having only a 320:240 screen, so I set myself the task of converting my DVD movies to a suitable format for such a player and such a screen. I quickly found that the Internet was littered with misinformation and so I have battled through with my two best friends Trial and Error until I succeeded. This small page contains the techniques that I eventually used and it is my hope that any readers will either profit by my example or email me to suggest where I could improve this technique.

Technical Specifications

There are many different iRiver media players and it seems obvious to me that many people have been copying and pasting encoding "recipes" suitable to a particular player and claiming some sort of universal recipe. My point is that the technique I will describe here is suitable for this iRiver device and should be modified to use with a different player. For the record I include some specifications of the iRiver X20:

iRiver X20 Specifications
Excerpts from the iRiver X20 datasheet.
Display 2.2inch QVGA TFT LCD (320x240)
Video Support MPEG4 SP, WMV SP / 320x240 / 15-30fps / Video Bitrate:32-512kbps / Audio Bitrate:8-320kbps
Audio Support MP3 : 5kbps ~ 320kbps / WMA : 8kbps ~ 320kbps / OGG : Up to Q10
Playback Time 22 hours (MP3, 128kbps, 44.1kHz,EQ Normal, Vol 20, LCD Off)
6 hours (avi, 320x240@30fps, video : 512kbps, Audio : MP3, 128kbps, 44.1kHz)
Capacity 2GB, 4GB, 8GB
Headphone Output 13mW + 13mW

It really is made for music playback not video playback with that tiny screen, and before you get your calculator out I will tell you that 320x240 is a 4:3 ratio screen as well. So I would definitely not recommend watching a feature movie on this screen, perhaps extracts from DVDs, home movies and the like?

To encode the video I am using MEncoder dev-SVN-r26028-4.1.2 and the latest stable release of xvid: 1.1.3. Both of these I have compiled myself on the Linux distro Slackware 12, if you have only Windows at your disposal you have my sympathy.

Encoding the Video

For this example I am encoding one of the great fight scenes from the Matrix Reloaded. In this scene Neo takes care of many of the bodyguards of the Merovingian. I am using 2-pass encoding and the first pass goes like this:

$ mencoder -v \
        dvd://1 -chapter 20-20 -alang en \
       -ovc xvid -xvidencopts pass=1:vhq=4:trellis:max_bframes=0 \
       -vf scale=320:240,expand=320:240,harddup \
       -ofps 30 \
       -oac copy \
       -o /dev/null

Those who have read this page before will note that I have developed this first pass a little. I have cautiously added a few more xvid options and finally realised that it is a waste of time encoding sound on the first pass. My experiments with cropping the movie for the iRiver were a little disastrous as I have not been able to rescale for the little screen without distortion. But now for the second pass:

$ mencoder -v \
        dvd://1 -chapter 20-20 -alang en \
       -ovc xvid -xvidencopts pass=2:vhq=4:trellis:bitrate=512:max_bframes=0 \
       -vf scale=320:240,expand=320:240,harddup \
       -ofps 30 \
       -oac mp3lame -lameopts mode=0:cbr:br=128 \
       -af resample=44100:1:2 \
       -o matrix.avi

The video bitrate is added in (video bitrate is ignored on the firsat pass of 2 pass encoding) and the sound options are added in. These options are severely constrained by the requirements of the iRiver. Playback is perfectly acceptable unless like me you are a purist and you think " What if I try ... "

Some more work needed...

There are some areas that still need working on and I am more than happy to hear advice from the many people more skilled in this area than myself:

  1. Cropping: I can work out the correct cropping needs using -vf cropdetect but I cannot work out the correct scaling to avoid distortion. The effect will be the same, with top and bottom black bands, but the encoding will be more efficient.
  2. Sound: This has a slight echo quality about it that is not present on the demonstration videos that come with the iRiver X20. So, some work to do here.
  3. Video quality: The options I have added to xvidencopts have made a big difference but since I have a specific device in mind I would like to experiment with some lighting filters.

Are you a mencoder guru with an iRiver X20 and some great ideas? I would love to hear from you! And if you have absolutely no idea about mencoder and you have an iRiver X20 please feel free to profit by my hours of experimentation and copy and paste my work!

And in conclusion ...

I have found immense enjoyment in writing this page and my pleasure will be redoubled if you have profited by any of the material on this page. Send me an email and let me know! Importantly I am still having a great and productive time in the world of Linux and I feel as if I have joined a community and am contributing to it. What about you?