I have a whole bunch of short avi files (not sure what format they actually are, but the extension is .avi) and needed to join them together quickly and easily so the 3 year old could watch some TV without bothering me every 5 minutes to start the next one 🙂 This post shows how to do this from the command line with the cat and mencoder commands
Get mencoder
It looks like you can download mencoder as part of the mplayer package here, but I’m not really sure about that. I use the PS3 media server app which includes mencoder so I used that.
Concatenate the files
Open up Terminal (Applications -> Utilities -> Teminal) and use the “cat” command to join the files into one great big file. Let’s say the files are in your Downloads folder, they’re all named something.avi and there are no other .avi files in the folder. Do this:
cd ~/Downloads
cat *.avi > combined.avi
They’re now in one big file, but if you play the combined media file it will only play the first video in it. That’s because there’s header information which tells the media player it’s only X minutes long, so it will stop playing then. We need to use mencoder to fix the header.
Use mencoder to fix the file so it plays them all
So for me, mencoder is at /Applications/PS3 Media Server.app/Contents/Resources/Java/osx/mencoder Unless you use PS3 Media Server then it’ll be somewhere else. I’ll leave it up to you to work out where it is…
Replace “mencoder” in the following command with the full path to your mencoder. If there are spaces anywhere in the path, you need to put quotes around it. So for me, mencoder = ‘/Applications/PS3 Media Server.app/Contents/Resources/Java/osx/mencoder’
mencoder -forceidx -oac copy -ovc copy combined.avi -o fixed.avi
combined.avi is the name of the combined file we created at the “cat” step above. fixed.avi is the name we want to name the final file that works. Change that to the actual name.
ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
As mencoder writes the file it will show a percentage counter. I’ve found once it gets to 100% you start seeing stuff like this:
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.
Pos:2868.0s71702f (100%) 4195.31fps Trem:0min 565mbA-V:0.000 [1523:128]
Skipping frame!
Pos:2868.1s71703f (100%) 4195.37fps Trem:0min 565mbA-V:0.004 [1523:128]
At this point, as far as I can tell, it will do this forever. Just hit Control + C to cancel. The file (named combined.avi in my example above) is there and works from my experience.
Voila, all done! Enjoy your joined video!!