Patch by Anton Khirnov <wyskas gmail com>. Originally committed as revision 22033 to svn://svn.ffmpeg.org/ffmpeg/trunk