tvf lottie player/lottie.js

A Lottie file is a recipe: layers, shapes and keyframes that a renderer works out again at every frame. The importer in player/lottie.js works it out itself, once per frame, keeps what it gets as the exact paths the TVF player already draws (corners, curve handles, roundings), follows each path from frame to frame and writes a scene: a .tvfs file the player poses with the editor's own engine, sharp at any size, and open to everything a scene can do that a Lottie cannot, like being taken in the hand.

Below, watch one processed a frame at a time, change the two knobs that decide how small the scene comes out, and drop in one of your own. Nothing is uploaded: the file is read in this tab, and what the importer cannot read (masks, mattes, effects, text, images, gradients, trim paths) it names, it does not guess at.

how it works watch it your own use it

how it works

4 steps

1 draw every frame

The Lottie is parametric: a ball's position is two keyframes and an ease. The importer evaluates all of it, as a Lottie renderer would (transforms, parents, precompositions, eases, opacity), at every frame, and keeps the shapes as exact paths: corners, cubic handles, rounded corners. That is the left picture below.

2 follow each path

A path that is there in every frame is a track. If its outline never changes in its own coordinates, only its matrix, it is kept once with a transform (teal below). If the outline itself moves, it is a morph of exact keys (gold). A path that never changes at all is a still.

3 keep what matters

Of a track's frames only those a straight blend cannot stand in for are kept, to a tolerance in pixels. A stretch between two kept frames is a straight blend, or a cubic-Bézier ease fitted to the frames between them, so an eased move Lottie keyed once comes back as one stretch.

4 play the scene

The result is a .tvfs scene. The player poses it at any time and draws the curves at the canvas's size, with the same engine as the editor: the right picture below, and nothing is a frame. Scenes can also be clicked and thrown, which a Lottie file has no way to say.

watch it processed

3 Lotties of our own

Pick a Lottie and press process it: the importer reads the file frame by frame (the left picture is each frame as exact paths), then follows and trims the paths, and the scene starts playing on the right. The strip shows which frames it kept for each path: the fewer the ticks, the smaller the scene. Drag the frame slider to compare one frame of the Lottie with the scene at the same moment, or move the tolerance to see how much it can drop.

your own

open or drop a Lottie .json

The same bench on a file of yours: open a Lottie .json (Bodymovin's export, which is what LottieFiles and After Effects write) or drop it on the panel. It is processed here, then you can scrub it, change the tolerance, and take the .tvfs away. A .lottie file is a zip and is not read yet; unzip it and use the .json inside.

use it

in a page, or from a shell

1 in a page

Three scripts, then convert and play:


        

report says what it made (frames, morphs, moved, keys) and what it left out (unsupported). tol is in the composition's pixels; xform: false keeps every moving shape as shape keys, as before version 2.

2 from a shell

The same conversion, written to .tvfs files, with what each one cost:


        

player.html opens a Lottie directly too, and its address takes ?src=.

3 what it reads, and what it leaves out

Read: shape layers (paths, rectangles with their roundness, ellipses, stars; fills and strokes; groups and their transforms), solids, null layers, parenting, precompositions, opacity, eases, colours.

Named and left out: masks and mattes, effects, text, images, gradients (drawn as their middle colour), trim paths, repeaters, merged paths, expressions, 3D layers, skew, blend modes, time remapping, a stroke keyed over time, a path whose vertex count changes.

Checked against lottie-web's canvas renderer on its repository's own demos: within 0.1 to 1.5 of 255 on the files it reads whole; the benches above compare the same way, 0.0 to 0.2 on these three.

4 how big it comes out

Gzipped, against the Lottie file, on lottie-web's demos (not shipped here):

fileLottiescene
gatin4.5 KB5.9 KB
adrock12 KB29 KB
bacon52 KB105 KB
happy201653 KB79 KB
bodymovin135 KB212 KB

A scene stores the shapes where a Lottie stores the recipe, so it comes out larger; what it buys is no renderer to run, the editor's engine at any size, and scenes you can touch. The player with the curve library is about 48 KB gzipped, about the size of lottie-web's light build.