avi to cd — avi trim, avi to iso, iso to cd with cdrecord 

Have you ever come across an AVI file which is just a few megabytes too large to fit on a CD or a DVD? Well I have… and in this post I'll go over a crude solution to this problem. That is, I'll assume that the very end of the AVI file is not that important and I'll simply trim it off. Of course, an alternate solution is to re-encode the file at a lower bit-rate. However, trimming seems just so much simpler.

So, lets say we want to get rid of trailing 32 MB of a 731 MB AVI file: video.avi. To achieve this we can use shell`s head command as follows.

head --bytes=-32m video.avi > trimmed.avi

Now lets compare the sizes of video.avi and trimmed.avi using the following command.

du -sh video.avi trimmed.avi

Here is the output of the above command.

731M    video.avi
699M    trimmed.avi

So that worked great. However, by trimming the AVI file we broke its internal index and we are left with a more or less raw AVI stream. You can still play it in mplayer like so:

mplayer -fs -zoom trimmed.avi

But you no longer can seek inside it, i.e. it is not possible to seek forward or backward. If you do try to seek then mplayer will produce the following error message.

Cannot seek in raw AVI streams. (Index required, try with the -idx switch.)

You could give mplayer the suggested -idx switch, like so

mplayer -fs -zoom -idx trimmed.avi

The mplayer would then rebuild the index on the fly before playback. This is instant on current CPUs, but can be quite slow on older hardware. It is also possible to fix the indexing permanently in the trimmed file using mencoder as follows.

mencoder -idx trimmed.avi -oac copy -ovc copy -o fixed.avi

Now forward and backward seeking works just fine. Ok, lets create an ISO image containing the AVI file. This is done using the following command.

mkisofs -r -o video.iso fixed.avi

Last step is to burn the ISO to a CD. This can be done in many ways, I'll use a shell tool: cdrecord. If you prefer to work with GUI apps then try K3b. With cdrecord I'll have to locate my DVD+-RW device identifier first before burning the CD. The following command is used for this purpose.

cdrecord -scanbus

Here is the fragment of the output that is of interest to us.

        2,0,0   200) 'HL-DT-ST' 'DVD+-RW GSA-H73N' 'B103' Removable CD-ROM

Now, the following command is used to burn the ISO image to a CD.

cdrecord -v dev=2,0,0 video.iso

Here is a quick summary of steps involved in trimming an over-sized AVI file and burning its ISO to a CD.

head --bytes=-32m video.avi > trimmed.avi
mencoder -idx trimmed.avi -oac copy -ovc copy -o fixed.avi
mkisofs -r -o video.iso fixed.avi
DEVID=`cdrecord -scanbus 2>/dev/null |grep 'DVD.*RW' |awk '{ print $1 }'`
cdrecord -v dev=$DEVID video.iso


Did you find the above information useful and interesting? If so, please support this site by using the blog directory links at the bottom of this page. Thanks for your support!

If you have any Linux related problems or questions then please feel free to post them on our Linux Forums: http://linux.dsplabs.com.au/forums.

VPS Hosting Referral Code DZZCC3

Add me to Technorati Favorites Vote for me on Blog Catalog

One Response to “avi to cd — avi trim, avi to iso, iso to cd with cdrecord”

  1. Mike Says:

    Thank you! Helped me out very much.

Leave a Reply