My previous version has flaws. It works well for opaque GIFs, but OpenCV is famous for not being good with transparent images. So instead of OpenCV I use imageio for GIF iteration and PIL for adding GIF frames to the static background.
Why do more?
The original algorithm left these artifacts, look at the cyan block on the intersection of GIF frame and a darker abstract part:
