Based on patch by Michael Kostylev <mik at it-1 dot ru> Originally committed as revision 16490 to svn://svn.ffmpeg.org/ffmpeg/trunk