Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering HTML5 animation server-side?

We are creating animations using HTML5 + Javascript. Now, we'd like to convert these animations to video files (MPEG4, or other, doesn't matter) so that browserly challenged people could also see the animations. Animations contain an audio track.

We are looking for solutions where HTML page would be rendered and recorded on the server side. I know there exist tools for rendering web page thumbnails etc. static images already. However, in our use case we should output a video file.

What options are there? Is headless X server + Firefox a way to go? Preferably we'd be running this in a cloud (Amazon EC2).

Also if there something special we'd need to think when playing animation in non-real-time speeds, I'd like to hear - e.g. syncing HTML5 audio with animation.

like image 357
Mikko Ohtamaa Avatar asked Apr 27 '11 14:04

Mikko Ohtamaa


People also ask

Is server-side rendering faster than client-side rendering?

Server-side rendering allows developers to pre-populate a web page with custom user data directly on the server. It is generally faster to make all the requests within a server than making extra browser-to-server round-trips for them. This is what developers used to do before client-side rendering.

Should you server-side render?

A server-side rendered application enables pages to load faster, improving the user experience. When rendering server-side, search engines can easily index and crawl content because the content can be rendered before the page is loaded, which is ideal for SEO.

Does server-side render?

Server-side rendering means using a server to generate HTML from JavaScript modules in response to a URL request. That's in contrast to client-side rendering, which uses the browser to create HTML using the DOM. Server-side rendering with JavaScript works similarly to other server-side languages such as PHP or .

Can HTML5 be used for animation?

You can create animations with HTML5 by combining HTML, CSS, and JavaScript (JS), with which you can build shapes. Also, you can control animations and edit images, video, and audio by means of JS or CSS elements, all of which you then add to a drawing board, which you set up with the <canvas> element.


2 Answers

Just to note that we have solved this problem by

  • Running Firefox on a headless server. A server with a decent graphics card.

  • Having a Selenium Python control script to start/stop rendering

  • A custom rendering loop which will use Firefox's XPCom API to feed <canvas> raw pixels directly in the encoding pipeline

  • A custom Javascript rendering loop where clock does not come from a real clock, but it slices frames to the renderer on a stable framerate which is not real-time

Quite a complex system, so doesn't fit into one Answer box :(

like image 132
Mikko Ohtamaa Avatar answered Sep 28 '22 12:09

Mikko Ohtamaa


One thing that might work, depending on your animation, would be to essentially create an animated gif. With enough still images of your animation strung together, you should be able to turn those into a video with the right software. This is a rather brute-force solution, but if you can advance through your animation in a "frame-by-frame" fashion, it might work.

like image 43
cdeszaq Avatar answered Sep 28 '22 11:09

cdeszaq