Skip to content

fix(render): preserve alpha on .webm overlays by forcing libvpx-vp9 decoder#59

Open
DanielOwusu wants to merge 1 commit into
browser-use:mainfrom
DanielOwusu:fix/webm-overlay-alpha-decode
Open

fix(render): preserve alpha on .webm overlays by forcing libvpx-vp9 decoder#59
DanielOwusu wants to merge 1 commit into
browser-use:mainfrom
DanielOwusu:fix/webm-overlay-alpha-decode

Conversation

@DanielOwusu

@DanielOwusu DanielOwusu commented Jun 6, 2026

Copy link
Copy Markdown

What

build_final_composite in helpers/render.py now forces -c:v libvpx-vp9 on .webm overlay inputs so their alpha channel is honored during compositing. Other overlay formats (mp4, etc.) are unaffected.

Why

ffmpeg's native VP9 decoder decodes alpha-carrying WebM (alpha stored as a side-data plane, reported as yuv420p + ALPHA_MODE=1) to opaque yuv420p. When such a file is used as an overlay via the overlay filter, the transparent regions render as opaque black. For a full-frame transparent overlay — e.g. a captions track or lower-third exported as VP9+alpha — this turns the entire frame black and hides the base video and every overlay beneath it.

Forcing the alpha-aware libvpx-vp9 decoder on the input makes ffmpeg decode to yuva420p, so overlay transparency composites correctly.

How it showed up

Compositing an EDL whose overlays included VP9+alpha WebM layers (a transparent caption overlay and a transparent CTA lower-third) produced an output that was entirely black except for the opaque pixels of the topmost overlay. The base talking-head video and an opaque demo overlay were both hidden. Swapping in the libvpx-vp9 decoder for the .webm inputs fixed it with no other changes.

Change

     inputs: list[str] = ["-i", str(base_path)]
     for ov in overlays:
         ov_path = resolve_path(ov["file"], edit_dir)
-        inputs += ["-i", str(ov_path)]
+        # VP9/WebM overlays carry alpha as a side-data plane. ffmpeg's native vp9
+        # decoder drops it (decodes to yuv420p -> opaque), which turns a full-frame
+        # transparent overlay into an opaque black layer. Force the alpha-aware
+        # libvpx-vp9 decoder so overlay alpha is honored.
+        if ov_path.suffix.lower() == ".webm":
+            inputs += ["-c:v", "libvpx-vp9", "-i", str(ov_path)]
+        else:
+            inputs += ["-i", str(ov_path)]

Notes for reviewers

  • Reproduced on ffmpeg 8.1.1 (Homebrew). Behavior of the native vp9 decoder vs libvpx-vp9 re: alpha is the root cause.
  • Requires the ffmpeg build to have libvpx enabled (already required elsewhere in the project for HyperFrames/VP9 work).
  • No change to behavior for non-.webm overlays.

🤖 Generated with Claude Code


Summary by cubic

Preserves alpha in .webm overlays by forcing the libvpx-vp9 decoder in build_final_composite, fixing black frames from VP9+alpha sources. Other overlay formats are unaffected.

  • Bug Fixes
    • For .webm overlays, add -c:v libvpx-vp9 before -i so ffmpeg decodes to yuva420p and the overlay filter honors transparency.
    • Prevents opaque black output caused by the native VP9 decoder dropping alpha.

Written for commit 257db63. Summary will update on new commits.

Review in cubic

…preserved

ffmpeg's native VP9 decoder decodes alpha-carrying WebM (alpha stored as a
side-data plane) to opaque yuv420p. As a result a full-frame transparent
overlay (e.g. a caption or lower-third track exported as VP9+alpha) becomes an
opaque black layer that hides the base video and every overlay beneath it.

Force `-c:v libvpx-vp9` on `.webm` overlay inputs in build_final_composite so
the alpha-aware decoder is used and overlay transparency is honored. mp4/other
overlays are unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="helpers/render.py">

<violation number="1" location="helpers/render.py:522">
P1: Extension-based decoder selection for .webm files is incorrect — WebM is a container that can hold VP8, VP9, or AV1 video. Forcing `libvpx-vp9` (a VP9-only decoder) for all `.webm` files will cause ffmpeg decode failure and abort the render when the overlay uses VP8 or AV1.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread helpers/render.py
# decoder drops it (decodes to yuv420p → opaque), which turns a full-frame
# transparent overlay into an opaque black layer. Force the alpha-aware
# libvpx-vp9 decoder so overlay alpha is honored.
if ov_path.suffix.lower() == ".webm":

@cubic-dev-ai cubic-dev-ai Bot Jun 6, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: Extension-based decoder selection for .webm files is incorrect — WebM is a container that can hold VP8, VP9, or AV1 video. Forcing libvpx-vp9 (a VP9-only decoder) for all .webm files will cause ffmpeg decode failure and abort the render when the overlay uses VP8 or AV1.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At helpers/render.py, line 522:

<comment>Extension-based decoder selection for .webm files is incorrect — WebM is a container that can hold VP8, VP9, or AV1 video. Forcing `libvpx-vp9` (a VP9-only decoder) for all `.webm` files will cause ffmpeg decode failure and abort the render when the overlay uses VP8 or AV1.</comment>

<file context>
@@ -515,7 +515,14 @@ def build_final_composite(
+        # decoder drops it (decodes to yuv420p → opaque), which turns a full-frame
+        # transparent overlay into an opaque black layer. Force the alpha-aware
+        # libvpx-vp9 decoder so overlay alpha is honored.
+        if ov_path.suffix.lower() == ".webm":
+            inputs += ["-c:v", "libvpx-vp9", "-i", str(ov_path)]
+        else:
</file context>
Fix with cubic

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant