For encoding videos, motion compensation (MC) is a very important step. In MC, we wish to encode the current frame exploiting the redundancies present be the current and the previous frame.
First, the current frame is divided into equal sized blocks, then we search for each of those blocks exhaustively over the last frame and find the one that matches it most closely. However exhaustive search is time consuming. If we assume that motion is small between frames, we can limit our search area to a region around the current block. This makes the algorithm faster. Once motion estimation is done, the motion vectors (vectors pointing to the location of the closest match block in the previous frame) and the error can be sent. The code is available here.
We try MC with block size of 8 and 16 and search window of 32 and 64. Thus (8,64) means block size 8 and search window 64. The two frames are shown below
Previous frame
Current frame
Motion vectors (marked blue) for (8,32), (8,64), (16,32) and (16,64)
Compensated errors for (8,32), (8,64), (16,32) and (16,64)
Non-compensated errors (direct difference) for (8,32), (8,64), (16,32) and (16,64)
Reconstructed frames for (8,32), (8,64), (16,32) and (16,64)
The reconstruction errors and time taken for the 4 modes are:
The uncompensated error is 0.0140
Next we study the foreman sequence
Previous frame
Current frame
Motion vectors (marked blue) for (8,32), (8,64), (16,32) and (16,64)
Compensated errors for (8,32), (8,64), (16,32) and (16,64)
Non-compensated errors (direct difference) for (8,32), (8,64), (16,32) and (16,64)
Reconstructed frames for (8,32), (8,64), (16,32) and (16,64)
The reconstruction errors and time taken for the 4 modes are:
By contrast, the uncompensated error is 0.008
We observe the following trends: