Log in

View Full Version : Interlaced VHS Cleaning with resize does not output correct interlaced video


papcom
19th September 2015, 23:15
I experiment with a script basically made by johnmeyer. I have added a crop and resize function, and I use autoadjust for Color and Levels, as well as a sharpen stage.

Principally it works fine but the result does not Output a correct interlaced TFF Video. There is something wrong with the fields.

Unfortunately I do not understand why it makes this field mess. It should output a TFF Video as is the Input. I think the various process stages are not in correct order. But how should it be?

Can anybody help me with this. I would appreciate it very much. Here is the VHS script:

#original Denoiser script for interlaced video using MDegrain2i2_by JMH

SetMemoryMax(1024)
Loadplugin("C:\Program Files (x86)\AviSynth 2.5\plugins\mvtools2.dll")
LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\cnr2.dll")

SetMTMode(5,6)
#~ source=AVISource("E:\fs.avi").killaudio().AssumeTFF().waveform().Crop(12, 4, -12, -8)
source=qtinput("D:\videodata.mov", color=2, audio=0).ConvertToYV12.AssumeTFF().Crop(12, 0, -12, -8) # Crops xx pixels L,T,R,B and resizes to 720x576ilaced:
SetMTMode(2)

#CHROMA RESTAURATION specially for analog source material
chroma=source.Cnr2("oxx",8,16,191,100,255,32,255,false) #for VHS/V8
#chroma=source.Cnr2("oxx",8,14,191,75,255,20,255,false) #for Laserdisc

#Set overlap in line below to 0, 2, 4, 8. Higher number=better, but slower (BLOCKSIZE/OVERLAP/STRENGTH/DCT) / Increase thSAD Value for more degraining
#~ output=MDegrain2i2(source,4,0,400,0) #For VHS, better results in shadows
#~ output=MDegrain2i2(source,8,2,300,0) #For Hi8, good noise reduction
output=MDegrain2i2(chroma,8,4,300,0) #Retains a little more detail, but slower
#output=MDegrain2i2(chroma,4,2,400,0) #Better for retaining detail on flat surfaces, but slower still

#-CHOOSE OUTPUT to display compared view or only processed output
output=IResize(output,720,576)
#~ StackHorizontal(source,output)
#~ return output.Levels(16, 1, 235, 0, 255, coring=false) #simple Level Adjust
return output.AutoAdjust(auto_balance=false, chroma_limit=1.05, auto_gain=true, gain_mode=0, chroma_process=100, gamma_limit=1.25, high_quality=false) #Auto Color and Level
#~ return output

#-------------------------------

function MDegrain2i2(clip source, int "blksize", int "overlap", int "strength", int "dct")
{
fields=source.SeparateFields() # separate by fields

super = fields.MSuper(pel=2, sharp=1)
backward_vec2 = super.MAnalyse(isb = true, delta = 2, blksize=blksize, overlap=overlap, dct=dct)
forward_vec2 = super.MAnalyse(isb = false, delta = 2, blksize=blksize, overlap=overlap, dct=dct)
backward_vec4 = super.MAnalyse(isb = true, delta = 4, blksize=blksize, overlap=overlap, dct=dct)
forward_vec4 = super.MAnalyse(isb = false, delta = 4, blksize=blksize, overlap=overlap, dct=dct)

MDegrain2(fields,super, backward_vec2,forward_vec2,backward_vec4,forward_vec4,thSAD=strength)

#Optional sharpening steps
unsharpmask(50,3,0)
sharpen(0.1)

Weave()
}

function IResize(clip Clip, int NewWidth, int NewHeight)
{
Clip
SeparateFields()
Shift=(GetParity() ? -0.25 : 0.25) * (Height()/Float(NewHeight/2)-1.0)
E = SelectEven().Spline36resize(NewWidth, NewHeight/2, 0, Shift)
O = SelectOdd( ).Spline36resize(NewWidth, NewHeight/2, 0, -Shift)
Ec = SelectEven().Spline36Resize(NewWidth, NewHeight/2, 0, 2*Shift)
Oc = SelectOdd( ).Spline36Resize(NewWidth, NewHeight/2, 0, -2*shift)
Interleave(E, O)
IsYV12() ? MergeChroma(Interleave(Ec, Oc)) : Last
Weave()
}

wonkey_monkey
20th September 2015, 00:35
IResize separates fields and resizes (or so it seems at a glance), but after separating fields you've really got non-contiguous rows above and below each other, which won't resize nicely if you're changing the vertical resolution. And you do seem to be cropping 8 pixels off the bottom before your resize to 720x576...

But I might be missing something.

hydra3333
20th September 2015, 09:48
seems about right from previous advice,
http://forum.doom9.org/showthread.php?p=1185790#post1185790

sure the source is TFF ? place AssumeTFF() before the function and on the end of the weave. does the cnr2 need separate and weave as well ?

papcom
20th September 2015, 11:16
Do You think that the crop is at the wrong Position? ... where shall I put the cropping? (I must be able to crop some Pixels at B/T/L/R in order to get rid of the nasty trash around VHS pics)

HELP:
The Problem is, that my script above results in a Video that has Field1 and Field2 identically !!!

Music Fan
20th September 2015, 16:25
Do you absolutely want to resize and avoid black borders ? Because you can simply replace cropped lines by black lines (and center video, thus add for example 4 lines on top and 4 below if you cropped 8 bottom lines), that's always what I do with VHS sources, I don't even de-interlace.
If you need temporal filters on interlaced sources, you can use JDL_UnfoldFieldsVertical ;
http://www.avisynth.nl/users/stickboy/
It separates fields and gather them one above the other, it's better than simply separate fields (which alternate top and bottom fields, not good for temporal filters).
It needs jdl-interlace.avsi and jdl-util.avsi.
Here is an example ;
source()
assumeTFF()
Crop(12,0,-12,-8)
JDL_UnfoldFieldsVertical(flip=true)#separate and gather fields, video becomes kind of progressive
spatial and/or temporal filters(...)
JDL_FoldFieldsVertical(flip=true)#re-interlace
addborders(12,4,12,4)
This is much faster than if you de-interlace and resize, you can compare with AVSMeter.
But of course, the result is not exactly the same than if you filter a de-interlaced video because filtering is done on flattened fields ; try and see if the result is good enough for you.
But it allows to avoid potential de-interlacing and resizing artifacts, each method has its benefits.
The argument flip=true flips only the bottom field, which makes both fields touching themselves by their bottom side (better for spatial filters).


edit : to open mov files (and also TS, mkv or mp4), LWLibavVideoSource may be better than qtinput, especially with interlaced h264.
Findable here (take L-SMASH-Works and put LSMASHSource.dll in Avisynth's plugins folder) ;
http://forum.doom9.org/showthread.php?p=1689573#post1689573

johnmeyer
20th September 2015, 17:35
I totally agree: do not resize, but instead crop.

papcom
20th September 2015, 18:05
thanks @musicfan and @jmh ...I will be pleased to try the border solution. But can You pls help me with the JDL Utility? I am not familiar with this. Where shall I put which code in my scipt?

Music Fan
20th September 2015, 19:46
You just have to put jdl-interlace.avsi and jdl-util.avsi (they include several functions) in Avisynth's plugins folder, then you will be able to use JDL_UnfoldFieldsVertical(flip=true) and JDL_FoldFieldsVertical(flip=true), as in my example.
If these functions are not detected, you will have to use Loadplugin in the debut of the script to load both avsi, as for the dlls in your script.

And of course you will have to modify your script to remove everything about resize an re-interlacing. Use all colors corrections and denoising between the 2 JDL... lines.

johnmeyer
20th September 2015, 21:32
The original script should work. Is this standard definition video? It appears that it might be, given that you are re-sizing to PAL SD. If your source is PAL SD, that is bottom field first, and therefore you need to change AssumeTFF to AssumeBFF.

Music Fan
20th September 2015, 23:08
Pal SD can be TFF.
And if he does not make resize, he can't use the original script as is.

papcom
23rd September 2015, 09:35
Black Borders can be a way to go, but anyway I search for the resized solution. I need a result without any border or blanking or head switching noise around the pic, and which finally has the standard SD-format of 720x576-25i.


(BTW: I work with SD 720x576 ProRes422-25i-PAL CCIR files, which are TFF, as defined in the prores-standard.)

hydra3333
26th September 2015, 03:54
Pal SD can be TFF.
Confirmed. All my PAL telly captures are TFF. DV is BFF ?

Music Fan
26th September 2015, 09:54
DV is BFF ?
Yes. And of course you can create sd BFF (for example if you wanna interlace 50p or 60p to make a dvd).