Patch by Vladimir Voroshilov and myself. Originally committed as revision 21125 to svn://svn.ffmpeg.org/ffmpeg/trunk