Patch by David Conrad <lessen42 gmail com> and myself. Originally committed as revision 23719 to svn://svn.ffmpeg.org/ffmpeg/trunk