Log in

View Full Version : Would like help w/ Avisynth script converting VHS>DVD


abyss616
31st August 2012, 05:18
I'm trying to convert some old VHS tapes to DVD. While I'm a novice at Avisynth, I'm (very) slowly learning the finer points of interlacing and deinterlacing and things of that nature, but I'm far from an expert.

Through my reading I have learned that when working with interlaced material that will eventually be converted for use on a DVD, it is better to leave it that way and not deinterlace it. However, in my tests I have found that the end product looks a million times better when deinterlaced than the opposite. I assume this has to do with my lack of knowledge of Avisynth, which is why I'm asking for help.

I am capturing using a Hauppauge HD-PVR, which gives me an interlaced (TFF) .ts file. I demux using tsMuxer and mux the 264 file into an mkv.

This is my deinterlacing script:

SetMemoryMax(1000)
SetMTMode(5, 8)
Import("C:\Program Files (x86)\AviSynth 2.5\plugins\QTGMC-3.32.avsi")
LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\MT.dll")
LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\avss.dll")
LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\nnedi2.dll")
LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\mvtools2.dll")
LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\mt_masktools-25.dll")
LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\removegrainsse2.dll")
LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\repairsse2.dll")
LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\ffms2.dll")
v=DSS2("SNME2&IC.track_4113.mkv", fps=29.970)
a=WAVSource("SNME2&IC PID 1100 DELAY -78ms.wav")
AudioDub(v,a)
Crop(8,4,-8,-4)
ConvertToYV12(interlaced=true)
AssumeTFF()
LanczosResize(640,480)
SetMTMode(2)
QTGMC( Preset="Medium", EdiThreads=2 )
SelectEven()
Trim(293,24057)+Trim(24720,40175)+Trim(40750,54342)+Trim(58525,71655)+Trim(72345,90845)+Trim(91507,99835)+ \
Trim(100665,113315)+Trim(113934,122990)+Trim(123525,124687)+Trim(125326,126455)

This gives me good results on my .mkvs using x264 and DVDs using hcenc.

This is what I've tried to do with my interlaced script to encode to DVD format:

v=DSS2("SNME2&IC.mkv", fps=29.970)
a=WAVSource("SNME2&IC PID 1100 DELAY -78ms.wav")
AudioDub(v,a)

bob()
spline36resize(704,480)
assumetff().separatefields().SelectEvery(4,0,3).Weave()

I have tried the above script in several different orders and I get the same result - lots of motion noise and distortion that I don't get with deinterlaced material.

Would one of you kind souls please tell me what I'm doing wrong? Thanks.

johnmeyer
31st August 2012, 15:44
I agree that you should not deinterlace. However, unless you are re-sizing, I would recommend that you don't do any deinterlacing, even in the middle of the script. You can instead simply work on the odd and even fields separately and then combine the results together. Thus, I don't think you need to use QTGMC for this job.

I have copied below the starting point that I use when converting VHS tapes. This is the results of many years of tweaking and experimenting. This script always needs to be changed for every transfer because there is no single script that fits all VHS transfers. You will need to change the BFF to TFF if your video really is TFF.

I still use the old VirtualDub CNR plugin to remove the usual chroma shimmering artifacts common on VHS (especially 6-hour mode VHS), but there are more modern plugins that might work better.

Using transfer equipment that contains a time base corrector makes the biggest difference of all.

In addition, you should use an editing program that lets you interactively adjust the levels, and also correct for chroma shifts. Old VHS tapes definitely have issues with both color shifts and levels, and it is next to impossible to adjust these accurately with anything other than an interactive GUI editing program (I use Vegas, a program that includes built-in histogram and vectorscope displays).

The sharpening step is optional, and I often don't use it (and for goodness sake, make sure you turn off the VHS deck's built-in "HQ" sharpening by using the "edit" or "dub" switch on your deck!!). If you find you are getting halos around sharp dark/light transitions, then don't use sharpening. Even the more advanced "LimitedSharpenFaster" plugin can create these artifacts. When it comes to sharpening, less is more.

Finally, this script contains some lines which are commented out that are designed to reduce chroma halos. These often occur on 2nd generation VHS tapes, but can happen on other captures as well. The usual thing you will see is the color shifted to the right. The problem will be most evident around a brightly color object that is next to something of a contrasting color or luminescence value. If you see this, try setting the horizontal shift parameter to 2 and then uncomment the first of the two shift lines. As you can see, they are turned off in the script posted below and that is because I seldom use this feature. However, when it is needed, it can perform some real magic. When it is not needed, however, if you use it, you will find that it introduces the very thing it is designed to eliminate!

Oh yes, the overlap parameter (the second number fed to MDegrain2i2) does make a difference, but slows down the operation considerably. Read the comments, do some experiments, and make your own judgement.

#Denoiser script for interlaced video using MDegrain2
#This is my recommended starting point script for VHS as of April, 2012

SetMemoryMax(768)

Loadplugin("C:\Program Files\AviSynth 2.5\plugins\MVTools\mvtools2.dll")
LoadPlugin("c:\Program Files\AviSynth 2.5\plugins\CNR\Cnr2.dll")
#loadplugin("c:\Program Files\AviSynth 2.5\plugins\despot.dll")
#Loadplugin("C:\Program Files\AviSynth 2.5\plugins\Film Restoration\Script_and_Plugins\removegrain.dll")
Import("C:\Program Files\AviSynth 2.5\plugins\Film Restoration\Script_and_Plugins\LimitedSharpenFaster.avs")

SetMTMode(5,4)
#Modify this line to point to your video file
source=AVISource("E:\fs.avi").killaudio().AssumeBFF()
#source=AVISource("E:\fs.avi").AssumeBFF()
SetMTMode(2)

#Only use chroma restoration for analog source material
chroma=source.Cnr2("oxx",8,16,191,100,255,32,255,false) #VHS
#chroma=source.Cnr2("oxx",8,14,191,75,255,20,255,false) #Laserdisc
#Set overlap in line below to 0, 2, 4, 8. Higher number=better, but slower
#For VHS, 4,0 seems to work better than 8,2. Most of difference is in shadows
#However, 8,0 is good enough and MUCH faster. 8,2 doesn't seem to make much difference on VHS.

#output=MDegrain2i2(chroma,8,0,0)
output=MDegrain2i2(chroma,8,4,0) #Better, but slower

#output=IResize(output,720,480)

#stackvertical(source,output)
#stackhorizontal(source,output)
#return output.Levels(16, 1, 235, 0, 255, coring=false)

return output


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

function MDegrain2i2(clip source, int "blksize", int "overlap", int "dct")
{
Vshift=0 # 2 lines per bobbed-field per tape generation (PAL); original=2; copy=4 etc
Hshift=0 # determine experimentally
overlap=default(overlap,0) # overlap value (0 to 4 for blksize=8)
dct=default(dct,0) # use dct=1 for clip with light flicker

fields=source.SeparateFields() # separate by fields

#This line gets rid of chroma halo
#fields=MergeChroma(fields,crop(fields,Hshift,Vshift,0,0).addborders(0,0,Hshift,Vshift))
#This line will shift chroma down and to the right instead of up and to the left
#fields=MergeChroma(fields,Crop(AddBorders(fields,Hshift,Vshift,0,0),0,0,-Hshift,-Vshift))

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)

#Increasing thSAD doesn't seem to help
# MDegrain2(fields,super, backward_vec2,forward_vec2,backward_vec4,forward_vec4,thSAD=400)

# Eliminate next three lines and uncomment above line to use MDegrain2 instead of MDegrain3
backward_vec6 = super.MAnalyse(isb = true, delta = 6, blksize=blksize, overlap=overlap, dct=dct)
forward_vec6 = super.MAnalyse(isb = false, delta = 6, blksize=blksize, overlap=overlap, dct=dct)
MDegrain3(fields,super, backward_vec2,forward_vec2,backward_vec4,forward_vec4,backward_vec6,forward_vec6,thSCD1=400,thSAD=300)

#UnsharpMask( clip , int "strength" , int "radius" , int "threshold" )
#strength: strength. The default is 64.
#radius: the scope of the blurring process. The default is 3.
#threshold: threshold. Absolute value of the processing component is greater than the threshold blur. The default is 8.

unsharpmask(60,3,0) #not sure whether to put this before or after the weave.

#This function is unstable under SetMTMode
#limitedSharpenFaster(smode=1,strength=160,overshoot=50,radius=2, ss_X=1.5, SS_Y=1.5,dest_x=720,dest_y=480)
#LimitedSharpenFaster(strength=150) #Default strength=150

Weave()
}

Mounir
1st September 2012, 00:37
depends what kind of footage it is. If it's an anime you should do an ivtc for example (not a deinterlacing)
Also, it's preferable you crop toward the end of your script

If your source is an mkv(AVc/h264) and you have a nvidia card use a good decoder like dgdecNV see here (http://neuron2.net/dgdecnv/dgdecnv.html)

abyss616
5th September 2012, 01:31
@johnmeyer - I've tried the script you posted but I'm getting the same issues I had before. I've uploaded a sample and maybe you can point me in the right direction (or tell me I'm an idiot).

One scene is deinterlaced (QTGMC) and the other is using your script. When the graphics roll across the screen, there's a lot of noise distortion on the weaved clip, but not nearly as much on the deinterlaced one. I see the same thing on high-motion scenes. I get the same results using another method with assumetff.separatefields.SelectEvery.Weave - it looks almost exactly the same.

My inexperience in areas like this could be showing through and is making me miss an obvious point. But any help is appreciated. Thanks.

http://www.mediafire.com/?7b91u88a1182cxx

johnmeyer
5th September 2012, 01:36
The DVD structure you posted is the video after you have changed it. The only way I can help is if I have a clip of the original video.

Also, if you are viewing the interlaced video on a progressive display that doesn't support deinterlacing, then it won't look good. This doesn't actually mean anything and is normal. Thus, I would expect to see herring bone interlacing "teeth" on moving interlaced graphics, if those are shown on a progressive display.

abyss616
5th September 2012, 02:27
http://www.mediafire.com/?r1v3hbtfkwrbthj - Original TS file. DVD example was to show what I was talking about.

To check my output, I'm converting, burning to DVD then watching on a Vizio 32" TV. Thought I read that watching on a computer monitor was not the same as watching on a regular TV.

johnmeyer
5th September 2012, 16:59
These sure don't look like VHS tapes. I see very few VHS tape artifacts, but instead see a LOT of compression encoding artifacts. Since the AVC encoder used on the clip you sent to me was set to a reasonably high bitrate, it is hard to believe that it would make the video look so blocky.

But, whatever route the video went through to get to what you sent to me, it is definitely TFF interlaced footage. If you view the video in VirtualDub -- a program that does not deinterlace unless you include a plugin to do that -- and if you then freeze any frame, such as the flying titles, you will see interlaced herring bone patterns. If you do not understand interlacing, this effect is totally normal and is exceedingly misleading. The two fields of an interlaced frame are taken at moments in time that are 1/60 of a second apart. If you show them both at the same time (i.e., in a freeze-frame), and objects are moving, then you will inevitably see the two intertwined (interlaced) images. You would get the same mish-mash if you took two frames of film and projected them at the same time, except that those frames occupy the same point in space and so would completely overlap. However, when you actually watch the interlaced video on a display capable of handling interlaced video (either natively or through its own deinterlacing), one half of the frame (the upper field) is shown at one moment in time, and the other half (the lower field) is shown at the next moment in time, and your eye does not see any problem.

So, this freeze frame from your video is totally normal and does not indicate any problem whatsoever:

http://i177.photobucket.com/albums/w208/johnmeyer/interlaced.jpg

My advice is to concentrate instead on how to smooth the blocking artifacts. You might want to search these forums for solutions to that problem. You really don't have any of the usual issues involved with VHS transfers, at least not that I can see from this clip.

abyss616
6th September 2012, 00:13
Thanks for taking a look at it and sharing the info. I was able to ascertain earlier that it was TFF interlaced video by separating fields and viewing the 240p output in VirtualDub.

Maybe I'm focusing too much on one aspect of this, but it bugs me when I watch this back on my TV that the picture is distorted during any kind of heavy motion (like when the titles roll across the screen). Is this a result of viewing this on a device that does not natively support interlaced video? One of the reasons I started this thread is because I noticed it wasn't as bad when I deinterlaced it and I knew that shouldn't doing that for interlaced video.

The tapes look very good to me for their age (25 years) so I wasn't able to notice any compression issues, but that could be because I don't know exactly what to look for. I'll search and see what I can come up with.