How to apply motion compensation on burst JPEG images with C++ or Python code?

How can I implement motion compensation on a sequence of JPEG images captured in quick succession, is there any way to reduce the discrepancies between these images, which were taken in a burst mode, by applying motion compensation technology?
I’m searching for an efficient way to achieve this, ideally leveraging existing tools or libraries. Is there available code, perhaps in C++ or Python, that is specifically designed for this task? In short, I’m interested in understanding the principles behind motion compensation and how it can be effectively applied to JPEG images to enhance their consistency.