rewrite it for greater clarity in the process. Originally committed as revision 18185 to svn://svn.ffmpeg.org/ffmpeg/trunk