Patch by Eli Friedman <eli.friedman at gmail dot com>. Originally committed as revision 25022 to svn://svn.ffmpeg.org/ffmpeg/trunk