x264 has two early termination conditions to speed up macroblock mode decision: * Some modes can be discarded without even running a motion search. For this pass, the "cost" of a mode is defined to be SATD+lambda*bits. First we evaluate P16x16ref0. If it ends up equal to the P-Skip mv and with sufficiently small residual, then assign this macroblock to be P-Skip and avoid any further analysis. Then we evaluate P16x16 and P8x8 with all reference frames. We can estimate the cost of P16x8 modes as being equal to the SATD of P8x8 + half the mv bit cost of P8x8. If this estimate is worse than the known cost of P16x16, then skip P16x8, otherwise search it using only the reference frames chosen for the 2 colocated 8x8 partitions. Search P4x4 only if P8x8 is the best mode known so far. Decide whether or not to search P8x4 using the same method as P16x8. Then we search the intra modes, with I16x16 first. The selection of intra directions is decided by SATD0, as above. If none of the neighboring macroblocks used intra, and I16x16 is much worse than the best inter mode, then skip the other intra modes. Otherwise search I8x8 and I4x4. * Now we refine the mode decision using RD. Discard any mode whose SATD0 is more than a threshold above the best mode's score, and compare the remaining modes by exact RD scores. The threshold is unlimited in I-frames, 25% in P-frames, and 6% in B-frames. * Now we refine the motion estimation or intra direction for the final selected mode, using RD. In inter blocks, run the same subpel diamond as before, but now with RD instead of SATD. As with the RD mode decision, a threshold (6%) is applied to the SATD0 scores before RDing each mv. In intra blocks, the thresholds are 12% for I16x16, 37% for I8x8, and unlimited for I4x4 (because it costs more time to keep track of 4x4 SATD scores than we save in reduced RD calls).