Initial patch by Benjamin Larsson. Originally committed as revision 9046 to svn://svn.ffmpeg.org/ffmpeg/trunk