Another way is slightly different from some code.
I manage to do this with PhantomJS and its screenshot function.
Basically, you access your animation through a browser without a title and continue to take screenshots until the animation ends. You can have a global var to indicate whether the animation is complete or not.
If you have screenshots, just use FFMPEG to generate the video.
A simple example:
PhantomJS:
var running; var c = 1; var intervalId = setInterval(function(){ running = page.evaluate(function(){ return window.RUNNING }); if (running) { console.log('still running: ', running); page.render('temp/screenshot'+c+'.png'); } else { clearInterval(intervalId); console.log('still running: ', running); phantom.exit(0); }; c++; }, 100);
Using FFMPEG you can:
ffmpeg -y -r 25 -i temp/screenshot%01d.png -c:v libx264 -r 25 -pix_fmt yuv420p video.mp4
Where 25 - FPS (frames per second), which you can configure as needed.
I hope this can be helpful to someone.
source share