Skip to content

feat: add webcam background effect (blur, color, image)#438

Open
praburajasekaran wants to merge 1 commit intowebadderallorg:mainfrom
praburajasekaran:claude/add-camera-blur-cctS6
Open

feat: add webcam background effect (blur, color, image)#438
praburajasekaran wants to merge 1 commit intowebadderallorg:mainfrom
praburajasekaran:claude/add-camera-blur-cctS6

Conversation

@praburajasekaran
Copy link
Copy Markdown

@praburajasekaran praburajasekaran commented May 7, 2026

Wraps the webcam MediaStream with a canvas-based pipeline that uses MediaPipe Selfie Segmentation to apply a background blur, solid color, or replacement image. Effect applies to both the live preview and the recorded -webcam.webm sidecar.

UI lives in the camera dropdown with a mode selector, intensity slider for blur, color picker for solid color, and image upload for image mode. Choice is persisted in localStorage. MediaPipe model and WASM runtime are bundled under public/mediapipe so it works offline.

Pull Request Template

Description

Motivation

Type of Change

  • New Feature
  • Bug Fix
  • Refactor / Code Cleanup
  • Documentation Update
  • Other (please specify)

Related Issue(s)

Screenshots / Video

Screenshot (if applicable):

![Screenshot Description](path/to/screenshot.png)

Video (wherever possible):

<video src="path/to/video.mp4" controls width="600"></video>

Testing Guide

Checklist

  • I have performed a self-review of my code.
  • I have added any necessary screenshots or videos.
  • I have linked related issue(s) and updated the changelog if applicable.

Thank you for contributing!

Summary by CodeRabbit

  • New Features
    • Added webcam background effects with options to apply blur, solid color, or custom images to your video background during recording.
    • Added adjustable blur intensity controls and the ability to upload and manage custom background images.
    • Extended localization for background settings across 8 languages.

Wraps the webcam MediaStream with a canvas-based pipeline that uses
MediaPipe Selfie Segmentation to apply a background blur, solid color,
or replacement image. Effect applies to both the live preview and the
recorded -webcam.webm sidecar.

UI lives in the camera dropdown with a mode selector, intensity slider
for blur, color picker for solid color, and image upload for image
mode. Choice is persisted in localStorage. MediaPipe model and WASM
runtime are bundled under public/mediapipe so it works offline.
@github-actions github-actions Bot added the Slop label May 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

⚠️ This pull request has been flagged by Anti-Slop.
Our automated checks detected patterns commonly associated with
low-quality or automated/AI submissions (failure count reached).
No automatic closure — a maintainer will review it.
If this is legitimate work, please add more context, link issues, or ping us.

2 similar comments
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

⚠️ This pull request has been flagged by Anti-Slop.
Our automated checks detected patterns commonly associated with
low-quality or automated/AI submissions (failure count reached).
No automatic closure — a maintainer will review it.
If this is legitimate work, please add more context, link issues, or ping us.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

⚠️ This pull request has been flagged by Anti-Slop.
Our automated checks detected patterns commonly associated with
low-quality or automated/AI submissions (failure count reached).
No automatic closure — a maintainer will review it.
If this is legitimate work, please add more context, link issues, or ping us.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR introduces a configurable webcam background effects system using MediaPipe segmentation. It adds a canvas-based processor supporting blur, solid color, and image backgrounds; a state-management hook with localStorage persistence; UI controls in LaunchWindow; integration with the screen recorder; and localized UI labels across eight languages.

Changes

Webcam Background Effects

Layer / File(s) Summary
Background Processor
src/lib/camera/backgroundEffect.ts
MediaPipe-based processor exports BackgroundEffectOptions type (mode, blur intensity, color, image), ProcessedStream with stream and stop(), and createProcessedStream() function. Lazy-loads ImageSegmenter with GPU delegation, renders selected background mode via canvas, composites person/foreground on top using segmentation mask, and provides cleanup handler.
State Management
src/hooks/useBackgroundEffect.ts
New useBackgroundEffect() hook manages BackgroundEffectOptions state with localStorage persistence (versioned key, fallback to defaults). Exports UseBackgroundEffectReturn with options, getOptions, setMode, setBlurIntensity, setColor, setImageDataUrl. Memoizes return value for stable references.
Screen Recorder Integration
src/hooks/useScreenRecorder.ts
useScreenRecorder() now accepts optional UseScreenRecorderArgs with getBackgroundOptions callback. Stores raw webcam stream separately, conditionally routes through createProcessedStream when background enabled, falls back to raw on failure. Cleanup stops both processor and raw tracks.
Launch Window UI
src/components/launch/LaunchWindow.tsx
Adds BackgroundEffectControls component with dropdown for mode selection (none, blur, color, image) and mode-specific inputs (blur intensity slider, color picker, image upload/removal). Wires to useBackgroundEffect() state. Preview stream setup conditionally applies createProcessedStream and cleanup properly tears down processor and stream tracks.
Localization
src/i18n/locales/{en,es,fr,ko,nl,pt-BR,zh-CN,zh-TW}/launch.json
Adds recording.background object to each locale with labels for mode selection (none, blur, color, image), intensity control, and image actions (chooseImage, changeImage, removeImage).
Dependencies
package.json
Adds @mediapipe/tasks-vision (^0.10.35) and @electron/rebuild (^4.0.3) as dev dependencies; removes @fix-webm-duration/fix.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • webadderallorg/Recordly#163: Modifies LaunchWindow webcam preview stream management and cleanup; both PRs update preview stream attachment/detachment logic and refs.

Suggested labels

Checked

Suggested reviewers

  • meiiie

Poem

🐰 A rabbit hops through frames so bright,
With blurred backdrops and colors right,
MediaPipe masks the ground beneath,
While features bloom like clover wreath,
Eight tongues now whisper: "Record with flair!" 📹✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning PR description includes an introductory summary of the feature but the template sections are largely uncompleted with mostly empty placeholders and minimal content in required fields. Complete the template by filling in: Motivation (problem/use case), Type of Change selection, Related Issue links, Screenshots/Videos demonstrating the background effect UI and results, and a detailed Testing Guide explaining how to test blur/color/image modes.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add webcam background effect (blur, color, image)' is clear and specific, directly summarizing the main feature addition and the three background effect modes introduced.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

⚠️ This pull request has been flagged by Anti-Slop.
Our automated checks detected patterns commonly associated with
low-quality or automated/AI submissions (failure count reached).
No automatic closure — a maintainer will review it.
If this is legitimate work, please add more context, link issues, or ping us.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/lib/camera/backgroundEffect.ts (1)

251-279: 💤 Low value

Module-level scratch canvas is shared across instances.

personScratch is a module-level singleton that would be shared if multiple createProcessedStream pipelines run concurrently (e.g., preview and recording). While RAF callbacks are serialized within a single thread, having instance-local scratch canvases would be more defensive.

In the current usage pattern (preview stops before recording), this is unlikely to cause issues, so flagging as optional.

♻️ Optional: Move scratch canvas into Internals state
 type Internals = {
 	cancelled: boolean;
 	rafHandle: number | null;
 	video: HTMLVideoElement;
 	canvas: HTMLCanvasElement;
 	ctx: CanvasRenderingContext2D;
 	maskCanvas: HTMLCanvasElement;
 	maskCtx: CanvasRenderingContext2D;
 	bgImage: HTMLImageElement | null;
 	bgImageUrl: string | null;
+	personScratch: HTMLCanvasElement;
+	personScratchCtx: CanvasRenderingContext2D;
 };

Then initialize per-instance in createProcessedStream and pass to drawPersonOnTop.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/camera/backgroundEffect.ts` around lines 251 - 279, The module-level
scratch canvas (personScratch/personScratchCtx) is shared across instances and
should be made instance-local to avoid cross-pipeline interference; move
initialization out of the module scope into the per-stream state created by
createProcessedStream, pass the instance-specific canvas/context into
drawPersonOnTop (replace references to module globals inside drawPersonOnTop
with the passed-in canvas/context), and ensure sizing/clearing logic remains the
same but operates on the per-instance scratch canvas.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/lib/camera/backgroundEffect.ts`:
- Around line 251-279: The module-level scratch canvas
(personScratch/personScratchCtx) is shared across instances and should be made
instance-local to avoid cross-pipeline interference; move initialization out of
the module scope into the per-stream state created by createProcessedStream,
pass the instance-specific canvas/context into drawPersonOnTop (replace
references to module globals inside drawPersonOnTop with the passed-in
canvas/context), and ensure sizing/clearing logic remains the same but operates
on the per-instance scratch canvas.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fd145452-bf08-4f46-869d-247be90eeae9

📥 Commits

Reviewing files that changed from the base of the PR and between 493c85f and 3dd2cb5.

⛔ Files ignored due to path filters (3)
  • package-lock.json is excluded by !**/package-lock.json
  • public/mediapipe/wasm/vision_wasm_internal.wasm is excluded by !**/*.wasm
  • public/mediapipe/wasm/vision_wasm_nosimd_internal.wasm is excluded by !**/*.wasm
📒 Files selected for processing (16)
  • package.json
  • public/mediapipe/selfie_segmenter.tflite
  • public/mediapipe/wasm/vision_wasm_internal.js
  • public/mediapipe/wasm/vision_wasm_nosimd_internal.js
  • src/components/launch/LaunchWindow.tsx
  • src/hooks/useBackgroundEffect.ts
  • src/hooks/useScreenRecorder.ts
  • src/i18n/locales/en/launch.json
  • src/i18n/locales/es/launch.json
  • src/i18n/locales/fr/launch.json
  • src/i18n/locales/ko/launch.json
  • src/i18n/locales/nl/launch.json
  • src/i18n/locales/pt-BR/launch.json
  • src/i18n/locales/zh-CN/launch.json
  • src/i18n/locales/zh-TW/launch.json
  • src/lib/camera/backgroundEffect.ts

@webadderall webadderall removed the Slop label May 8, 2026
@meiiie meiiie added the Checked label May 8, 2026
@ExtraBinoss
Copy link
Copy Markdown
Collaborator

There is a good chance adding mediapipe to the main thread, while also recording, will result in heavy lag, maybe consider webworkers with mediapipe. They can work with GPU too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants