Maybe I missed something, but the .webm file seemed to me to have better quality than .ogv. So I think it’s enough to support two formats only: .mp4 for Chrome and .webm for Firefox. By the way, in my test the input file (.mp4) had the best quality and smallest filesize, but again, I may miss something.

Problem

Solution

What is PhantomJS?
“PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.” (source)

How to install PhantomJS?
Follow the instructions here. Under Ubuntu I compiled it from source to get the latest version. Note that it takes a lot of time (about 30 minutes). Under Manjaro I could install it via yaourt and it took 1 minute (and got the newest version). The good news is that installation is not a problem.

How to take a screenshot?
If you download the source, you get a lot of example scripts. One of them is called rasterize.js, and this is exactly what we need.