DEV Community

Muhammad Shoaib
Muhammad Shoaib

Posted on

Editing video in the browser with no upload: what MediaRecorder and canvas can (and can't) do

Small video jobs (merge, crop, rotate, mute, reverse) don't need a server. The browser can do them while the file stays on the visitor's computer: no upload, no queue, no watermark. Here is the general approach, and where the browser pushes back.

1. Load the file locally

const url = URL.createObjectURL(fileInput.files[0]);
video.src = url;
Enter fullscreen mode Exit fullscreen mode

An object URL lets a <video> element play a local file instantly. Nothing is uploaded.

2. Crop and rotate by drawing frames to a canvas

For crop and rotate, draw each frame onto a canvas with drawImage() (using the source rectangle for crop, or ctx.rotate() for a 90 or 180 degree turn), then record the canvas:

const stream = canvas.captureStream(30);
const rec = new MediaRecorder(stream, { mimeType: 'video/webm' });
Enter fullscreen mode Exit fullscreen mode

3. Keep or drop the audio

To keep sound, add the audio track from video.captureStream() to the canvas stream. To mute a clip, simply leave it out. That one choice is the whole "remove audio" tool.

4. The honest limits

  • MediaRecorder records in real time, so a 3-minute clip takes about 3 minutes.
  • Output is usually WebM. That is fine for most sites, but some phones prefer MP4.
  • Reversing video means reading every frame first, so it makes sense to cap the section length (the reverse tool below allows up to 60 seconds).

5. Merging

Play clips one after another into the same canvas and recorder, scaling each to a common size so the joins don't jump.

Try them

They're free and need no account. If you have built something similar, I'd like to hear how you handled MP4 output.

Top comments (0)