Combining SAM2 Masks on one clip

I have 2 SAM2 masks which i want to combine and use on one clip using the Shape Alpha mask effect without one mask overriding or distorting the other mask. I have looked online but I can’t find anything which was clear and easy to understand. Does anyone know how to combine two Shape Alpha masks to create one combined mask?

Try it with a mask stack: Masking — Kdenlive Manual 25.08 documentation

Use: shape alpha (mask) and mask apply.

Here a video with rotoscoping for inspiration: https://www.youtube.com/watch?v=GbzPooeGYeU

I tried but they would just seem to cancel each other out when I did the mask stacking:

httpss://streamable.com/m3huq5

Hi, and welcome to the forum and community.

The Shape Alpha effect cannot be stacked as suggested as stacking requires all subsequent alpha shapes to have a different operator to prevent overwriting the first one.

Here is a workaround to combine SAM2 masks:

  1. Create the masks
  2. Locate the .mkv files in your filesystem (right click on the mask in the list and select Open Containing Folder)
  3. Load them into your project bin
  4. Add them to the timeline and put them into different tracks on top of each other (assuming they are of the same length)
  5. Render that project (or define a timeline zone just for the mask files and render that) using the V9 WEBM render preset. This creates a file with an alpha channel and turns black into alpha.
  6. In your main project add the Shape Alpha effect to the clip, select Custom and then the .webm file you just created

Another option is to use sequences:

  1. Create a mask and apply it to a clip
  2. Put that clip into a sequence
  3. Create a mask for the sequence
1 Like

Thanks, One more question: How would I invert the .mkv mask when I import it into kdenlive to combine?

Use the invert0r or invert effect

It just seems to change the red colour of the mask to a cyan colour

Sorry. My bad. Use the Alpha Operations effect, set Operation to Threshold, set Threshold to 0, and enable Invert.

I did that and it removed the red from the mask, but when i put the exported the combined mask .webm and I put it on my clip, it still looks the same as if the one mask hasn’t been inverted.

Can’t you just set the Invert flag in the Shape Alpha effect with the mask?

I did but it didn’t seem to do anything except remove the red part of the mask and it didn’t seem to invert it after i exported the mask. Sorry if this is a bit vague.

It is, so let’s discuss this in more detail in a private conversation and come back here with the solution.

Is there a way to take a SAM2 mask and invert it, then save the inverted mask to a file like a .mkv. Is it easier to do it with the original .mkv mask opened as a video clip in another project or while its loaded as a mask into a kdenlive project?

Please see the message I sent you directly here on Discuss. Check the My messages link in the left-hand sidebar.