backport r23083 by michael Originally committed as revision 23214 to svn://svn.ffmpeg.org/ffmpeg/branches/0.6