Log in

View Full Version : Overlay? Or similar... Help please!


Floatingshed
5th November 2014, 19:18
I need pointing in the right direction...

I have two pieces of film. One is aged and fairly poor but has text over-layed. The other is the same footage but without the text.
The text is made from modified fonts making it very difficult to re-create.

My aim is to overlay the text from the bad film on the clean footage.

Madness? Thanks for any help.

johnmeyer
5th November 2014, 19:45
I have two pieces of film. One is aged and fairly poor but has text over-layed. The other is the same footage but without the text. The text is made from modified fonts making it very difficult to re-create. My aim is to overlay the text from the bad film on the clean footage.I did exactly the same thing about nine months ago. I was given a pristine DVD of a Canadian film, "Maria Chapdelaine." The only audio was in French, but the person who sent it to me who is Canadian and speaks French, wanted to watch it with his wife, who does not speak that language.

I was able to find, on YouTube, a version of that film, taken from a VHS transfer, which had embedded English subtitles. The YouTube video was, of course, significantly inferior quality. I wanted to take the subtitles from the poor quality YouTube transfer and put them onto the good video from the DVD.

I succeeded, and the result was quite watchable, but I never once thought of using AVISynth. IMHO, AVISynth is the wrong tool for the job.

My solution was to first use IVTC to get both copies of the movie into native 23.976 progressive format. I then put them both into Sony Vegas. Next -- and this is one of many reasons why I don't think AVISynth is going to work for you -- I used the "pan/crop" tools in Vegas to align the two copies. The VHS version was a 4:3 transfer, whereas the DVD was 16:9. Even without this difference, the overscan issues meant that the VHS version needed to slightly reduced in order to overlay the DVD version.

The subtitles were mostly in a bright yellow font. I used the Secondary Color Corrector fX to create a mask which allowed anything yellow to show through onto the good DVD transfer. I enlarged the mask slightly to ensure that the fonts were full and looked natural. I also added a "garbage mask" over the top 4/5 of the VHS video so that anything yellow in the upper part of the video wouldn't get overlaid, no matter what.

For places where this didn't work, or where the fonts were not yellow, such as the scenes taken of bright snow, I simply used a rectangular mask.

It took at least an hour of editing work to modify and check the "automatic" masks, and to create manual overrides, where necessary.

Bottom line: there were just too many unanticipated variations in size, color and placement to let the automatic technique work every time. You need tools which let you interact with each section of video, and make manual adjustments.

poisondeathray
5th November 2014, 21:18
Can you describe the text characteristics, or better yet or post a video sample?

While there are definitely other tools that are suited to this type of task (e.g. after effects), you might be able to do some of the mask generation in avisynth. You can still do manual refinements by compositing with free tools like aviutl

For example, if you had yellow text , you could use MaskHS() isolating by hue , saturation, combined with masktools to refine the mask . There are examples of how to do this in various threads here and other forums

foxyshadis
6th November 2014, 02:06
Huh, I've had a project exactly like this on my back burner for months, a really crappy DVD (not sure if legit) and a not-as-crappy German-subtitled DVD. Thanks for the hints, maybe I'll look into tackling it soon.

StainlessS
6th November 2014, 06:18
Perhaps of some use:

Function RT_RgbInRangeLocate(clip c,int "n"=current_frame,int "Delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,int "Baffle"=8,float "Thresh"=0.0, \
int "RLo"=128,int "RHi"=255,int "GLo"=128,int "GHi"=255,int "BLo"=128,int "BHi"=255, \
String "Prefix"="RGBIRL_",bool "Debug"=false,int "Baffle_W"=Baffle,int "Baffle_H"=Baffle)

Function to scan frame n+delta for an area where percentage of pixels in all 3 RGB channels range cLo to cHi (inclusive, c==R or G or B)
breaks a threshold over at least Baffle consecutive number of scanlines (all four sides).
Returns True on Successful location else false. On success sets Local var Coords.

RT_RgbInRangeLocate() tests scanlines from outer most scanlines (h and v), towards inner most, stops where it finds Baffle consecutive scanlines
that contain more than Thresh percent of pixels in range cLo to cHi. Object interiors are not tested and so could be hollow.
Would also give +ve result for a disjoint shape like this
--
| |
--
Args:
n: default = current_frame in runtime environment.
Delta: Default = 0
X:Y:W:H: All default=0 as in crop. Area to search, default is full frame.
Baffle: Default=8, minimum number of scanlines that must have a percentage of pixels in range Lo to Hi, greater than Thresh. Avoids noise.
Thresh: Default=0.0 (0.0->100.0). Percentage pixels above which breaks Threshold.
Default is any pixel with all three channels in range cLo to cHi, will break threshold.
RLo: Default 128, lower bound of pixel values of Red Channel to search for.
RHi: Default 255, upper bound of pixel values to Red Channel search for.
GLo: Default 128, lower bound of pixel values of Green Channel to search for.
GHi: Default 255, upper bound of pixel values to Green Channel search for.
BLo: Default 128, lower bound of pixel values of Blue Channel to search for.
BHi: Default 255, upper bound of pixel values to Blue Channel search for.
Prefix: Default "RGBIRL_", prefix for Local Var coords set on successful location of object, eg RGBIRL_X, RGBIRL_Y, RGBIRL_W, RGBIRL_H.
Debug: Default false. If true outputs info to debugView.
Baffle_W, Default Baffle. Thickness of Left and Right side vertical edges, silently limited to width W of search area.
Baffle_H, Default Baffle. Thickness of Top and Bottom horizontal edges, silently limited to height H of search area.


Demo from RT_Stats zip:

# RGBInRangeLocate_Test

RED =$AA # Object Color to look for
GREEN =$CC
BLUE =$FF

OBJECT_W = 10 # Object Width
OBJECT_H = 10 # Object Height

AREA_X = 0 # Area of frame to search (0,0,0,0=full frame, As Crop)
AREA_Y = 0
AREA_W = 0
AREA_H = 0

R_MIN = RED R_MAX = RED
G_MIN = GREEN G_MAX = GREEN
B_MIN = BLUE B_MAX = BLUE

# Overlay Converts RGB->YUV->RGB (can set inexact color). Use Layer Instead, MUST set ALPHA
RGBA=((255 * 256 + RED)*256+GREEN)*256+BLUE

COORDINATES="RGB_Coordinates.txt"

# Fake input clip, for testing
a = BlankClip(length=480,width=480,height=480)
b = a.BlankClip(width=OBJECT_W, height=OBJECT_H, color=RGBA)
a.Animate (0, a.FrameCount () - 1, "Layer", b,"add",257, 0, 0, b,"add",257, 479, 479)

NOTFOUND="NOT FOUND" # Will be NOT FOUND, As OBJECT moves out of frame at end of clip (can no longer find size OBJECT_W x OBJECT_H)
sep = ", "
Ket = "] "
RT_FileDelete(COORDINATES) # Delete coordinates file
DEBUG=False
ScriptClip ("""
Bingo=RT_RgbInRangeLocate(x=AREA_X,y=AREA_Y,w=AREA_W,h=AREA_H,
\ RLo=R_MIN,Rhi=R_MAX,GLo=G_MIN,Ghi=G_MAX,BLo=B_MIN,Bhi=B_MAX,Baffle_W=OBJECT_W,Baffle_H=OBJECT_H,debug=DEBUG)
(Bingo) ? WriteFile (COORDINATES,"current_frame", "Ket", "RGBIRL_X", "sep", "RGBIRL_Y")
\ : WriteFile (COORDINATES,"current_frame", "Ket", "NOTFOUND")
""")

Floatingshed
6th November 2014, 19:23
Plenty to think about there, thanks guys.
I will tackle it again when I finish the run of night shifts I start tomorrow, brain will be useless for the next week!

Kein
4th March 2015, 19:04
Didn't want to create another thread since I have similar question: I need to overlay customizable text (position, render effects a-la stroke/shadow) over specific parts of the video with fadein/out effects (applies text clip only), each segment through whole base clip has its own text clip overlayed ("chapters"). Since I want to preserve original colorspace (YV12), no NLE suitable here and AviUtil crashes too often when I try to use layers so I guess I'm stuck with avisynth.

What would be the easiest and efficient way to do what I want? Subtitle()/SubtitleEx()?

poisondeathray
4th March 2015, 19:17
Didn't want to create another thread since I have similar question: I need to overlay customizable text (position, render effects a-la stroke/shadow) over specific parts of the video with fadein/out effects (applies text clip only), each segment through whole base clip has its own text clip overlayed ("chapters"). Since I want to preserve original colorspace (YV12), no NLE suitable here and AviUtil crashes too often when I try to use layers so I guess I'm stuck with avisynth.

What would be the easiest and efficient way to do what I want? "Subtitle()"?

It's actually a very different topic...

But anyways, it depends what you mean specifically by "customizable text" . If subtitle can do what you want, then yes that would be the easiest.

Even if you have fancy title effects, or things you needed to do in other programs in RGB, when you use mt_merge() or overlay(), the base clip in YV12 isn't affected, only the small overlay would be affected (if it was RGB, it would be converted to YUV)

Kein
4th March 2015, 19:39
It's actually a very different topic...
Heh, my main concern was just to avoid creating another thread.

But anyways, it depends what you mean specifically by "customizable text" . If subtitle can do what you want, then yes that would be the easiest.

Even if you have fancy title effects, or things you needed to do in other programs in RGB, when you use mt_merge() or overlay(), the base clip in YV12 isn't affected, only the small overlay would be affected (if it was RGB, it would be converted to YUV)

For now SubtitleEx does its job, but I always look forward.

Okay, so let's say I made some super-fancy text-title clip and want to merge with original YV12 base video using some dissolve/fade effects for more consisten integration - during the merging, RGB-clip will be automatically converted into base video colorspace, as you say, or do I need to something here into consideration?

poisondeathray
4th March 2015, 19:55
Okay, so let's say I made some super-fancy text-title clip and want to merge with original YV12 base video using some dissolve/fade effects for more consisten integration - during the merging, RGB-clip will be automatically converted into base video colorspace, as you say, or do I need to something here into consideration?

Yes, if you use overlay() with an RGBA overlay clip - only the RGB overlay portion will get converted internally to YUV444 . Those areas not "covered" on the baseclip will not incur any losses and will still be YV12

creaothceann
4th March 2015, 22:58
Have you checked if subtitle renderers (http://avisynth.nl/index.php/External_filters#Subtitling) work directly in YV12? xy-vsfilter (https://code.google.com/p/xy-vsfilter/) allegedly does.

Just create the subtitles in AegiSub.

Kein
5th March 2015, 08:31
Well, to be honest, I don't need subtitles exactly per se, I need something like "annotations" or "Sony Text" (Vegas) but mostly text based with small additions a-la rectangle box (fill/transparent). Fro now, SubtitleEx works for me with its basic, though.

foxyshadis
5th March 2015, 09:11
If you need fancy, you need ASS and some variant of vsfilter. It has been done with Animate and Subtitle, but it's slow and incredibly painful, whereas actual subtitle renderers do all of the heavy lifting for you.

Kein
5th March 2015, 09:57
If you need fancy, you need ASS and some variant of vsfilter. It has been done with Animate and Subtitle, but it's slow and incredibly painful, whereas actual subtitle renderers do all of the heavy lifting for you.

Yeah, I'm looking at VSFilterMod right now.