If I were going to attempt to write the software I would create a buffer along the edges of the image like a picture frame, and crop the image. I would compare each frame to the one before it and look for closely matching pixels and try to line up the two frames by shifting them up/down/left/right in the opposite direction of the motion. This may be a completely wrong approach, and I suspect that modern software is a lot more sophisticated than this.