Removing a video watermark: temporal median first, model second
The video watermark demo samples a dozen frames and checks whether the background behind the watermark moves. If it does, a temporal median rebuilds it and nothing is downloaded; a static background gets a single MI-GAN inpaint. Also covered: re-encoding frame by frame with WebCodecs and muxing the audio back with ffmpeg.wasm.
The built-in sample is an 8-second street clip. Running the inpainting network on every frame was the first plan, and a few hundred frames made that obviously too slow. We changed it to sample a dozen frames along the timeline and check whether the area behind the watermark moves. A moving one is rebuilt straight from a temporal median. A static one gets an AI inpaint on a single representative frame, and that patch is composited onto every frame. Most runs download no weights at all.
How `motion` is computed
The sample count scales with duration, clamped between 8 and 24 frames, with a 5 percent margin at each end capped at 0.25 seconds. The 8-second sample produces 13 frames. We take a per-pixel temporal median across the selection and compute the mean deviation from it, divided by 255. A motion value of 0.015 or above counts as a moving background and selects the temporal median. Anything lower calls MI-GAN for a single-frame patch. The decision, the patch and the video all stay in the browser.
| Mode | What runs | Weights | When to pick it |
|---|---|---|---|
| auto | Chooses from motion | Possibly none | Default, let it decide |
| temporal | Per-pixel temporal median | None | Moving background, fixed watermark |
| ai | MI-GAN single-frame inpaint | 26.8 MiB | Static background |
| hq | big-lama fp32 single-frame inpaint | 198 MiB, wasm only | Large watermarks and structure, about 7x slower |
hq is opt-in only, and auto never selects it. Without the LaMa weights the code degrades to MI-GAN and then to the temporal patch, so a failed download does not stall the run. LaMa deadlocks on WebGPU, so the code does not even try that backend and goes straight to wasm.
Re-encoding frame by frame
Once the patch is ready, requestVideoFrameCallback draws each frame onto a canvas, composites the patch, wraps the canvas in a VideoFrame and hands it to VideoEncoder. Framerate is fixed at 30. Bitrate is width times height times 30 times 0.07, clamped between 1.2 Mbps and 20 Mbps. Seven avc1.* config candidates are tried from highest to lowest and isConfigSupported() picks the first usable one. When the encoder queue passes 8 frames, a requestAnimationFrame pump waits. A keyframe goes in every 2 seconds, and mp4-muxer writes the container with in-memory fastStart.
await ffmpeg.exec([
'-i', 'output-silent.mp4',
'-i', 'input-source.mp4',
'-map', '0:v:0',
'-map', '1:a:0?',
'-c:v', 'copy',
'-c:a', 'aac',
'-b:a', '160k',
'-movflags', '+faststart',
'output-with-audio.mp4',
]);WebCodecs gives us a video track only, so the audio is gone. In the real-weights path we load ffmpeg.wasm once more to mux the original audio back. The question mark in 1:a:0? keeps the command valid when the source has no audio track. A browser without VideoEncoder gets an unsupported-browser error. Input is capped at 120 seconds and 200 MiB. Demo mode skips both the MI-GAN weights and the audio mux, and always uses the temporal median.
Frame classification on the understanding page
The VideoCLIP, X-CLIP and VideoMAE cards under video/video-understanding carry only historic size estimates in the catalogue, roughly 300, 350 and 430 MB. None of them has browser-downloadable weights. Their real branch uses MediaPipe EfficientNet-Lite0 at about 18 MB, classifies each sampled frame, and merges adjacent frames with the same label into segments. Sampling rate runs from 1 to 12 fps with a default of 4, and the segment cap from 2 to 10 with a default of 6. The page answers what appears in which seconds. Action recognition and temporal reasoning are not wired up, and the result bar marks the substitute.
- On this site · Video watermark removal demo
- On this site · Video understanding demo
- Model page · Video watermark removal (MI-GAN / LaMa)
- Model page · Video watermark removal HD
- Model page · VideoCLIP
- Model page · X-CLIP
- Model page · VideoMAE
- W3C · WebCodecs ↗
- GitHub · Picsart-AI-Research/MI-GAN ↗
- GitHub · advimman/lama ↗
- Hugging Face · microsoft/xclip-base-patch32 ↗
- Hugging Face · MCG-NJU/videomae-base ↗