Patch by James Darnley <james darnley at gmail>. Originally committed as revision 22605 to svn://svn.ffmpeg.org/ffmpeg/trunk