Fixing an AVI index with mencoder
This is more a “note to self”, but I’m sure others find it useful as well.
Quite often I run across AVI files with a broken index. That index is used in media players to seek rapidly in the movie file. Without an index or with a corrupt index, seeking either does not work at all or takes a long time.
mencoder, which is available on almost any platform, allows you to massage AVI files besides tons of other operations on a never-ending list of video formats.
Here’s the command to repair a broken AVI index (I used the mplayer/mencoder version that comes with the FreeBSD ports collection):
$ mencoder -idx in.avi -ovc copy -oac copy -o out.avi MEncoder 1.0rc2-4.2.1 (C) 2000-2007 MPlayer Team CPU: Intel(R) Pentium(R) 4 CPU 3.60GHz (Family: 15, Model: 4, Stepping: 10) CPUflags: Type: 15 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1 Compiled with runtime CPU detection. success: format: 0 data: 0x0 - 0x2aea0000 AVI file format detected. [aviheader] Video stream found, -vid 0 [aviheader] Audio stream found, -aid 1 AVI: Generated index table for 332070 chunks! VIDEO: [XVID] 640x272 12bpp 23.976 fps 994.0 kbps (121.3 kbyte/s) [V] filefmt:3 fourcc:0x44495658 size:640x272 fps:23.98 ftime:=0.0417 videocodec: framecopy (640x272 12bpp fourcc=44495658) audiocodec: framecopy (format=55 chans=2 rate=48000 bits=0 B/s=17579 sample-0) Writing header... ODML: Aspect information not (yet?) available or unspecified, not writing vprp header. Writing header... ODML: Aspect information not (yet?) available or unspecified, not writing vprp header. Writing index...81f (99%) 7391.58fps Trem: 0min 690mb A-V:0.047 [993:140]] Writing header... ODML: Aspect information not (yet?) available or unspecified, not writing vprp header. Video stream: 993.962 kbit/s (124245 B/s) size: 628485708 bytes 5058.428 secs Audio stream: 140.323 kbit/s (17540 B/s) size: 88735536 bytes 5058.936 secs $ |
You guessed it right: “in.avi” is the broken file and “out.avi” is the repaired avi-file. The whole operation took a few seconds on this 700MB file.
January 30th, 2010 at 2:06 pm
Useful, thank you 🙂
February 16th, 2010 at 6:04 am
[…] Fixing an AVI index with mencoder | kahunaburger […]
February 22nd, 2011 at 7:42 am
Works perfectly. I created >4GB AVI files containing HuffYUV raw footage using vlc stream capture only to find the indexes were missing. Your instruction works perfectly. VLC frontend failed to fix such large files but this simple solution works without a problem. Avidemux reports a clean file afterwards.
Thankyou.
February 22nd, 2011 at 12:12 pm
Talking of >4GB files. I’ve just captured a 1h50m avi in HuffYUV for editing in kdenlive. The file is a 64GB avi and the solution described here does work. It takes around 35 mins to fix on my AMD64x2. Kdenlive handles the large file without a problem for those who might be interested.
September 1st, 2011 at 4:26 pm
This is great, just what I was looking for! Thanks 😀
January 21st, 2012 at 3:12 pm
You saved me! 😉
February 17th, 2012 at 11:56 pm
thanks a lot!
February 20th, 2012 at 11:57 am
Thanks! For an XVID, MEncoder Sherpya-SVN-r34401-4.6.2 did the trick resyncing (“Incomplete stream? Trying resync.”), where VLC and DivFix++ failed (video broken after 30 min).
Audio seems to be in sync now, no lag, no skipped scenes.
MEncoder does not seem to be part of newer releases of MPlayer, but I found it at http://oss.netfarm.it/mplayer-win32.php
July 22nd, 2015 at 10:04 am
Hi, thanks for this useful post. Can anyone suggest a modified version of this command to parse and fix several .avi clips in one folder at the same time?
Thanks and regards.