Developer swaps FFmpeg.wasm for native browser decoders to streamline Telegram sticker conversions

Telegram · Web Development: A developer replaced a 30 MB FFmpeg payload with native browser decoders.

A small web utility that downloads Telegram sticker packs has been re‑engineered to perform all format conversions inside the browser, eliminating the 30 MB FFmpeg.wasm payload and the need for cross‑origin isolation headers.

Why the FFmpeg.wasm approach was dropped

The original implementation relied on FFmpeg compiled to WebAssembly, which functioned but required users to fetch a roughly 30 MB script and to serve the page with SharedArrayBuffer support. Those isolation headers also blocked the Microsoft Clarity analytics script, leaving the site without session data. Removing FFmpeg.wasm therefore reduced the download size dramatically and restored compatibility with standard analytics setups.

Leveraging built‑in browser decoders

Modern browsers already provide native decoders for the three Telegram sticker formats: createImageBitmap handles static WebP, the <video> element decodes VP9‑encoded WebM video stickers, and the lottie‑web library renders the JSON animation inside .tgs files. The only missing pieces were a GIF encoder (supplied by the lightweight modern‑gif library) and a ZIP writer (provided by client‑zip). By chaining these native tools, the conversion pipeline now runs entirely in the client without any external binary.

Static stickers: WebP → PNG via canvas

For still stickers the process is straightforward: the WebP blob is turned into an ImageBitmap, drawn onto a same‑size canvas, and exported as a PNG blob via canvas.toBlob. Transparency is preserved, and the code cleans up the bitmap after use to free memory.

Animated stickers: gzipped Lottie to GIF

A .tgs file is simply a gzip‑compressed Lottie JSON. The browser’s DecompressionStream inflates the data, after which a stripped‑down version of lottie‑light‑canvas renders each frame to a canvas. The script steps through the animation manually, captures pixel data, and feeds it to modern‑gif running in a Web Worker. To keep the UI responsive, the loop yields between frames via a MessageChannel.

Video stickers: WebM → GIF via <video>

Video‑based stickers are VP9 WebM clips up to three seconds long. Lacking a frame‑accurate extraction API, the code seeks to incremental timestamps, draws the current frame to a canvas, and adds it to the GIF encoder. A timeout guards against stalled decoders. Because GIF does not support partial alpha, each pixel’s opacity is quantised at a 128 threshold before encoding.

Performance, limits and caching

According to the developer’s own measurements, converting 34 animated stickers to GIF takes about 19 seconds, while a 50‑sticker static pack exports as a PNG ZIP in under a second. The tool caches each sticker’s conversion result, so repeated downloads avoid re‑encoding. Concurrency is throttled based on device memory—only one GIF conversion runs on devices reporting ≤ 4 GB RAM to prevent a single 512 px GIF from consuming ~100 MB of RAM.

Converting 34 animated stickers to GIF takes about 19 seconds, while a 50-sticker static pack exports as a PNG ZIP in under a second.

The companion Z.Tools page confirms similar user‑facing numbers: animated stickers require roughly 0.5–0.7 seconds each to process, video stickers about 0.8 seconds, and static packs complete in less than a second. It also notes that GIFs are limited to 512 px (or 256 px for size‑constrained chats) and that transparency is binary, which can make edges appear harsher than in the original WebP/WebM assets.

Material limitations

The conversion pipeline still depends on browser support: DecompressionStream is needed for .tgs handling (available in Chrome 80+, Edge, Safari 16.4, Firefox 113+), and VP9 WebM playback is required for video stickers (supported in Chrome and Edge). When a required feature is missing, the tool falls back to saving the original file. Additionally, GIFs cannot faithfully reproduce the 60 fps frame rate of some stickers; the encoder clamps delays to a minimum of 4 centiseconds, effectively capping output at 25 fps, which may increase file size without perceptible visual gain.

Why it matters for web developers

Replacing a heavyweight WebAssembly dependency with native browser APIs illustrates a broader shift toward leveraging built‑in capabilities to shrink front‑end bundles and simplify security requirements. For developers building client‑side media processors, the Telegram sticker converter offers a concrete case study: identify existing browser decoders, supplement only the missing parts with tiny, focused libraries, and design a fallback path that preserves functionality when a feature is unavailable. The removal of cross‑origin isolation also avoids the need for SharedArrayBuffer, which many sites struggle to enable due to CSP and COOP/COEP constraints. By keeping all processing client‑side, the tool eliminates server‑side transcoding costs and reduces latency for end users. However, the approach is bounded by current browser feature parity; developers must still account for variations in codec support, memory limits, and the loss of features such as partial alpha in GIF. As browsers continue to add APIs like WebCodecs, future revisions could further close the gap between native capabilities and high‑fidelity media conversion, making this model increasingly attractive for a range of web‑based media tools.

Editorial graphic and headline text by Signal Titans.

Source: Converting Telegram stickers to PNG and GIF in the browser, without FFmpeg · Telegram Sticker Downloader · Z.Tools

Share this article
FacebookThreadsLinkedInX

Leave a Reply

Your email address will not be published. Required fields are marked *