Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

Domains: forum.doom9.org / forum.doom9.net / forum.doom9.se

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage
Register FAQ Today's Posts Search

Reply
 
Thread Tools Search this Thread
Old 6th October 2007, 19:33   #1  |  Link
Shubin
Registered User
 
Join Date: Jul 2003
Posts: 52
Static mask - how ?

I've read all things about masks in masktools and avisynth doc, and I think (maybe I'm wrong here) that only moving masks are supported. But I need a static mask.

What's the difference ?

In moving mask you have an overlay clip that contains some areas that should be removed. This is done with a mask. What is masked, is not visible. The mask is "tied" to an overlay clip.

In static mask you have a base clip and want to replace some areas of it with an overlay clip. In this case the mask is "tied" to the base clip. An example is usually seen in 50-s films : when the car is moving, the view from the window changes, but it is visible that it is another movie overlayed on first one.

Technically I have a clip and want to replace some areas of it, calculated using the clip colors, with contents of another clip which has different size and typically will move around.

How can I do it ? Should I write another plugin ?
Shubin is offline   Reply With Quote
Old 7th October 2007, 01:11   #2  |  Link
foxyshadis
Angel of Night
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Tangled in the silks
Posts: 9,569
A truly static mask can be inserted with imagesource("").converttoyv12(matrix="pc.601"), if you have it in a png or whatever. If you're bluescreening, ColorKeyMask might be what you need. If you have more complex needs, you might need a lut or even a custom plugin.
foxyshadis is offline   Reply With Quote
Old 7th October 2007, 01:15   #3  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
A static mask is fixed for all frames in the clip, typically you provide it in a single image file (.bmp, .png, etc).

A moving mask has a unique mask for each frame in the clip, it will be a separate clip in it's own right. The degenerate case is that all the frames are the same, i.e. it reverts to being a static mask.

These should not be confused with a motion mask which is used to select areas in a frame that are different from related areas in adjacent frames.

To turn a single frame clip into many frames use "Loop(n)".

To freeze 1 frame in a clip to many frames use "FreezeFrame(n, start, end)"

To build a mask clip to track an area of a particular colour use "ColorKeyMask".

MaskTools has many other features to manipulate masks and images in advance of the limited tools native to avisynth.
IanB is offline   Reply With Quote
Old 7th October 2007, 08:58   #4  |  Link
Shubin
Registered User
 
Join Date: Jul 2003
Posts: 52
Yes, I understand this. I've made a static mask from the png picture and Loop() already. But the problem remains. Using Overlay function I can apply mask to the OVERLAY clip, but I need to apply it to the BASE clip. I cannot simply exchange clips, because the ovrlay clip should move relative to base clip and the mask.

What I need is to "cut a window" in a base clip and see moving overlay clip through it.
Shubin is offline   Reply With Quote
Old 7th October 2007, 09:38   #5  |  Link
foxyshadis
Angel of Night
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Tangled in the silks
Posts: 9,569
overlay(base,new,mask) doesn't work? The behavior your describe is exactly what you should be getting, if the mask is working. You can also use mt_merge, which is strictly weighting based on the mask, no fancy blending modes.

As a test, output the mask to be sure that it's actually showing up the way you want it to.
foxyshadis is offline   Reply With Quote
Old 7th October 2007, 10:17   #6  |  Link
Shubin
Registered User
 
Join Date: Jul 2003
Posts: 52
Quote:
Originally Posted by foxyshadis View Post
overlay(base,new,mask) doesn't work?
No. It says "Mask clip should be the same size as overlay clip". In my case it is the same size as the base clip.
Shubin is offline   Reply With Quote
Old 7th October 2007, 13:14   #7  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Sounds like you need to invert your mask. i.e. swap transparent and opaque areas.

Overlay(base, overlay, mask) == Overlay(overlay, base, mask.Invert())
IanB is offline   Reply With Quote
Old 7th October 2007, 14:56   #8  |  Link
Shubin
Registered User
 
Join Date: Jul 2003
Posts: 52
Quote:
Originally Posted by IanB View Post
Sounds like you need to invert your mask. i.e. swap transparent and opaque areas.
I do not think that it will change its size...
Shubin is offline   Reply With Quote
Old 7th October 2007, 16:05   #9  |  Link
Wilbert
Super Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,392
What size is the mask? What size is the overlay-clip? What size is the base-clip?
Wilbert is offline   Reply With Quote
Old 7th October 2007, 19:26   #10  |  Link
Shubin
Registered User
 
Join Date: Jul 2003
Posts: 52
Quote:
Originally Posted by Wilbert View Post
What size is the mask? What size is the overlay-clip? What size is the base-clip?
The size of the mask is exactly the same as the size of the base clip : 720*576. The overlay clip is smaller, 640*480
Shubin is offline   Reply With Quote
Old 7th October 2007, 20:28   #11  |  Link
foxyshadis
Angel of Night
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Tangled in the silks
Posts: 9,569
Well, I really don't think the error can get much more explicit. Crop your mask down, inside or outside avisynth, to match the overlay instead of the base clip. And if the overlay isn't supposed to start at 0,0 (upper left corner) make sure you use x and y. Alternately, pad/crop/resize your overlay clip to match the base.
foxyshadis is offline   Reply With Quote
Old 7th October 2007, 21:57   #12  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,182
may be you need not in static but in sliding (tracking feature) mask for base clip?
__________________
My Avisynth plugins are now at http://avisynth.org.ru and mirror at http://avisynth.nl/users/fizick
I usually do not provide a technical support in private messages.
Fizick is offline   Reply With Quote
Old 7th October 2007, 23:22   #13  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
and a matching copy of a good example frame from each of the base, overlay and mask. Plus a quick hand painted version of what you expect the output to look like (just use paint?? to paste approximate parts of the overlay onto the base) (highly compressed jpeg will be okay)
IanB is offline   Reply With Quote
Old 8th October 2007, 06:18   #14  |  Link
Shubin
Registered User
 
Join Date: Jul 2003
Posts: 52
Here I tried to draw what I want to do. The upper picture shows what I already know how to make - the mask has the same size as an overlay clip, and when the overlay clip moves (using Animate) the mask moves with it.

The lower picture shows what I need. The mask has the same size as the base clip, and always stays at the same place.
Attached Images
File Type: png mask.png (18.8 KB, 189 views)
Shubin is offline   Reply With Quote
Old 8th October 2007, 08:31   #15  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
As I said previously you will need to abuse this relation
Quote:
Originally Posted by ianb
Overlay(base, overlay, mask) == Overlay(overlay, base, mask.Invert())
With a bit of trickery, you extend the Overlay clip enough so you do not clip the original base clip, I chose 100 on all sides but knowing how X and Y vary you can pick better values. Slide the Base clip over the Overlay in the opposite direction. When done crop off the unused bits of the Overlay, I used PointResize to avoid any mod 2 restrictions that a straight crop might have.
Code:
...
InvOlay=Base
H=Base.Height()
W=base.Width()
InvMask=Mask.Invert() # Make middle blob transparent
InvBase=Olay.AddBorders(100,100,100,100) # extra room
Overlay(InvBase, InvOlay, 100-X, 100-Y, InvMask)
PointResize(W, H, 100-X, 100-Y, W, H) # Restore base
IanB is offline   Reply With Quote
Old 9th October 2007, 06:05   #16  |  Link
Shubin
Registered User
 
Join Date: Jul 2003
Posts: 52
Thank you, IanB, I'll try this
Shubin is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:10.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.