based on patch by Graham Booker <ffmpeglist at cod3r com> Originally committed as revision 5722 to svn://svn.ffmpeg.org/ffmpeg/trunk