backported r18640 by michael Originally committed as revision 21712 to svn://svn.ffmpeg.org/ffmpeg/branches/0.5