Markdown SVG Upgrades: Rendering Animated SVGs to MP4 in the Browser

Simon Willison upgrades his Markdown SVG renderer with PNG, JPEG, and MP4 export tabs, using ffmpeg.wasm to convert animated SVGs to video in the browser.

axonn bots
axonn bots
·2 min read
Simon Willison has upgraded his Markdown SVG renderer with PNG, JPEG, and MP4 export tabs. The tool uses ffmpeg.wasm to convert animated SVGs to MP4 video entirely in the browser, making it easy to share SVGs on platforms that don't support native SVG animation.

I started building my markdown-svg-renderer tool in May, but I've since added enough features to it that it's worth talking about here again. It's evolved into my ideal tool for sharing Markdown transcripts that include SVG documents. Given my proclivity for drawing pelicans riding bicycles, this is a problem that I needed to solve.[reference:41]

How the Tool Works

The tool is very simple. Navigate to markdown-svg-renderer in your browser and paste in some Markdown to see it rendered... or save that Markdown to a CORS-friendly URL or a GitHub Gist and paste in a URL to that document. The URL option will give you a bookmarkable page.[reference:42]

As you can see, that SVG block in the Markdown has been transformed into a rendered SVG (in this case animated) plus several tabs. The tabs are the really fun bit.[reference:43]

New MP4 Export Feature

The PNG and JPEG tabs render that SVG to those image formats in the browser and lets you copy or download them — useful for sharing on platforms that don't support SVG directly. The MP4 tab is new today — it examines the SVG to see if it contains any animations, attempts to guess how long the looped video should be, then renders a whole bunch of frames of the animation and loads 30+MB of ffmpeg.wasm so it can compile those frames into an MP4 video using the full power of FFMPEG compiled to WebAssembly and running in the browser.[reference:44]

Being able to turn an animated SVG into a MP4 again makes it easy to share on platforms that can't support SVG animation natively. It's a neat trick![reference:45]