Don't! :laugh:
They do exist:
http://video-converter.winavi.com/[
^] and re-inventing the wheel is never fun.
Or you could look at VirtaulDub or VirtualDubMod as these are open source.
It is a lot of work, for little reward. You might be better off buying in a working solution (the WinAvi one is pretty good indeed and not that expensive - especially compared to your time)