- LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\tivtc.dll")
- LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\dgdecode.dll")
- LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\fieldhint.dll")
- DGDecode_Mpeg2Source("M:\TEMP\Andromeda Stories\Andromeda.d2v")
- FieldHint(ovr="M:\TEMP\Andromeda Stories\Andromeda.d2v.fh.txt")
- TDecimate(mode=1,cycle=5,ovr="M:\TEMP\Andromeda Stories\Andromeda.d2v.dec.txt")
- # now we are going to normalise the fuzzy right border.
- # the filtering uses masking and the pre-made masks always limit it to just one column.
- # imask3.bmp limits to column 718, imask4.bmp limits to column 717.
- # (they are black images of 16x480 resolution with a white line in the appropiate place).
- fm3 = imagesource(file = "M:\TEMP\terra e\imask3.bmp").converttoyv12(matrix="PC.601").mt_binarize()
- fm4 = imagesource(file = "M:\TEMP\terra e\imask4.bmp").converttoyv12(matrix="PC.601").mt_binarize()
- prefixcol = last
- workcol = crop(704,0,0,0)
- mt_merge(workcol,workcol.tweak(cont=1.250,sat=1.0),fm3, luma = true)
- mt_merge(last,workcol.tweak(cont=1.029,sat=1.74),fm4, luma = true)
- fixcol = last
- stackhorizontal(prefixcol.crop(0,0,-16,0),fixcol)
- # following line is useful to determine the values for tweak and check the effect
- #
- #return interleave(prefixcol.crop(704,0,0,0).pointresize(200,height).subtitle("before"),last.crop(704,0,0,0).pointresize(200,height))
- # Now we are going to mess with the look.
- #
- # The DVD has very very rough grain/noise/dirt/artifacts in the brightest areas.
- # Apparently this is caused by scanning the film from a negative.
- # In bright parts, the negative is black and very little light arrives to the sensor there.
- # Thus the scanner's sensor's noise floor manifests and you end up with this heavy noise
- # in bright areas. Normaly we don't want degraining, but in this case teh noise has questionable
- # effect on the look of the video (possibly because the noise was turned into artifacts
- # by the mpeg2 compression?) and it also dramatically increases the bitrate needed for encoding.
- #
- # For this reason, we are going to selectively filter the bright areas with mdegrain2.
- # A mask is used, one that weights the strength of the degraining based on brightness of a pixel.
- # The curve is non-linear to protect the dark parts and make the effect stronger in bright ones.
- source = last
- prefilt = FFT3Dgpu(sigma=3,bw=32,bh=32,bt=3,ow=16,oh=16,plane=4,precision=1) # this affects only the motion search, preventing misdecissions due to noise.
- superfilt = prefilt.MSuper(pel=2, sharp=1)
- super = MSuper(pel=2, sharp=1)
- backward_vec2 = MAnalyse(superfilt, isb = true, delta = 2, overlap=4)
- backward_vec1 = MAnalyse(superfilt, isb = true, delta = 1, overlap=4)
- forward_vec1 = MAnalyse(superfilt, isb = false, delta = 1, overlap=4)
- forward_vec2 = MAnalyse(superfilt, isb = false, delta = 2, overlap=4)
- degrain = source.MDegrain2(super, backward_vec1,forward_vec1,backward_vec2,forward_vec2,thSAD=100)
- mask = source.mt_lut("x 3.10 ^ 42000 /").blur(0.3)
- mt_merge(source,degrain,mask,luma=true)
- Crop(4,0,-2,-2)