Video with Linux

AVI files for MP4 Players using Linux

There are a number of portable MP4 digital media players that can play avi files encoded with Xvid and twolame using Linux. Since Xvid is one of the best MPEG-4 Part 2 ASP video encoders available, using Linux and the method described here will often give better results than the manufacturers transcoding software. This document explains how to encode avi files that can be played in the Iriver E100 MP4 Player, the Machspeed Zodiac Media Player, the Centon MP4 Player and a host of others.

Required Software

The software required is We will create an avi file with an Xvid encoded MP4 video track and a twolame encoded audio track. Make sure you have compiled mencoder with support for xvid and twolame. You may verify these encoders are available in your version of mencoder with the commands
$ mencoder -ovc help
$ mencoder -oac help
and then checking that the lines
   xvid     - XviD encoding
   twolame  - Twolame MP2 audio encoder
are present.

Cropping and Letterboxing

To be compatible with portable MP4 players we will create an avi file with a 15 frame per second deinterlaced 320x240 MP4 video stream and a 44.1Khz mp2 audio stream. Depending on whether the video source needs to be cropped or letterboxed we first set the environment variable rate.

If the video source file was intended to be played back on a traditional television then you need not crop or letterbox. In this case enter

$ rate="scale=320:240"
If your video source file was intended to be played back on a widescreen television you will need either to to letterbox or crop it. To letterbox it enter
$ rate="scale=320:180,expand=320:240'
and to crop it enter
$ ratio="scale=426:240,crop=320:240"
Some video streams come from film source with an original aspect ratio of 9x5. To crop a 9x5 aspect ratio movie that has been letterboxed for a widescreen television enter
$ ratio="scale=576:324,crop=320:240"

Encoding the File

After setting the environment variable rate as above encode the video
$ mencoder sounce.mpg -quiet \
    -ovc xvid -oac twolame -ofps 15 \
    -xvidencopts profile=sp3:bitrate=250 \
    -twolameopts br=64 \
    -vf harddup,kerndeint,$ratio,dsize=320:240 \
    -af resample=44100,volume=8,volnorm=2 -o output.avi

Copying the File to the Player

Most portable MP4 players act like a flash drive if the correct configuration option is set. Make sure this option is set and plug the portable MP4 player into the USB socket of the computer. The window managers in some Linux distributions automatically mount USB drives as they are detected. In this case things are easy, simply copy the file with your mouse and then use the window manager to unmount or eject the disk.

If the MP4 player is not automatically mounted then check the log files using

$ dmesg
to determine what device your player was detected as. Lets assume it was detected as /dev/sdb. Since the player was not automatically mounted it may be possible to mount and copy the files as root. Change to root and make sure the mount point /z/b exists.
$ su
Password
# mkdir -p /z/b

Some video players have a partition table and others do not. If your potable MP4 players has a partition table, mount the player using the command

# mount /dev/sdb1 /z/b
If you don't have a partition table, use
# mount /dev/sdb /z/b
Now copy the avi file over to the player and synchronize the buffers by
# cp output.avi /z/b
# sync; sync; sync
Finally unmount the drive
# umount /z/b
# exit
and unplug the portable MP4 player from the computer.

Put a line like

/dev/sdb1       /z/b            auto    rw,user,noauto  0       0
in /etc/fstab to allow regular users to mount and unmount the MP4 player as a flash drive. The rule is don't do things as root that could be done as a regular user.

Playing the File

Turn the player off and on once to ensure it recognizes the new file. Test the new video file. Note that I had sound synchonization problems with the Iriver Player until I updated its firmware.
Last Updated: Wed Jul 15 00:41:06 PDT 2009