View Full Version : Newb needs help with overlay.
Arashi
3rd July 2007, 16:38
Hi all. I have a small problem with a weird project I'm working on for my employer. I have a series of separate videos I'm encoding, some to different resolutions. They all will have some animated text, logos and some signs covered. The overlays will occur at the same spots on each video with the only difference possibly being the resolution.
I figured the easiest way to do this would be to put all the overlays into a separate video, that I could later resize in the avisynth script, with a black background using balckclip(color=$000000). Then I created a mask using mt_binarize(16) since I figured anything over a luma threshold of 16 would be my overlays and then used that mask to overlay a video.
I started with just using some simple animated text I created with a .ass script and a small test video. The result was less than perfect with some of the black from the background showing around the text in the final video. I thought maybe mt_lutxy would maybe work but it's a little more than I could get my head around. I tried a couple chromakey searches but the examples in the results didn't help me much there.
Am I doing something wrong or is this beyond the scope of avisynth? If it's not doable in avisynth can Aftereffects handle it. I'm sure my employer would like to use a freeware alternative but we've almost got him convinced to splurge for a good CS3 package and needing Aftereffects may convince him. :p
Wilbert
3rd July 2007, 17:08
I started with just using some simple animated text I created with a .ass script and a small test video. The result was less than perfect with some of the black from the background showing around the text in the final video.
I think that the problem is that your mask (with animated subs) is not entirely black and white. It's a bit gray around the subs. You can solve this by using levels (map light gray to white and dark gray to black), or use the tolerance levels in ColorKeyMask to create a new mask which is entirely black and white.
Arashi
3rd July 2007, 17:25
Thanks for the quick reply. If I understand right ColorKeyMask needs RGB input and my video is YV12 so a colorspace conversion would be needed. I think I want to avoid that since it degrades quality.
So with levels would something like levels(20,1,220,0,255) be a good start or at least am I in the right ballpark? I don't have the video here to play with right now to test.
Didée
3rd July 2007, 18:01
Wilbert - there should not be any "bit gray" around the subs. Arashi says he used mt_binarize to create the mask, mt_binarize outputs nothing but pixels either 0 or 255.
Arashi - it would help to see pics of the subs & the mask (short clips would be even better, to have things in the original colorspace), and the script you're actually using. From your description, I fail to see at which points things are going wrong. (Smells a bit like that it could be related to halos that are rendered around the letters.)
Arashi
3rd July 2007, 18:37
I'll certainly post some sample clips when I can. The original materials are locked up in an office untill Thursday. If I can't get in I can easily reproduce them tonight at home.
Didée, by halo, do you mean like the edge enhancement I'm always using your scripts to get rid of from my anime?
Didée
3rd July 2007, 20:02
I mean the "aura" around letters, often used to ensure that the text has enough contrast to stay readable against all possible backgrounds.
blankclip(color=$808080,width=80,height=40)
Subtitle("Hello",size=24,x=12,y=8)
http://img78.imageshack.us/img78/8525/textwithauragl1.png (http://imageshack.us)
Wilbert - there should not be any "bit gray" around the subs. Arashi says he used mt_binarize to create the mask, mt_binarize outputs nothing but pixels either 0 or 255.
I'm pretty sure his original titles were anti-aliased. So mt_binarize is going to make the mask opaque everywhere around the letters where there's the slightest hint of a dark gray (or lighter) pixel due to anti-aliasing, leading to ugly aliased 1-pixel borders around the letters in the mask...
If the text is just white text on a black background, why not use the image itself as the mask and overlay a single-color clip using that mask? That'll give nice anti-aliased edges around the text to boot...
np: The Orb - Ultraworld Ten - A Huge Evergrowing Pulsating Brain That Rules From The Centre Of The Ultraworld (Live Mix Mk 10) (Adventures Beyond The Ultraworld (Disc 2))
Didée
4th July 2007, 00:50
Ah, of course! You hit the bull's-eye: 100 points.
One more contra-example of binary masking. Masking the text overlay by just itself should do it. (But remember to expand the mask from [16,235] to [0,255] to avoid surprises.)
And a notorious opponent of binary masks didn't see the point ... funny. :D
Arashi
4th July 2007, 06:53
Here is a sample (http://www.savefile.com/files/862836).
Didée
4th July 2007, 16:01
OK. The diagnosis stays, it's like Leak said.
Your initial way with binary masking:
vid = AviSource("bg.avi")
ovl = AviSource("overlay.avi")
msk = ovl.mt_binarize(16)
overlay(vid,ovl,mask=msk)
http://img128.imageshack.us/img128/4412/binarymaskedlu7.png (http://imageshack.us)
The better way with self-masking:
vid = AviSource("bg.avi")
ovl = AviSource("overlay.avi")
msk = ovl.ColorYUV(levels="TV->PC")
overlay(vid,ovl,mask=msk)
http://img152.imageshack.us/img152/2323/selfmaskedin2.png (http://imageshack.us)
For a quick&dirty adjustment of the outlining, you could replace ColorYUV with
Levels( x, 1.0, y, 0,255,false)
x>>16, y=235 --> weaker outlining
x=16, y<<235 --> stronger outlining
Arashi
5th July 2007, 06:32
:thanks:
Your solution seems to work but with the several internet outages I've endured since yesterday I managed to come up with another solution too and that was to create a separate .ass script the same as the first only with pure white lettering to use for the mask. Your way seems more eloquent.
I thought I read in another post that in the future avisynth may have some sort of HSV masking feature; any truth to that? Seems like it would be useful.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.