Add MP4 export for animated SVGs using ffmpeg.wasm - #314
Merged
Conversation
Animated SVG blocks (SMIL or CSS animations) get an extra MP4 tab that renders a looping H.264 video entirely in the browser: - Detects animation from SMIL elements (animate, set, animateTransform, animateMotion) and CSS @keyframes/animation rules, and derives a suggested loop length from dur/repeatCount/repeatDur and animation-duration/iteration-count (editable before generating). - Captures frames by freezing a copy of the SVG at each timestamp: negative animation-delay + paused for CSS, shifted begin offsets for SMIL, then rasterizes via the same blob-URL canvas approach as the PNG/JPEG tabs. SVG images draw at document time 0, so each shifted copy yields the frame at that time. - Encodes with ffmpeg.wasm, lazy-loaded from jsdelivr (~31 MB, first use only). The @ffmpeg/ffmpeg wrapper's UMD build cannot start its worker cross-origin, so a small inline worker drives @ffmpeg/core directly via blob URLs. - Output is mobile-friendly: max 720px, even dimensions, yuv420p, main profile, CRF 26, +faststart, previewed in a looping video element with a download button showing file size. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RWMdMCX4SnoLjTkQ4MXvA2
Selecting the MP4 tab now starts the ~31 MB ffmpeg.wasm download immediately (once per page, shared across blocks) instead of waiting for the Generate click, so it is usually ready by the time the user has reviewed the loop length. Nothing is fetched for documents where the MP4 tab is never opened, and the tests now assert that. Verified against the animated nudibranch gist: the CSS animation shorthands (4.6s-7s, infinite) detect as a 7s loop, and the default 7s x 30fps generation produces a 60 KB 720x596 H.264 MP4 in ~14s of encode time. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RWMdMCX4SnoLjTkQ4MXvA2
Contributor
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claude Fable 5 PR
This PR adds support for exporting animated SVGs as looping H.264 MP4 videos. When an SVG contains animations (either SMIL or CSS), a new MP4 tab appears in the renderer allowing users to generate and download a video.
Key Changes
detectSvgAnimation()to identify SMIL animations (<animate>,<set>,<animateTransform>,<animateMotion>) and CSS animations (@keyframes), with duration calculation for loop length estimationsnapshotSvgAtTime()to freeze an animated SVG at a specific time by shifting animation delays and begin offsets, enabling frame captureImplementation Details
https://claude.ai/code/session_01RWMdMCX4SnoLjTkQ4MXvA2