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