Patch by Anton Khirnov (gmail{wyskas}). Originally committed as revision 21653 to svn://svn.ffmpeg.org/ffmpeg/trunk