Dev.to WebDev 🛠 Dev 👁 2 📖 2 min read

Exporting 60fps Audio-Synced 1080p MP4s in Pure Browser JS with WebCodecs (

Most browser-based audio visualizers stop at a live <canvas> preview or delegate video rendering to a slow server-side FFmpeg queue. When we built SoundFlick—a browser-native release studio for indie musicians and AI mus

Most browser-based audio visualizers stop at a live <canvas> preview or delegate video rendering to a slow server-side FFmpeg queue. When we built SoundFlick—a browser-native release studio for indie musicians and AI music creators—we wanted the entire pipeline from MP3 decoding to 1080p MP4 export to run deterministically inside the user's tab.

Here are three hard engineering problems we hit when pairing WebGL1, Web Audio, and WebCodecs, and how we solved them.

1. Real-Time MediaRecorder Drifts; Deterministic Frame Stepping Does Not

Recording a live <canvas> stream with MediaRecorder ties frame timestamps to main-thread requestAnimationFrame jitter. If a tab briefly stutters or encodes slightly slower than real time, audio and video drift apart and keyframe spacing breaks.

Instead, SoundFlick renders deterministically frame by frame:

  • Decode the full audio track with AudioContext.decodeAudioData() and slice the selected 15s/30s chorus hook.
  • Step a fixed virtual clock t = frameIndex / fps (60fps preview, deterministic export clock).
  • Feed each stepped frame (VideoFrame) into VideoEncoder (avc1 H.264) and feed PCM chunks into AudioEncoder (mp4a.40.2 AAC).
  • Mux encoded chunks directly in memory via a zero-copy Blob-part MP4 muxer with faststart (moov before mdat) so exported MP4s play immediately on TikTok, Reels, YouTube Shorts, and iOS Photos.

Across our automated Chrome + ffprobe test suite, measured audio/video duration drift stays within <= 40ms (typically ~2.7ms on 15s 1080p exports).

2. Guarding Against Silent Exports and Mobile Sample-Rate Edge Cases

Two real-world audio traps surfaced right after launch:

  1. Zero-chunk silent MP4s: If an encoder configuration fails silently or audio chunks aren't flushed before muxer finalization, the user downloads a valid-looking MP4 with no sound. We added a strict guard (audioChunks.length === 0 aborts export with a clear diagnostic error instead of producing a silent file).
  2. Mobile sample-rate mismatches: Mobile Safari and Chrome instances frequently report hardware sample rates (44100 Hz vs 48000 Hz) that differ from naive encoder defaults, requiring explicit fallback resampling before passing AudioData to AudioEncoder.

3. Keeping Landing Pages Fast (0 KB Studio JS on Entry)

A full WebGL shader + WebCodecs studio bundle is heavier than a marketing page should ship on initial load. Instead of hydrating the whole studio on / or /ai-lyric-video-maker, SoundFlick decouples them:

  • / and AI Lyric Video Maker ship lightweight pre-rendered preview loops and an in-memory handoff dropzone (0 KB Studio engine JS on the landing route).
  • Dropping an MP3/WAV or pasting lyrics hands the File object and text straight into /studio in memory with zero double-upload.

Try It in Chrome

You can load a built-in demo track or drop your own MP3 at soundflick.com with no signup required and inspect the exported 1080p MP4 locally with ffprobe.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.