{
  "id": 14578879,
  "title": "Detecting BPM and musical key in the browser (and encoding MP4 with WebCodecs)",
  "url": "https://urgent.news/2026/10/15/detecting-bpm-and-musical-key-in-the-browser-and-encoding-mp4-with",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-15T01:09:40.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/hao_yin_58711e69baab27ad7/detecting-bpm-and-musical-key-in-the-browser-and-encoding-mp4-with-webcodecs-1c6l"
  },
  "original_language": "en",
  "account": "The article explains how to build three free, browser-based tools for an AI music video generator: a BPM and key finder, an audio-to-video converter, and a Spotify Canvas maker. The tools utilize plain Web Audio, a one-handed FFT, and WebCodecs, and they don't require any servers, accounts, or uploads.\n\nThe BPM analysis begins with the Web Audio API's decodeAudioData method, which converts MP3, WAV, and M4A files into an AudioBuffer of raw float samples. The OfflineAudioContext is then used to downmix and resample the audio for further analysis. The BPM detector employs the web-audio-beat-detector package, which takes a tempo range (70 to 180 BPM) and returns the detected tempo. In case the automated detection fails, a tap-tempo button allows users to manually set the tempo.\n\nDetecting the musical key involves creating a chromagram, which represents the frequency content of a short audio segment in terms of 12 pitch classes (C2 to C7). The algorithm slides a Hann window across the mono downsampled audio, performs an FFT for each frame, and normalizes the results. These frames are then correlated with Krumhansl-Kessler major and minor profiles, and the best match is selected as the detected key. The process is optimized to avoid freezing the tab, reporting progress periodically, and using a Web Worker for better performance.\n\nTo suggest chorus or drop locations for a short music video clip, the algorithm computes the Root Mean Square (RMS) energy in half-second blocks and identifies the loudest stretch within the clip length. The user can adjust this selection if needed. For encoding MP4 files, the article describes using the WebCodecs VideoEncoder API, which efficiently encodes frames into MP4 format. The encoding process takes into account varying frame rates based on the content (30 fps for moving frames, 2 fps for static covers), and the spectrum visualizer for each frame is generated using the same FFT code as the key detector. The article also provides tips for seamless loops, such as maintaining symmetric motion, using keyframe synchronization, and wrapping up the story.",
  "summary": "We run AIMusicVideoGen , an AI music video generator for independent artists. The main product needs a server, but along the way we built three small free tools that run entirely in the browser: a BPM and key finder, an audio-to-video converter and a Spotify Canvas maker. No upload, no backend, no account. This post walks through how they work, because most of it is plain Web Audio, one…",
  "key_points": [
    "BPM and key finder built using Web Audio API and WebCodecs",
    "Audio-to-video converter and Spotify Canvas maker tools created",
    "No servers, accounts, or uploads required for browser-based tools"
  ],
  "editors_take": "Moving complex audio analysis and video encoding directly into the browser eliminates the need for server-side processing and protects user privacy by keeping files on local devices.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}