View Single Post
Old 17th January 2019, 00:19   #1  |  Link
rarend
Registered User
 
Join Date: Feb 2018
Posts: 9
Red color bleeding in Avisynth ffmpeg edit of VHS capture

Hi all,

Following several posts, guides and trial and error I'm trying to digitize a VHS-recording from TV as best as I can using AviSynth and ffmpeg. I'm reasonably satisfied with the results so far
but now I am running into an issue that the red in the video is bleeding outside the areas in which it is supposed to be. I've added screenshots of this. It looks a bit like ghosting but then
only with the color red. Is this chroma bleeding? If not, what would you call it? And how can I counter it?

To capture the analogue video I use an old Sony camcorder that I put in between my S-VHS VCR and my PC using a high-end S-VHS cable and a high end fire wire cable. I do the initial
capture using Pinnacle Studio, to 720x576 DV avi, and then edit the initial result using AviSynth and ffmpeg, directly to mp4.

This is a screenshot of the dv avi:
http://imagizer.imageshack.us/a/img923/1381/kgDOPK.png

This is a screenshot of the same frame in the mp4 after processing:
https://imagizer.imageshack.com/v2/1...921/P2IlUY.png

This is a WeTransfer link to the first 2+ minutes of the raw DV avi (457MB, no sound). The screenshot was taken at 2:05.480:
https://wetransfer.com/downloads/01e...6223404/fe8670
(Valid until January 23rd 2019)

If you look at the shoulders of the person in the screenshot of the processed mp4, you'll notice that the red is bleeding out above the shoulders, which it doesn't do in the DV avi.

Any idea what might be causing this?

I use the script below, in which I remove VHS flickering using Cnr2 and MDegrain2i2, de-interlace using QTGMC, remove additional noise using fft3dfilter and then sharpen the video using
LSFMod. After this I crop and resize the video to give it a 16:9 compliant height. I then use GradFun3 to smoothen transitions and finally I box the video to give it the 16:9 width that
corresponds with the height.

Thanks in advance for any suggestions and tips.

Script:

Code:
# 1. import plugins

LoadPlugin("E:\Program Files (x86)\AviSynth\plugins\Avisynth 32-bit Plugins\2.5x Plugins\mt_masktools-25.dll")
LoadPlugin("E:\Program Files (x86)\AviSynth\plugins\Avisynth 32-bit Plugins\RemoveGrain.dll")
LoadPlugin("E:\Program Files (x86)\AviSynth\plugins\Avisynth 32-bit Plugins\mvtools2.dll")
LoadPlugin("E:\Program Files (x86)\AviSynth\plugins\Avisynth 32-bit Plugins\nnedi3.dll")
loadplugin("E:\Program Files (x86)\AviSynth\plugins\fft3dfilter211\fft3dfilter.dll")
LoadPlugin("E:\Program Files (x86)\AviSynth\plugins\removegrain\RemoveGrain.dll")
LoadPlugin("E:\Program Files (x86)\AviSynth\plugins\removegrain\Repair.dll")
Import("E:\Program Files (x86)\AviSynth\plugins\LSFmod.v1.9.avsi")
LoadPlugin("E:\Program Files (x86)\AviSynth\plugins\mvtools-2.6.0.5\avstp.dll")
LoadPlugin("E:\Program Files (x86)\AviSynth\plugins\mvtools-2.6.0.5\mvtools2.dll")
LoadPlugin("E:\Program Files (x86)\AviSynth\plugins\dfttest-1.9.4\dfttest.dll")
LoadPlugin("E:\Program Files (x86)\AviSynth\plugins\dither-1.27.2\win32\dither.dll")
Import("E:\Program Files (x86)\AviSynth\plugins\dither-1.27.2\dither.avsi")
Import("E:\Program Files (x86)\AviSynth\plugins\dither-1.27.2\mt_xxpand_multi.avsi")
LoadPlugin("E:\Program Files (x86)\AviSynth\plugins\Chromashift\ChromaShift.dll")
LoadPlugin("E:\Program Files (x86)\AviSynth\plugins\WarpSharp\warpsharp.dll")
LoadPlugin("E:\Program Files (x86)\AviSynth\plugins\RemapFrames\RemapFrames.dll")
# Chroma Stabilizer for analog sources. It's a temporal filter and it's very effective against two chroma artifacts: Stationary rainbows and huge analog chroma activity.
loadPlugin("E:\Program Files (x86)\AviSynth\plugins\cnr2_v261\Cnr2.dll")

# 2. inline functions:

# MDegrain2i2 found on https://forum.videohelp.com/threads/308840-old-VHS-restoration/page2 correct old vhs tapes
function MDegrain2i2(clip source, int "blksize", int "overlap", int "dct")
{
Vshift=2 # 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 vertical chroma halo
fixed_fields=MergeChroma(fields,crop(fields,Hshift,Vshift,0,0).addborders(0,0,Hshift,Vshift))

super = fixed_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(fixed_fields,super, backward_vec2,forward_vec2,backward_vec4,forward_vec4,thSAD=400) 

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

Weave()
}

# 3. open file

SetMemoryMax(700)  # Optional line.
SetMTMode(3, 1)  # See below for value X, could try 5 instead of 3 for non-standard source-filter/avisynth combinations
### SOURCE
source=AVISource("R:\NEWCAPS 20180326\raw dv avi\System Of A Down live Lowlands (20010825)\20180325 system of a down live lowlands (raw dv)_cropped_without_commercials.avi")  # DGDecode_mpeg2source, FFVideoSource, AviSource, whatever your source requires

# 4. Force the field order

# This line is important as AviSynth usually guesses field order incorrectly! Change to AssumeBFF() if working with bottom-field-first video.
# Read more: http://www.digitalfaq.com/forum/video-restore/3729-qtgmc-how-deinterlacing.html#ixzz5BeJJyP7Z
# According to MediaInfo, the source is BFF
source2 = AssumeBFF(source)

SetMTMode(2,0)

# 5. remove flickering typical of VHS

# https://forum.videohelp.com/threads/308840-old-VHS-restoration/page2 correct old vhs tapes
# Only use chroma restoration for analog source material
chroma=source2.Cnr2("oxx",8,16,191,100,255,32,255,false) #VHS

#Set overlap in line below to 0, 2, 4, 8. Lower 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,4,0,0)

# 6. deinterlace video - this outputs a video with double framerate 

deinterlacedVid=QTGMC( output, Preset="Slow", EdiThreads=1 ) # Choose preset based on overall speed/quality you want. See below for value Y

# 7. remove additional noise

additionalDenoisedVid=fft3dfilter(deinterlacedVid, sigma=0.7, bt=5, bw=32, bh=32, ow=16, oh=16)

# 8. sharpen after denoising

sharpenedLSFVid=LSFMod(additionalDenoisedVid, strength=40, defaults="slow")

# 9. crop (must be even values)

# left 12 right 6 -> 702x576
# top 82 bottom 74 -> 702x420
cropped = Crop(sharpenedLSFVid, 12, 82, -6, -74)

# 10. resize

# After the cropping is done, resize to a near 1280x720 resolution (1204x720) and afterwards add borders to make the result truly 1280x720
resizedvid=Lanczos4Resize(cropped, 1204,720)

# 11. apply gradfun at the very end to smoothen gradiations

gradFunVid=GradFun3(resizedvid)

# 12. add borders to get 16:9 dimensions

borderVid = AddBorders(gradFunVid,38,0,38,0)

return borderVid
The version of LSFmod that I use is v1.9, which can be found here:
https://forum.doom9.org/showthread.php?t=142706

Last edited by rarend; 17th January 2019 at 01:16.
rarend is offline   Reply With Quote