backport r23273 by banan Originally committed as revision 23356 to svn://svn.ffmpeg.org/ffmpeg/branches/0.6