The basic idea of motion compensation is to find the parts of each frame that have moved or changed from the preceding frame and code only the changes, called 'residuals'. Each frame is then built by adding the decoded residuals to the prediction based on the previous frame. The previous frame predicts the next frame except for places where something has changed or moved. These frames are called P-frames.
The previous frame is searched with each block of the current frame(block matching). If a match is found, the location of the block (motion vector) in the previous frame is coded. A trail predicted frame is then built by moving blocks from the previous frame using the motion vectors. The predicted frame is subtracted from the actual current frame to make the residual image, which is then coded for transmission. So two things are encoded: motion vectors and residual image. At the receiving end, the process is reversed: the predicted frame is built from the previous frame (from the motion vector), the residual image is decoded and added tot he predicted frame.
The frame prediction has two problems:
- If an error occurs in one frame, it will happen to future frames.
- when you want to edit the video in some frames, you cannot get the whole frame.
Both problems are solved by periodically sending a full frame that is not a prediction of the previous one. Such full frames are called intracoded (I-frames).
B-frame(bidirectional) use bidirectional interpolation between two frames. It provides the most compression, but requires the most processing and most complex decompression.
Motion estimation: the process of finding the best match and generates the motion vectors that determine how each motion compensated prediction frame is crated from the previous frame. Search an area in the previous frame to find a 'matching' MxN sample region: comparing the MxN block in the current frame with some or all of the possible MxN regions in the search area (usually a region centered on the current block position) and finding the region that gives the best match.