patch by baptiste based on reverse engineering work by chrono. Originally committed as revision 15618 to svn://svn.ffmpeg.org/ffmpeg/trunk