digitalFAQ.com Forum

digitalFAQ.com Forum (https://www.digitalfaq.com/forum/)
-   Restore, Filter, Improve Quality (https://www.digitalfaq.com/forum/video-restore/)
-   -   VHS cleaning script, lost in colorspace? (https://www.digitalfaq.com/forum/video-restore/12134-vhs-cleaning-script.html)

chrisbati 08-31-2021 03:27 PM

VHS cleaning script, lost in colorspace?
 
2 Attachment(s)
Hello,

I don't know how to start this, because I "play" with a lot of thing I don't really master.

So I use a script to "improve quality" of my captured vhs file (see below, i have to mention that this is not my script).

My captures settings :

- Huffyuv AVI YUY2 file
- Lagarith AVI YUY2 file
- Lagarith AVI YV12 file (YUY2 from the device but YV12 in lagarith configuration mode)

Issue #1 - QTGMC

So basically, If I want to use QTGMC (and I want to), it only works with planar content, so YV12 in my case
If I want to make it work with YUY2, I have to convert to YV12.
For what I have read around this forum and other, the best is to apply all the filters and at the end, convert to YV12 if needed.
In my case it's not possible, I have to use YV12 or to convert to YV12 before starting the differents filters.
I must miss something...

Issue #2 - Color

If I want to use my script without QTGMC to avoid converting to yv12 and only use yuy2, I have strange colors in the picture (see picture below), some colors seem to be missing, the only way to retrieve the right colours is to convert to yv12 (see picture below).

So is it a problem in the script or is it really impossible to perform all without yv12 ?

Thanks in advance for any help

Chrisbati

bad colours in YUY2


Attachment 14002


Right colours in YV12

Attachment 14003


Code:

source=AVISource("U:\Mediaatraiter\usa93vhshufyuy2vdub.avi").AssumeTFF().QTGMC(preset="placebo", EdiThreads=3).crop(12,0,-24,-12).addborders(18,6,18,6)
#source=ffms2("U:\Mediaatraiter\usa93vhs_mod.avi", atrack=1).AssumeBFF().QTGMC(preset="placebo", EdiThreads=3).crop(12,0,-24,-12).addborders(18,6,18,6)
#ConvertToYV12(interlaced=true)
#Only use chroma restoration for analog source material
chroma=source.Cnr2("oxx",8,16,191,100,255,32,255,false) #VHS

#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,400,0) 

return output

#Enable the following block to see original frame followed by denoised frame
/*
return Interleave(
\    source
\  , output
\ )
*/

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

function MDegrain2i2(clip source, int "blksize", int "overlap", int "denoising_strength", 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)
denoising_strength=default(denoising_strength, 400)
dct=default(dct,0) # use dct=1 for clip with light flicker

fields=source.SeparateFields() # separate by fields

#This line gets rid of vertical 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)

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

#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.

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()
}


lollo2 08-31-2021 04:23 PM

Use QTGMC 3.364, it supports YUY2 input. Using this version there is no need to convert to planar color space.

"Green contamination" comes from not up-to-date filters called by QTGMC. Here the versions I use with QTGMC 3.364 (you probably do not need all of them):
Code:

        # QTGMC
Import(plugins_dir + "QTGMC.avsi")
        # Zs_RF_Shared
Import(plugins_dir + "Zs_RF_Shared.avsi")

        # RgTools
loadPlugin(plugins_dir + "RgTools-v1.0\x86\RgTools.dll")
        # MaskTools2
loadPlugin(plugins_dir + "masktools2-v2.2.23\x86\masktools2.dll")
        # MVTools
loadPlugin(plugins_dir + "mvtools-2.7.41-with-depans20200430\x86\mvtools2.dll")
        # FFT3DFilter
loadPlugin(plugins_dir + "FFT3dFilter-v2.6\x86\fft3dfilter.dll")
        # FFTW
loadPlugin(plugins_dir + "LoadDll\LoadDll.dll")
loadDll(plugins_dir + "fftw-3.3.5-dll32\libfftw3f-3.dll")

If a temporary conversion to planar format is needed in your filtering try lossless ConvertToYV16(interlaced=true) or ConvertToYV16(interlaced=false) instead of YV12, then go back to YUY2.

Your script tries to apply an old and not too effective method about using a progressive filter (MDegrain2 with motion compansated vectors) on interlaced material. As you use QTCMC at the beginning your video is deinterlaced and you do not need it at all.
Use directly the filter instead, with the parameters you prefer:
Code:

c_msuper = MSuper()
backward_vec1 = MAnalyse(c_msuper, isb=true,  delta=1, blksize=blksize, overlap=overlap, dct=dct, chroma=true, badSAD=badSAD)
forward_vec1  = MAnalyse(c_msuper, isb=false, delta=1, blksize=blksize, overlap=overlap, dct=dct, chroma=true, badSAD=badSAD)
backward_vec2 = MAnalyse(c_msuper, isb=true,  delta=2, blksize=blksize, overlap=overlap, dct=dct, chroma=true, badSAD=badSAD)
forward_vec2  = MAnalyse(c_msuper, isb=false, delta=2, blksize=blksize, overlap=overlap, dct=dct, chroma=true, badSAD=badSAD)
MDegrain2(c_msuper, backward_vec1, forward_vec1, backward_vec2, forward_vec2, thSAD=thSAD, thSADc=thSADc)

Try this, and we can later improve the script for further and better denoise/sharpening and chroma processing if you are not satisfied...

msgohan 08-31-2021 06:08 PM

Quote:

Originally Posted by lollo2 (Post 79491)
If a temporary conversion to planar format is needed in your filtering try lossless ConvertToYV16(interlaced=true) or ConvertToYV16(interlaced=false) instead of YV12, then go back to YUY2.

I agree. If planar is needed, convert to the planar version of YUY2, which is YV16. Both are 4:2:2 and you're just losslessly changing the order of bytes. Conversion to YV12 (4:2:0) should be avoided until final output, unless some filter absolutely requires it.

BTW, the "interlaced" parameter doesn't do anything in your example when the source is YUY2. It's for handling YV12 chroma conversions: http://avisynth.nl/index.php/Convert#Interlaced

4:2:2 has full chroma vertically, so no special handling is required for interlaced lines.

chrisbati 09-01-2021 02:56 AM

Quote:

Originally Posted by lollo2 (Post 79491)
Try this, and we can later improve the script for further and better denoise/sharpening and chroma processing if you are not satisfied...

Thanks a lot, I'll try to adapt the script, hope it'll work !

chrisbati 09-01-2021 12:58 PM

So I tried to tune the script, maybe basic, but not easy for me, but I tried :wink2:

For the QTGCM issue with non planar, I updated all version and needed plugin of QTGMC I found on my computer.
Now It works in 64bit but I still have the issue with the 32bit version, quite ennoying because most of the time the 32bit version is the one which works the best.
I checked but didn't found why still have that planar issue in 32bit.

I also modify the script with the new code you gave me.
I hope I did it well because I can't get most of it :)
I also gave up some elements like badsad or thsad because I don't know how to deal with them.

Here's the first version of the new script, do you think it's correct ?

Thanks in advance

Chrisbati

Code:

source=AVISource("U:\Mediaatraiter\usa93vhshufyuy2vdub.avi").AssumeTFF().QTGMC(preset="placebo", EdiThreads=3).crop(12,0,-24,-12).addborders(18,6,18,6)
chroma=source.Cnr2("oxx",8,16,191,100,255,32,255,false)
output=MDegrain2i2(chroma,8,0,400,0) 

return output



function MDegrain2i2(clip source, int "blksize", int "overlap", int "denoising_strength", 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)
denoising_strength=default(denoising_strength, 400)
dct=default(dct,0) # use dct=1 for clip with light flicker

fields=source.SeparateFields() # separate by fields

#This line gets rid of vertical 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))

c_msuper = fields.MSuper(pel=2, sharp=1)
backward_vec1 = MAnalyse(c_msuper, isb=true, delta=1, blksize=blksize, overlap=overlap, dct=dct, chroma=true, badSAD=1000)
forward_vec1 = MAnalyse(c_msuper, isb=false, delta=1, blksize=blksize, overlap=overlap, dct=dct, chroma=true, badSAD=1000)
backward_vec2 = MAnalyse(c_msuper, isb=true, delta=2, blksize=blksize, overlap=overlap, dct=dct, chroma=true, badSAD=1000)
forward_vec2 = MAnalyse(c_msuper, isb=false, delta=2, blksize=blksize, overlap=overlap, dct=dct, chroma=true, badSAD=1000)
MDegrain2(fields,c_msuper, backward_vec1, forward_vec1, backward_vec2, forward_vec2)

#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.

Weave()
}


lollo2 09-01-2021 02:03 PM

Try this first with 32bit AviSynth, downloadeing the version of the filters as specified and replacing my path with your location for the AviSynth filters.
We'll add more processing if you need chroma shift and chroma stabilization (cnr2 plugin).

Code:

source=AVISource("U:\Mediaatraiter\usa93vhshufyuy2vdub.avi")

# ---> specify here your location for AviSynth filters <---
# plugins directory
plugins_dir="C:\Users\giuse\Documents\VideoSoft\MPEG\AviSynth\extFilters\"

        # QTGMC
Import(plugins_dir + "QTGMC.avsi")
        # Zs_RF_Shared
Import(plugins_dir + "Zs_RF_Shared.avsi")
        # Nnedi3
loadPlugin(plugins_dir + "NNEDI3_v0_9_4_55\x86\Release_W7\nnedi3.dll")
        # RgTools
loadPlugin(plugins_dir + "RgTools-v1.0\x86\RgTools.dll")
        # MaskTools2
loadPlugin(plugins_dir + "masktools2-v2.2.23\x86\masktools2.dll")
        # MVTools
loadPlugin(plugins_dir + "mvtools-2.7.41-with-depans20200430\x86\mvtools2.dll")

source_deinterlaced=source.AssumeTFF().QTGMC(EdiThreads=3)
source_deinterlaced_centered=source_deinterlaced.crop(12,0,-24,-12).addborders(18,6,18,6)

MDegrain2_MC_p(source_deinterlaced_centered, blksize=8, overlap=4, dct=0, badSAD=1000, thSAD=400, thSADc=400)

#stackhorizontal(source.SelectEvery(1,0,0),last)
#interleave(source.SelectEvery(1,0,0),last)
return(last)


function MDegrain2_MC_p(clip c, int "blksize", int "overlap", int "dct", int "badSAD", int "thSAD", int "thSADc")
{
c_msuper = c.MSuper()
backward_vec1 = MAnalyse(c_msuper, isb=true,  delta=1, blksize=blksize, overlap=overlap, dct=dct, chroma=true, badSAD=badSAD)
forward_vec1  = MAnalyse(c_msuper, isb=false, delta=1, blksize=blksize, overlap=overlap, dct=dct, chroma=true, badSAD=badSAD)
backward_vec2 = MAnalyse(c_msuper, isb=true,  delta=2, blksize=blksize, overlap=overlap, dct=dct, chroma=true, badSAD=badSAD)
forward_vec2  = MAnalyse(c_msuper, isb=false, delta=2, blksize=blksize, overlap=overlap, dct=dct, chroma=true, badSAD=badSAD)
c.MDegrain2(c_msuper, backward_vec1, forward_vec1, backward_vec2, forward_vec2, thSAD=thSAD, thSADc=thSADc)
return (last)
}



All times are GMT -5. The time now is 06:02 PM

Site design, images and content © 2002-2024 The Digital FAQ, www.digitalFAQ.com
Forum Software by vBulletin · Copyright © 2024 Jelsoft Enterprises Ltd.