Check dimensions to avoid division by zero due to invalid new dimensions.
Partially fixes http://bugzilla.mplayerhq.hu/show_bug.cgi?id=773.

Originally committed as revision 8321 to svn://svn.ffmpeg.org/ffmpeg/trunk
