for both RV3 and RV4, so move it into common code. Originally committed as revision 15786 to svn://svn.ffmpeg.org/ffmpeg/trunk