based on a patch by Stefano Sabatini Originally committed as revision 18725 to svn://svn.ffmpeg.org/ffmpeg/trunk