DEV Community

Mark Jhon Pasamon
Mark Jhon Pasamon

Posted on Fully Autonomous

How I built a video editor that never uploads your video (canvas + MediaRecorder)

Most free online video tools upload your file to a server, process it, and send it back — with a watermark or a length limit on the free plan. I wanted crop, blur, loop, reverse and split for ToolsKo without any upload, so everything had to run in the browser. Here's the approach, what worked, and the trade-offs.

The idea: play it, draw it, record it

The browser already has everything needed:

  1. a hidden <video> element plays the file,
  2. each frame is drawn onto a <canvas> with the change applied (crop, colour filter, blur box…),
  3. canvas.captureStream() turns the canvas into a live video stream, and
  4. MediaRecorder records that stream into a file.
const stream = canvas.captureStream(30);
// add the (optional) audio track from Web Audio
for (const t of audioDest.stream.getAudioTracks()) stream.addTrack(t);
const rec = new MediaRecorder(stream, { mimeType, videoBitsPerSecond: 5_000_000 });
rec.ondataavailable = (e) => e.data.size && chunks.push(e.data);
rec.start(250);
video.play();
requestAnimationFrame(function draw() {
  ctx.drawImage(video, sx, sy, sw, sh, 0, 0, w, h); // e.g. a crop
  if (!video.ended) requestAnimationFrame(draw);
});
Enter fullscreen mode Exit fullscreen mode

Because the video plays in real time, saving a 1-minute clip takes about a minute. That's the main trade-off; the win is that nothing is uploaded and there's no encoder to download.

Picking a format

Not every browser can record MP4, so I try the best option first and fall back:

const candidates = [
  'video/mp4;codecs=avc1.42E01E,mp4a.40.2',
  'video/mp4;codecs=avc1.42E01E,opus',
  'video/mp4',
  'video/webm;codecs=vp9,opus',
  'video/webm',
];
const mimeType = candidates.find((c) => MediaRecorder.isTypeSupported(c)) ?? '';
Enter fullscreen mode Exit fullscreen mode

Volume above 100% without distortion

Boosting audio with a GainNode clips loud parts. A DynamicsCompressorNode set like a limiter (threshold −3 dB, ratio 20, fast attack) catches the peaks. I checked the result with ffmpeg's volumedetect: 150% came out +3.5 dB, which is exactly 20·log₁₀(1.5).

Blurring faces and plate numbers

For each box, I clip to the rectangle and redraw the canvas onto itself with ctx.filter = 'blur(…)'. Older Safari ignores canvas filters, so the code tests support first and falls back to pixelation (draw the area tiny, then scale it back up with smoothing off).

Reverse: you can't play a video backwards

Browsers won't play video in reverse, so the tool seeks frame by frame (30 fps), saves each frame as a JPEG blob (about 80 KB instead of ~3.7 MB for a raw 720p bitmap), then replays the frames in reverse order into the recorder. That's why reverse is limited to 60-second clips.

Testing it for real

I generated a 6-second test clip with ffmpeg, drove every tool with Playwright, and checked each output with ffprobe: dimensions, duration, and whether an audio stream exists (a "muted" video must have none).

What I'd do next

WebCodecs would make exports faster than real time and give exact MP4 output. For now, real-time recording keeps the code small and works in every modern browser.

You can try the tools here: https://toolsko.com/toolkits/video-editing — feedback welcome, especially from Safari users.

Top comments (0)