Partially fixes issue 1758. Originally committed as revision 23005 to svn://svn.ffmpeg.org/ffmpeg/trunk