feat: Extend Lottie specification with VideoFrame asset support#149
feat: Extend Lottie specification with VideoFrame asset support#149stepancar wants to merge 9 commits intolottie:mainfrom
Conversation
|
We require contributors to sign our Contributor License Agreement, and we don't have @stepancar on file. In order for us to review and merge your code, please contact @heathmill or @jcgregorio to get yourself added. |
| "p": { | ||
| "title": "File Name", | ||
| "description": "Name of the video file or a data url", | ||
| "type": "string" | ||
| }, | ||
| "u": { | ||
| "title": "File Path", | ||
| "description": "Path to the video file", | ||
| "type": "string" | ||
| }, | ||
| "e": { | ||
| "title": "Embedded", | ||
| "description": "If '1', 'p' is a Data URL", | ||
| "$ref": "#/$defs/values/int-boolean" | ||
| } | ||
| }, | ||
| "allOf": [ | ||
| { | ||
| "if": { | ||
| "properties": { | ||
| "e": {"const": 1} | ||
| }, | ||
| "required": ["e"] | ||
| }, | ||
| "then": { | ||
| "properties": { | ||
| "p": {"$ref": "#/$defs/values/data-url"} | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
I'd extract this into an abstract file-asset schema so we can share the definition between image and video assets (and other future assets
| "w": { | ||
| "title": "Width", | ||
| "description": "Width of the frame", | ||
| "type": "number" | ||
| }, | ||
| "h": { | ||
| "title": "Height", | ||
| "description": "Height of the frame", | ||
| "type": "number" | ||
| } |
There was a problem hiding this comment.
The video asset schema also has w and h, are they needed here as well? if so, what's their semantic?
There was a problem hiding this comment.
@mbasaglia I was thinking about extracting a frame from VideoResource, specifying width, height, x, y from the top left corner. But you are right, as a first iteration we can drop w/h from frame
| }, | ||
| { | ||
| "type": "object", | ||
| "properties": { |
There was a problem hiding this comment.
I think we should introduce a ty for assets (not strictly required for this proposal)
|
|
||
| {schema_object:assets/video-frame} | ||
|
|
||
| Video frame assets reference a video asset by ID and specify a timestamp to extract a specific frame. Players MUST extract the frame at the exact timestamp specified, or the closest available frame if the exact timestamp is not available. The extracted frame should be treated as a static image for rendering purposes. |
There was a problem hiding this comment.
should
Is this a SHOULD or a MUST?
There was a problem hiding this comment.
This point is up for discussion.
The advantage of using MUST is that Lottie players could extract frames on the fly, which speeds up animation initialization and reduces memory usage before playback starts. At the same time, if players don’t treat the extracted frame as a static image but instead process it in real time, it could impose constraints on the video itself - for example, requiring more keyframes to ensure fast seeking, which would increase file size.
That’s why I would vote for MUST.
In the future, if we want to support optimization for initialization we could extend videoFrame with initialization: static | dynamic param to achieve that.
|
We require contributors to sign our Contributor License Agreement, and we don't have @stepancar on file. In order for us to review and merge your code, please contact @heathmill or @jcgregorio to get yourself added. |
|
We require contributors to sign our Contributor License Agreement, and we don't have @stepancar on file. In order for us to review and merge your code, please contact @heathmill or @jcgregorio to get yourself added. |
|
@heathmill or @jcgregorio Hello. I have signed CLA, but bot is still complaining in this PR. Could you check? Thank you! |
|
We require contributors to sign our Contributor License Agreement, and we don't have @stepancar on file. In order for us to review and merge your code, please contact @heathmill or @jcgregorio to get yourself added. |
|
We require contributors to sign our Contributor License Agreement, and we don't have @stepancar on file. In order for us to review and merge your code, please contact @heathmill or @jcgregorio to get yourself added. |
|
We require contributors to sign our Contributor License Agreement, and we don't have @stepancar on file. In order for us to review and merge your code, please contact @heathmill or @jcgregorio to get yourself added. |
|
We require contributors to sign our Contributor License Agreement, and we don't have @stepancar on file. In order for us to review and merge your code, please contact @heathmill or @jcgregorio to get yourself added. |
|
We require contributors to sign our Contributor License Agreement, and we don't have @stepancar on file. In order for us to review and merge your code, please contact @heathmill or @jcgregorio to get yourself added. |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
ok I fixed the bot |
Thank you! |
fmalita
left a comment
There was a problem hiding this comment.
What is the authoring story for these asset types, are you planning to add support in existing or new tools?
| "type": "integer", | ||
| "const": 3 | ||
| }, | ||
| "vsid": { |
There was a problem hiding this comment.
Naming bike-shed: normally sid refers for "slot ID", which I guess could be adopted here if we squint. But since we're not dealing with real slots, that may be confusing.
How about refId, which is the normal way to reference assets?
There was a problem hiding this comment.
Agree, refId makes more sense, updated
| }, | ||
| "t": { | ||
| "title": "Timestamp", | ||
| "description": "Timestamp in seconds where to extract the frame from the video", |
There was a problem hiding this comment.
How does this interact with start-time/time-stretch/general time remapping in referencing layers?
Also actual time units seem a bit odd since everything else in Lottie is expressed as frame indices (ip, op, etc).
There was a problem hiding this comment.
Actually, you are right, we can define time in frames here
|
|
||
| {schema_object:assets/video-frame} | ||
|
|
||
| Video frame assets reference a video asset by ID and specify a timestamp to extract a specific frame. Players MUST extract the frame at the exact timestamp specified, or the closest available frame if the exact timestamp is not available. The extracted frame should be treated as a static image for rendering purposes. |
There was a problem hiding this comment.
Can the same functionality be achieved using time remapping to lock a video layer's time? IOW do we actually need video frame assets, or would video assets be sufficient?
I can think of some advantages to having a dedicated asset type, mostly on the implementation side (caching) - but there are also some downsides (more verbose than video asset + time-locked video layer).
There was a problem hiding this comment.
The main motivation of having VideoFrame is ability to set time or frame number, I didn't find better way to express it with existing lottie primitives
These assets are created in any raster editor and then exported as Lottie files with base64-encoded individual frames. I’m not sure how easy it would be to extend Bodymovin to support wrapping a sequence of images into a video/animated image. |
|
The source code for bodymovin is here- https://github.com/bodymovin/bodymovin-extension. FYI it took me a bit to get the dev environment running, particularly if you are on an ARM system. Also did you have the authoring site/updated player available? Part of the spec process is to have at least an end to end demo of the feature. One other thing is we wanted to be sure that the video asset could also be used for video playback. I think this still looks good but we may want to flesh out that support as well. |
Motivation
Currently, raster animations in Lottie are supported as sequences of frames where images are embedded directly. Since no interframe coding happens under the hood, raster animations are very large. Lottie is not just a vector format, it is also used as a universal animation format. Adding support for frames extracted from video resources makes animation size much smaller. Modern systems support a variety of codecs, so video processing and frame extraction will not be a problem.
Changes:
Add VideoAsset with id, resourceUrl, duration, width, height.
Add VideoFrame asset, similar to ImageAsset, but referencing a VideoAsset by id and specifying a timestamp.
This is a painless schema change. Players can keep their existing image-sequence engines: when encountering VideoFrame, simply extract the frame from the video, convert it to a base64 PNG, and treat it as a normal ImageAsset.
Effectively:
lottieWithVideoFrames -> lottieWithImageSequence
Before
After
CLA PR