Seriously, this is a very non-trivial process. Even commercial packages have real problems doing this right every time. Part of the problem is that both AVI and MP4 are not Video formats, they are Container file formats which hold both audio and video streams - and these can be in a range of different video types - AVI does not support all the stream types that MP4 does, and so you sometimes have to transcode the streams as well as change the container format. And that depends on having the right codecs installed on your PC (another true PITA sometimes).
There is at least one open source video converter which may be able to help you:
Handbrake[
^] (allthough I don't like it that much as an application and tend to use Freemake instead, which is free, but not open source)
Looking at how Handbrake does it may help you at least understand the complexity of what you are getting into! :laugh: