based on patch by Matthieu Castet <castet dot matthieu at free dot fr> Originally committed as revision 4220 to svn://svn.ffmpeg.org/ffmpeg/trunk