backport r23065 by mstorsjo Originally committed as revision 23190 to svn://svn.ffmpeg.org/ffmpeg/branches/0.6