A free library called FFMpeg makes this possible for us.
If you wish to encode to MP4, you'll need the help of the following additional libraries:
http://www.videolan.org/developers/x264.html
http://www.audiocoding.com/faac.html
Linux Installation
Note: This procedure will not apply to all distributions, you may need to adjust.
Libx264:
./configure –disable-asm
make
make install
ldconfig
LibFAAC:
./configure –enable-shared
make
make install
ldconfig
FFMPEG
./configure –enable-libfaac –prefix=/usr/sbin/ffmpeg –enable-nonfree –disable-yasm –enable-libx264 –enable-gpl
make
make install