[Partner Nodes] feat(bria): add Transparent option to Remove Video Background#14377
Draft
guill wants to merge 3 commits into
Draft
[Partner Nodes] feat(bria): add Transparent option to Remove Video Background#14377guill wants to merge 3 commits into
guill wants to merge 3 commits into
Conversation
…ckground Bria's /remove_background endpoint accepts background_color='Transparent' when paired with an alpha-capable container/codec; pass output_container_and_codec= 'webm_vp9' in that case (otherwise mp4_h264, unchanged). The returned WebM flows through ComfyUI's VIDEO type as a file reference, so Save Video with the default auto/auto settings stream-copies it byte-for-byte with the alpha plane intact (covered by new test_save_to_auto_preserves_vp9_alpha_via_stream_copy). BriaTransparentVideoBackground is kept as-is because it remains the supported path for the IMAGE+MASK workflow: Get Video Components currently cannot expose alpha for VP9 streams (PyAV's default vp9 decoder drops the side alpha layer), so the per-frame compositing workflow still needs the dedicated node that decodes via libvpx-vp9 itself.
- Move 'Transparent' to the end of the dropdown and set explicit default='Black' so newly-added nodes preserve prior behavior (review warning). - Reword node + tooltip descriptions to be honest that Save Video drops the alpha plane when its default .mp4 extension is used; direct users to the IMAGE+MASK node for any workflow that needs to persist alpha to disk today. - Update the dispatch comment with the same caveat.
- Rename test to reflect that it only validates the in-memory BytesIO stream-copy path; documents that the .mp4 file-path case (SaveVideo's default) drops alpha. - Flush the libvpx-vp9 decoder with decode(None) in the helper. - Rework BriaTransparentVideoBackground description to make it explicit that this is currently the only way to persist the alpha channel to disk.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Created by the Glary-Bot Agent
Why
Bria asked for the "Transparent" output to live inside the
Bria Remove Video Backgroundnode as just anotherbackground_colordropdown value, rather than a separateBria Remove Video Background (Transparent)node. This PR is the smallest change that adds it.Draft on purpose — there is a UX caveat we should decide how to handle before merging. See "Open question" below.
What changed
comfy_api_nodes/nodes_bria.py:BriaRemoveVideoBackgroundnow exposesTransparentin thebackground_colordropdown.background_color == "Transparent", the node sendsoutput_container_and_codec="webm_vp9"to Bria (Bria returns 422 if you pairTransparentwithmp4_h264). Everything else still sendsmp4_h264."Black"to preserve the prior implicit default;Transparentis at the end of the list.BriaRemoveVideoBackgroundandBriaTransparentVideoBackgroundreworked to make the division of labor explicit and call out the Save Video alpha-drop issue.BriaTransparentVideoBackground(the IMAGE + MASK node) is unchanged and not deprecated — see "Why both still exist".tests-unit/comfy_api_test/video_types_test.py:test_video_from_file_save_to_bytesio_stream_copies_vp9_alpha: builds a synthetic WebM/VP9 video with a deliberately varying alpha plane, runs it throughVideoFromFile.save_to(BytesIO, format=AUTO, codec=AUTO), and confirms alpha decodes back identically vialibvpx-vp9. Test name and docstring scope it precisely to the in-memory BytesIO path; the .mp4 file-path case (SaveVideo's default) is intentionally not covered because it drops alpha (see PR notes).Why both nodes still exist (and the new node isn't a full replacement)
I tested the end-to-end flow on a synthetic VP9 + alpha file, and there are two ComfyUI-core gaps that mean the consolidated node is not yet equivalent to the dedicated transparent node:
Get Video Componentscannot expose the alpha plane for VP9.VideoFromFile.get_components_internaldecodes with PyAV's defaultvp9decoder, which drops the side alpha layer before the alpha-detection code atcomfy_api/latest/_input_impl/video_types.py:291-321runs. The existingBriaTransparentVideoBackgroundworks around this by manually constructingCodecContext.create("libvpx-vp9", "r")(see_video_to_images_and_mask). Until core grows VP9-alpha decoding, anyone who wantsimages + masksockets has to use the dedicated node.Save Videowith defaultauto/autowrites a.mp4file, and muxing a VP9 stream into MP4 drops the alpha plane. Confirmed locally: source[50, 100, 151, 201, 251]per-frame alpha decodes back as[255, 255, 255, 255, 255]after a round-trip through a.mp4path.VideoContainerdoesn't have a WebM option today, so users can't simply pick a different format either.So
BriaTransparentVideoBackgroundis the only path that actually delivers an alpha-channel result to disk today. The PR makes that explicit in both nodes' descriptions.Open question for review
The consolidated "Transparent" option technically works — Bria returns the right file, the file passes through the graph carrying alpha bytes — but the only thing the user can do with it today is feed it back into the graph in memory or write it to disk losing alpha. Options:
WebMtoVideoContainer, teachSaveVideoto pick the right extension based on source codec/container, optionally surfaceVideoComponents.alphafromGetVideoComponents. Bigger blast radius (touches core video code that every node uses).I lean toward shipping this PR as-is and filing follow-ups for the two core issues — but it's your call. Not marking ready-for-review until that's decided.
Verification
ruff check comfy_api_nodes/nodes_bria.py tests-unit/comfy_api_test/video_types_test.py— clean.python -m pytest tests-unit/comfy_api_test/video_types_test.py—16 passed, including the new VP9-alpha round-trip test.VideoFromFile→save_toconfirmed (a) byte-exact alpha preservation when target isBytesIO/.webm, (b) alpha-dropping when target is.mp4(which is whatSaveVideodoes by default — the caveat we're being honest about).Follow-ups (not in this PR)
VideoFromFile.get_components_internalto fall back tolibvpx-vp9when the stream codec isvp9so alpha decoding works for every VP9 input, then surface an optionalmaskoutput onGetVideoComponents.webm_vp9toVideoContainer/VideoCodecand teachSaveVideoto choose the extension based on the source's container/codec when inautomode.BriaTransparentVideoBackgroundcan actually be deprecated.API Node PR Checklist
Scope
Pricing & Billing
If Need pricing update:
QA
Comms