How does MP4 encoding work?

I am curious on how MP4 files are encoded and why is it that I can
only play my MP4 files in ITunes ? Obviously there is some protection
involved, but it has aroused my curiosity of how it works. Are there
ruby gems to read MP4 files ?