Some time ago, someone posted a link walking through writing their own H261 encoder. Unfortunately, I haven't been able to find the post again, but it helped a ignite a huge interest in media codecs. These are some good notes I found which walk through the key "tricks" leveraged by the JPEG/MPEG image formats to compress raw pixel data effectively.