I got inspired to finally write this up after seeing the discussion today about Apple's use of a similar technique.
Code is available at https://github.com/sublimehq/anim_encoder, although you'll undoubtedly need to do some wrangling to use it for your own projects.