13. Removal of clicks, scratches and VHS drop-outs

13.1 Introduction

Problems in transmission (electronic broadcast) or media storage/handling can lead to artefacts, which will be discussed here.

The electronic images are transferred via electromagnetic waves. This suggests that if we are producing waves with a spectrum close to that broadcasted by a transmitter, interference will be introduced in the original broadcast signal. But this isn't something we should be afraid of, as such intentional disturbances are forbidden by law in many countries. However,it turns out that electromagnetic waves (EM-waves) produced by a mere lightning or electric sparks (amongst other things) emit a wide spectrum of EM-waves, some of which intrude into our broadcast spectrum. So this results in clicks (different words for this effect are sparklies, spots) on our screens. We know that this won't destroy the signal completely, as there are very slim chances that such disturbances will cover the complete bandwidth that is use. They will only bite our signal here and there. Perhaps you noticed last time somebody used a hair-dryer while you were watching plain old analogue tv broadcast.

An other source of such problems is seen in analogue satellite tv. Here, worsening of the signal/noise (S/N) ratio results in the sparklies (in a simillar fashion as when your AM-radio is full of noise, because the transmitters are too far away, and AM is more prone to interference than FM), so when you have heavy rain-fall, clouds are blocking your antenna's view of satellite and you have worse S/N ratio, thus more sparklies. This will also happen if a particular transmitter on the satellite (also called 'transponder') is transmitting on lower power than others-in such case that channel has more sparklies than other (higher power) transponders. So in a sense, more sparklies means you have a signal that gets closer to white noise itself (lowering S/N means getting closer to noise).

VHS knows of this problem mainly by means of poor tracking adjustment. (This can also be considered as a kind of noise, namely noise induced by misaligned scanning (on playback) of magnetic video-tracks layed on tape during the recording.) VHS will also record any noise that it sensed in the 'air' (already explained interference of EM-waves), as VHS is just recording what the antenna provides. Usually though, VHS doesn't have a means to produce this sort of noise if your signal (to be recorded) is clean and tracking is OK.

VHS' biggest problem are the so-called "drop-outs". These errors present a loss of video-signal for a particular scanline(or a number of scanlines); it is easy to spot VHS drop-out: miscolored horizontal line(s) appear on the screen, making this problem very annoying.
This problem is usually caused by a tape-damage (other analog video tape formats can and will suffer from drop-outs too), which results in video-head producing signal levels that are below the required threshold to produce a 'valid' video line (ie the one that looks OK). VHS machines have so called "drop-out compensator" circuits which try to get rid of this nasty tape-format problems. This circuit works on the following principle; if one can detect drop-out (by already mentioned way of detecting 'below the threshold' video-signal levels of damaged lines), then it is also possible to replace the damaged line with the 'last good line'. Usually this works fairly good (if you ever looked at the VHS tape, you may of seen much more lil mechanical damage dots than you saw damaged lines while watching the same tape; that's because drop-out compensator is doing it's job), but there are cases when built-in drop-out compensation won't do; tape damage was too great for drop-out compensator to correct the error. This is when we see nasty, miscolored horizontal lines on the screen.

In general, it can be said that digital systems are more robust than analogue ones, so DVB broadcast (for example) is harder to 'jam' (with some sort of EM noise) than analogue broadcast. This is because digital systems can still differentiate 0 from 1's even if you have very high levels of noise in between. However, digital broadcasting systems suffer from other things. Mainly because too much channels are packed into a small overall bandwidth. Then it becomes apparent how 'line noise' of analogue broadcast (unrelated to clicking etc.) is actualy better and less visible than low-bitrate 'blocking noise' of digital MPEG systems.)

Film image flaws take much less time to explain. It's just damage/deterioration/covering (with foreign objects) of the negative or positive film media. This is essentially caused by the mechanics that drag the film over the image making/projecting machinery. Also, if camera's insides is filled with dust, then dust will block a part of the path of the light onto the film. (That goes for the negative->positive conversion process too. Positive is the film that goes to cinemas, but also sometimes it's used to make electronic video if the negative can't be found.)

This guide explains an attempt to make such flaws less irritating via the usage of AviSynth (the most powerfull freeware video post-processing software) and its plugins ('modules' added to AviSynth for particular video image correction purpose).

[Note; If you're unsure wether you need this filter or not, please inspect the following web-pages to be sure you're on a right track:
Despot used on damaged film sources (Despot home)
CTMedian used to clean laserdisc video problems/tips on Despot loading
CTMedian home and a sample of removal of video 'clicks'
CTMedian used to remove analog satellite-tv 'sparklies'
Despot used on damaged film (tv-cap of vintage Marx Brothers movie)
VHS drop-outs before/after the Descratch
VHS drop-outs before/after the Descratch (neuron2 forum thread)
The guide you're reading now will present you with one more example where Despot can be used; removal of long horizontal lines in video.(These lines should not be confused with VHS drop-outs which are a different type of problem.)]

13.2 AviSynth usage

The Despot plugin (by Fizick) will be used here for clicks/speckle removal, since it is the only good filter available. (If you have long lines that last longer than 1 frame, then Descratch plugin (by Fizick) filter may be used; Descratch does spatial-detection-only on every frame, so it does not depend on 1-frame-duration spots, like Despot does (Despot works in spatial and temporal way). This property means that Descratch is also a filter we'll be using to remove VHS drop-outs. Despot is improved version of Kevin Atkinson's CTMedian filter; improvements were done by Alexander G. Balakhnin aka Fizick. Descratch is Fizick's filter.)

13.2.1 Despot

The spots should be removed before the deinterlacing process (or before any additional filtering if the source is progressive). The filter requires YV12, so you should convert to that color format before using it.

ConvertToYV12(interlaced=true)
Despot(..., interlaced=true)
Deinterlace(...)

To set the correct settings, you should do the following steps:

0 - interlaced setting:
If your video-to-filter is interlaced, then "interlaced=true" should be selected, otherwise set it to "false". Interlaced processing works on fields, so "pheight" should be halved (ie if you measured 4 pixels, you should enter 2 if interlaced mode is used). If you see horizontal stripes in your video, like this 

 

or this 

 

try setting "pwidth" to full frame width (768, 720, 704 or whatever your capture size was), so the detection (more about this in point 3) shows something like this

or this

1 - "pwidth" and "pheight":
Set "pwidth" and "pheight" slightly bigger than the dimensions of the specks you want to remove (you can copy-paste the speckled frame from VirtualDub to some image viewer or even a mere "paint" (to copy input frame in vdub <Ctrl+1>), and measure the speck by selecting it with paint's "select" (rectangular).

2 - m, p1, p2 parameters:
Input some values for "m" (motion) and p1, p2 parameters, for example

DeSpot(p1=30, mthres=15, p2=10, pwidth=12, pheight=10, mwidth=12, mheight=10, interlaced=false, blur=4) 

The author of the plugin suggests " p1 > mthres > p2", so use it as a decent starting point.

3 - "DeSpotMark":
Be aware of what are you doing. If you turn on "DeSpotMark", like this

DeSpotMark(p1=30, mthres=15, p2=10, pwidth=12, pheight=10, mwidth=12, mheight=10, interlaced=false, blur=4, mark_v=255)

It will show the recognized spots as white speckles (the recognized spots are the ones that'll be removed).

4 - p1, mthres and p2 settings:
Try to find good settings; p1, mthres and p2 settings are the most important settings of this filter. They steer what portions of image are rated as "dot to be removed" and what "good portion of the image, leave as-is". This will probably takes some time and many openings of the script in VirtualDub.

You want to remove as much of junk as possible while not disturbing good portions of the image too much. Thus you need to toy with p1, mthres and p2. When you see too much of whiteness applied, you know you're doing too much of interpolation. The goal is to affect the spots only. (Meaning that the white areas only cover the real spots. Open raw video in one instance of VirtualDub, and despot filtered in another, so you know exactly what's happening.)
If p1, mthreash and p2 tweaking doesn't satisfy, you can also try changing the "mwidth" and "mheight", although five variables to balance with is a difficult job.

Generally, it can be said that higher values of p1 and p2 will denoise less (less interpolation going on), while higher values of mthresh results in more denoising. Higher values of mheight and mweight will denoise less.

5 - turning off mark setting:
Turn off 'mark' by erasing that word from syntax (see point "2 - m, p1, p2 parameters" for a syntax example with mark turned off). The last thing to do is checking unprocessed video (from one VirtualDub instance) versus processed one: does it look acceptable? 

 

Shortcoming of this filter(Despot/CTMedian) is a handling of motion scenes: filter that works with image data can't really tell if it was just a speckle in a single frame or was it subject moving. Look, for example, at how despot interpolated the buttons here

while it shouldn't of touched anything 

Usually, it will just turn itself off when it senses faster camera motion. But generally, you can tweak a filter so that no bigger problems occur. Be also warned that filter is pretty slow (12 fps encoding speed dropped to 6 fps when despot was turned on: processing a 640x576 clip on Celeron600).

[Despot has reached version 3.1, but because no bigger improvements are seen in filter speed or handling of motion scenes, there was no need to update this guide.]

13.2.2 DeScratch

Now, we move on to Descratch, and VHS drop-outs removal. Descratch was made to be used to remove thin vertical scratch-lines from the film sources. This filter employs spatial-only image processing, so it will come handy for VHS drop-out removal too, as drop-outs can indeed last more than one frame, and that alone means Despot can't be utilized for this purpose. Lately, this filter got an option to process chroma planes too, so this makes it a nice filter to try on drop-outs too (The usual vhs drop-outs are lines with totally messed color info and a minor and less sudden degradation of luma signal(or no degradation of luma signal at all)).

To setup Descratch, follow these guidelines:

1-This filter was ment to be used on progressive(film based) sequences and to be employed on vertical-only film scratches, so to adapt it to remove VHS drop-outs (VHS is field-based(same as video-standards) recording, and there will be cases where we'll need purely interlaced processing), we will use separatefields(), and turnleft()/turnright() in out avs syntax. That way, we can satisfy filter's need to have vertically oriented error lines (turnlef()/turnright()), and we can output purely interlaced filtered content (for example, if we need interlaced output to mpeg2 encoder) by applying filter to fields via separatefields(). Generally you are advised to use separatefields() for VHS drop-outs removal with Descratch, even if you're trying to clean VHS source with progressive content on it. It will make filter's job easier.

2-Descrach can detect/repair both luma and chroma channels. (Chroma detection/repair is very important for VHS drop-outs). You can use Greyscale(), on your source video to establish if your video needs luma repair, chroma repair, or both. This behaviour is steered by modeY, modeU, modeV parameters. (Y=luma plane,U and V=chroma planes)
If you inspect your video with Greyscale() you will notice that some drop-outs affect chroma only(no damage to luma channel whatsoever), and some damage the luma too. This (a damage to both planes) won't be a problem, because:

a - you can set different mindif (luma detection threshold) to mindifuv (chroma detection threshold), and therefore you can separately process luma and chroma.

b - you can call Descratch more than one time (for example, one instance tweaked to remove chroma-only drop-outs, and another instance removes luma drop-outs).

The "2 instances" approach will result in higher flexibility (you can set all the parameters differently for 2 different planes (luma and chroma planes)), so use that if you feel one-line syntax can't be tweaked enough.
Syntax samples will show an examples of a proper filtering for both cases.

If your video has drop-outs only on particular spots of timeline, you can use applyrange, to apply filter to only particular (damaged) portions of the clip (see Animate/Applyrange section of avs docs).

3-(Visualization can be done by adding mark=true to the syntax)
Tweak the mindif (minimal difference luma) and mindufuv (minimal difference chroma) parameters, so that the filter detects/repairs most of the luma/chroma problematic lines (ie lines that stand-out from the rest of the video-image).
Again, it's good to use the approach of 2 instance of virtualdub, as pointed out in "4 - p1, mthres and p2 settings:" of the Despot guide.
Understandably, higher values of mindif will do less denoising (if you see weird line-blur artefacts, you wanna increase the mindif somewhat).
maxgap,maxwidth,minlen,maxangle
are the parameteres simillar to pwidth and pheight of Despot. They influence the detection of stray lines; if line is below a threshold as defined by these 'dimension/orientation' parameters, it will be skipped (for example, filter won't try to fix a 500 pixels wide damaged line if you put minlen=600)
It seems as if somewhat higher values of blurlen, are well suited for drop-outs. A default value of 15 is therefore probably better suited for film vertical-scratches removal.

4-As with Despot, turn off visualization (by mark=false) if you used it, and to end the tweaking, compare the unprocessed to processed frames again. Does it look OK? If it does, you're done.

Syntax samples (these should be a good starting points to tweak Descratch upon):

Sample No.1:
ConvertToYV12()
#filter requires YV12 colorspace
AssumeTFF().SeparateFields()
#AssumeTFF() for most of capture cards, AssumeBFF() for DV video
TurnLeft()
# turn image 90°
# luma and chroma detection in one syntax line:
DeScratch(modey=1, modeu=3, modev=3, mindif=4, mindifuv=1, maxgap=20, minlen=100, blurlen=50, keep=100, border=0, maxangle=0)
TurnRight()
Weave()

Sample No.2:
ConvertToYV12() #filter requires YV12 colorspace
AssumeTFF().SeparateFields()
#AssumeTFF() for most of capture cards, AssumeBFF() for DV video
TurnLeft()
# turn image 90°
# chroma process
DeScratch(modey=0, modeu=3, modev=3, mindif=1, minlen=50, maxgap=20, blurlen=60, keep=100, mark=false, maxangle=0)
# luma process
DeScratch(modey=1, modeu=0, modev=0, mindif=4, maxgap=20, minlen=300, blurlen=50, keep=100, border=0, maxangle=0)
TurnRight()
Weave()

Sample No.3 plus screenshots:
LoadPlugin("descratch.dll")
AviSource("drop-outs_.avi")
ConvertToYV12()
AssumeTFF()
SeparateFields()
# for analog interlaced source
TurnLeft()
DeScratch(mindif=4, maxgap=20, minlen=300, blurlen=50, keep=100, border=0, maxangle=0)
TurnRight()
Weave()
# restore fields

above: source frame; below: after applying DeScratch

Afterwards proceed as described in the AviSynth post processing guide.


Back to VirtualDub postprocessing

Back to AviSynth postprocessing

Back to the Index: HOME


Last edited on: 23/08/2004 | First release: n/a | Author: Ivo | Content by doom9.org