How I built a browser-only MP4 and GIF meme studio on Cloudflare Workers, Canvas, and Web Audio
Most short-form meme editors either require a heavy mobile app like Alight Motion or upload your photos to a remote server and stamp a watermark on the export. I wanted a tool that builds beat-synced tweenslop videos and
Most short-form meme editors either require a heavy mobile app like Alight Motion or upload your photos to a remote server and stamp a watermark on the export. I wanted a tool that builds beat-synced tweenslop videos and looping GIFs locally in the browser, with no account and no server rendering bill.
That project became Tweenslop Maker. It runs on Cloudflare Workers for server-rendered HTML and does all image processing, 2D animation, audio synthesis, and MP4/GIF encoding on the user's device.
Here are the five engineering problems I ran into while shipping it and how I fixed them.
1. Avoiding bad cutouts on real photos
Users upload clean PNG stickers, Roblox avatars, and messy bedroom photos of their cats. Running an aggressive automatic background removal pass on a cluttered pet photo produces jagged blobs.
Instead of forcing one cutout mode on every upload, the editor checks background uniformity when an image loads. Clean backgrounds go straight to automatic cutout. Busy real-life photos default to a 512px rounded white-border sticker card. Users can switch between Rounded, Circle, and Auto Cutout in one click without re-uploading.
2. Speeding up client-side GIF encoding by 35.6x
Discord and meme creators want looping GIFs in addition to MP4 clips, so I built a dedicated GIF maker route. Early tests on mobile phones were painfully slow because nearest-color palette matching scanned the color table for every pixel on every frame.
Precomputing a color lookup table (LUT) replaced the inner loop with an array index read. That single change made client-side GIF encoding 35.6x faster and made 360x640 multi-second loops practical on mid-range phones.
3. Keeping Web Audio and Canvas in sync on iOS Safari
The full studio combines 16 preset animation templates, pixel rainbow trails, a 4-character Squad Mode, and a 16-step beat machine for Brazilian Funk and Dark Phonk loops.
iOS Safari is strict about two things:
-
AudioContextstays suspended until a direct user tap resumes it. -
MediaRecordercodec support differs from desktop Chrome.
I moved AudioContext creation and resume() directly inside tap handlers, bound the animation clock to the audio timeline instead of raw setInterval ticks, and targeted 5 Mbps H.264 output where supported with automatic WebM fallback. I also capped default squash-and-stretch scaling at 1.85:1 at 100% Chaos so fast beat drops stay funny without turning the photo into an unreadable smear.
4. Bundling 8 royalty-free beats without bloating page load
Audio tools often suffer from huge initial payloads. The beat library lives on a dedicated songs page with 8 royalty-free tracks (including 138 BPM and 142 BPM Brazilian Funk loops) that users can preview, download as WAV, or send straight into the sequencer.
Audio buffers load on demand rather than on initial page render. Non-editor routes ship stripped-down JavaScript bundles between 3.45 kB and 19.0 kB.
5. Fixing Core Web Vitals on Cloudflare Workers
Cloudflare Workers renders all 36 pages from TypeScript templates with static assets served under public, max-age=31536000, immutable headers. During real-device testing, two layout shifts showed up: preview cards resized after images decoded, and web fonts reflowed headings.
Reserving explicit aspect ratios across breakpoints cut desktop CLS on /songs from 0.4006 to 0.0044. Switching template previews to 640x360 WebP assets (12 KB to 25 KB each) with fetchpriority="high" brought template gallery LCP down to 1,500 ms and kept mobile INP between 16 ms and 120 ms.
Try it and poke holes in it
Everything runs locally in your browser with no login and no watermark:
- Main editor: Tweenslop Maker
- 4-tab editor and 16-step beat machine: Tweenslop Studio
- Looping GIF exporter: Tweenslop GIF Maker
- Free WAV beat library: Tweenslop Songs
If you have hit strange MediaRecorder quirks on mobile Safari or have ideas for faster client-side MP4 muxing, I would love to hear how you solved them in the comments.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.