View Full Version : Restoring old VHS(video)
torwart
12th April 2011, 08:23
Hello.
I have captured old VHS tape via easycap usb2.0 and now I have a PAL video(Lagarith). 720x576, 25fps. I want to improve the quality of this video, but I don't know what plugins should I use. At the end it will be xvid file. Here is my script:
Avisource("Capture.avi",pixel_type="YUY2")
TDeint()
Cnr2()
converttorgb24(matrix="rec709",interlaced=false)
and here are screenshots:
http://i028.radikal.ru/1104/96/5c025a2a0c60.jpg
http://s39.radikal.ru/i084/1104/de/64f002163d20.jpg
http://s51.radikal.ru/i134/1104/92/7201ef305f25.jpg
http://i072.radikal.ru/1104/57/2feeac34e586.jpg
I know that avisynth has a possibility to make this video better. Just show me the road. :) Thank you for any answers!!!
Ghitulescu
12th April 2011, 08:28
It looks like that you desperately need a TBC.
2Bdecided
12th April 2011, 16:23
Yes. And/or a better capture device and/or a better VHS machine and/or some way of adjusting levels before capture.
It'll probably still be soft, possibly badly shot video, whatever you do. With what you have, you might be able to claw back some of the blown highlights if there's a RGB/YUV 255 vs 235 issue (i.e. if there's more range in the captured file than in your screen caps).
You can always remove noise and sharpen a bit - but sometimes that makes things like this look even worse. Plastic, artificial, etc.
Cheers,
David.
jmac698
12th April 2011, 19:19
A better vcr/capture card seems to be an often repeated theme. I've doubted this, so I tried the same tape on 3 different VCRs and two different capture cards. I can barely see the difference, when calibrated. I have an explanation for this perception; the default setting of each capture card are different, and some are preferable. But really, capture cards are quite precise and not very variable. VCR's vary only slightly by color.
As far as TBC, I used correlations to compare two captures of the same video, expecting to show me the statistical distribution of horizontal jitter. I was shocked that there was no difference. In fact, my capture card has a TBC and probably so does yours (line TBC only), but this fact doesn't seem well known. In my case, the chip feature is called UltraLock. I'm still investigating these issues.
Anyhow, try some denoising and sharpening. I have one idea that could really work, capture it several times and take the median, it will clear up some noise. Here is a median function:
Function Median2(clip "input_1", clip "input_2", clip "input_3", clip "input_4", clip "input_5", string "chroma")
{# median of 5 clips from Helpers.avs by G-force
chroma = default(chroma,"process") #default is "process". Alternates: "copy first" or "copy second"
#MEDIAN(i1,i3,i5)
Interleave(input_1,input_3,input_5)
chroma == "process" ? Clense() : Clense(grey=true)
m1 = selectevery(3,1)
#MAX(MIN(i1,i3,i5),i2)
m2 = input_1.MT_Logic(input_3,"min",chroma=chroma).MT_Logic(input_5,"min",chroma=chroma).MT_Logic(input_2,"max",chroma=chroma)
#MIN(MAX(i1,i3,i5),i4)
m3 = input_1.MT_Logic(input_3,"max",chroma=chroma).MT_Logic(input_5,"max",chroma=chroma).MT_Logic(input_4,"min",chroma=chroma)
Interleave(m1,m2,m3)
chroma == "process" ? Clense() : Clense(grey=true)
selectevery(3,1)
chroma == "copy first" ? last.MergeChroma(input_1) : chroma == "copy second" ? last.MergeChroma(input_2) : last
Return(last)
}
It's made for up to 5 captures, but you can use 3. Call like median2(clip1,clip1,clip2,clip3,clip3). Trim each clip to the same starting point first.
torwart
13th April 2011, 17:52
Thank you for your answers gyes! I have only one VCR(Panasonic) and I have no time to capture for 5 times. One tape is about 4 hours and I have many tapes to capture. :) So all I can is to work with video , that I have. About TBC. I found a script that makes TBC, but there is no difference between TBCed and the original. Maybe this script do not work correct or I do wrong things. Result is 0. Here is this script with 3 functions. Which of them do I need and what I have to change in this script?
#To use on a real video:
#v=MPEG2Source("C:\MyVideos\vcr\rca.d2v", cpu=0)
#remove jitter line
#remove stackvertical line, which is just for visual comparison of before and after
#adjust hardcoded offset and thresh in tbc function
#adjust hardcoded '80' in slice to 480.
#hope it doesn't crash - it's slow and takes a lot of memory. Adjust slice value slowly upward.
#this works! The first 80 lines are TBC'd and highlighted
v=greybars()
#v=MPEG2Source("C:\MyVideos\vcr\rca.d2v", cpu=0)
v
jitter(4+1)
slice(last,0)
pointresize(last.width,last.height/4)
stackvertical(last.coloryuv(off_y=24),v.crop(0,0,0,480-80))
# pointresize(last.width,last.height*2)
# crop(0,4*2,0,2).pointresize(720,4)
# tbc
function tbc(clip last) {
ScriptClip("""
v3=last
function getpixel(clip v2, int x1, int y1) {
v2
pointresize(last.width*2,last.height*2)#double to avoid problems reading single pixel of YV12
crop(x1*2,y1*2,2,2)
}
y=0
v3
#find where >=thresh
p0=getpixel(last,719,0).averageluma
p1=getpixel(last,718,0).averageluma
p2=getpixel(last,717,0).averageluma
p3=getpixel(last,716,0).averageluma
p4=getpixel(last,715,0).averageluma
p5=getpixel(last,714,0).averageluma
p6=getpixel(last,713,0).averageluma
p7=getpixel(last,712,0).averageluma
p8=getpixel(last,711,0).averageluma
p9=getpixel(last,710,0).averageluma
p10=getpixel(last,709,0).averageluma
p11=getpixel(last,708,0).averageluma
p12=getpixel(last,707,0).averageluma
p13=getpixel(last,706,0).averageluma
p14=getpixel(last,705,0).averageluma
p15=getpixel(last,704,0).averageluma
thresh=85
offset=4
x=p0>=thresh?7191>=thresh?7182>=thresh?7173>=thresh?7164>=thresh?7155>=thresh?7146>=thresh?7137>=thresh?712: \
p8>=thresh?7119>=thresh?71010>=thresh?70911>=thresh?70812>=thresh?70713>=thresh?70614>=thresh?70515>=thresh?704:720
v3.bilinearresize(last.width,last.height,0,last.height,x+offset,last.height)#+4 moves detection point in
#subtitle(string(x),x=100)
""")
}
function jitter(clip in, int jitter) {
n=5#this works and make 5 slices of horizontally resized areas
j1=rand(jitter)#determined once per clip
j2=rand(jitter)
j3=rand(jitter)
j4=rand(jitter)
j5=rand(jitter)
w=720
h=480
h1=h/n
h1=16
slice=blankclip(width=w,height=h1,pixel_type="YV12")
c1=in.bilinearresize(720-j1*2,h1,0,0*h1,w,h1)
c1=overlay(slice,c1,opacity=1).subtitle(string(j1))
#c1=c1.bilinearresize(720,h1,0,h1,720-j1*2,h1)#test resizing back to original size
c2=in.bilinearresize(720-j2*2,h1,0,1*h1,w,h1)
c2=overlay(slice,c2,opacity=1).subtitle(string(j2))
#c2=c2.bilinearresize(720,h1,0,h1,720-j2*2,h1)
c3=in.bilinearresize(720-j3*2,h1,0,2*h1,w,h1)
c3=overlay(slice,c3,opacity=1).subtitle(string(j3))
c4=in.bilinearresize(720-j4*2,h1,0,3*h1,w,h1)
c4=overlay(slice,c4,opacity=1).subtitle(string(j4))
c5=in.bilinearresize(720-j5*2,h1,0,4*h1,w,h1)
c5=overlay(slice,c5,opacity=1).subtitle(string(j5))
stackvertical(c1,c2,c3,c4,c5)
}
function slice(clip v5, int y) {
#warning! this function is very slow. It eats a lot of memory also. Only good for experimentation.
v5
pointresize(last.width,last.height*2)
crop(0,y*2,0,2).pointresize(720,4)
tbc
y<80-1?stackvertical(last,slice(v5,y+1)):last
}
Thanks!
Ghitulescu
13th April 2011, 17:54
Use search and you'll find at least 2 topics about "software TBCs" and their use (:)). As you find it out yourself.
A HW TBC stabilises the video signal before capturing. You may also want to google a bit or to access lordsmurf's pages on this topic.
jmac698
14th April 2011, 01:41
That's funny, I wrote that and it doesn't work practically. I should update my webpage :)
There's some other tbc plugins you can try.
DeJitter
Author V. C. Mohan
Date Mar 16, 2006
EMail: mohanvc
Some vhs tapes have time sync problems, and the rows exhibit severe jitter. This plugin examines the specified window of each of the rows and tries to find the amount by which the pixels are out of alignment, adds the sync signal width and shifts, to put them in correct alignment. Dark scenes with luma less than 50 or so may give erroneous results. The resulting voids at the right ends of the rows are greyed out or end color extended.
RGB32, RGB24, YUY2 and YV12 formats are supported. In case of RGB the red color only is used and for YUY2 and YV12 the Y value is used to determine shift required.
You can improve noise even if you capture twice, but I see your problem. I used 350GB disk drive just for one tape.
Ghitulescu
14th April 2011, 08:30
You can improve noise even if you capture twice, but I see your problem. I used 350GB disk drive just for one tape.
For that you need however that the duplicate pixels fall exactly in the same place (so you need a TBC) or you'll loose resolution and/or end with ghosting.
2Bdecided
14th April 2011, 12:17
A better vcr/capture card seems to be an often repeated theme. I've doubted this, so I tried the same tape on 3 different VCRs and two different capture cards. I can barely see the difference, when calibrated. I have an explanation for this perception; the default setting of each capture card are different, and some are preferable. But really, capture cards are quite precise and not very variable. VCR's vary only slightly by color.If they play the tape perfectly VCRs vary by bandwidth/sharpening and noise levels. But far more important is that some VCRs don't play some tapes at all, others add distortion, tracking errors, black and white streaks etc while a different machine may play the exact same tape perfectly. Using an S-VHS machine means you don't have to rely on your capture device's comb filter (if it has one).
A DV camcorder, a Panasonic ES10 DVD recorder, an ADVC110, and a generic PC capture card will all give very different results - due to different processing within, not just different levels (though some are easier to calibrate than others).
Cheers,
David.
torwart
14th April 2011, 17:47
Thanks a lot for help. I have tried dejitter plugin. With different parameters. Nothing positive. Quality becomes worse. I think all I can do is to antinoise with mvtools mvdegrain i2i and autolevels. Maybe someday we will have a good TBC plugin for avisynth.
Ghitulescu
14th April 2011, 18:14
Maybe someday we will have a good TBC plugin for avisynth.
First of all a TBC repairs only analog signals (there's no need to do this on a digital signal - for digital there are "jitter removers"), and given that analog signals will be shut down next year, and also given that nothing happened for the last 3 or more years, I very much doubt it. Probably a good deshaker, maybe ...
Secondly, I think is good for you to tell you that one should not expect miracles from avisynth or whatever SW solution.
No SW in the world can correct what a broken HW did (or did not :)). It's incredible how widespread is this misunderstanding of how things properly work - people buy crap HW because it's cheap (no offence intended) then spend hours/days/weeks tweaking various options and filters and scripts to get a satisfactory result. If I would get paid by the hour all this time, I think I could buy Scenarist with the money I would have been paid for all these spent hours - why not use a tiny fraction of that money (the electricity bill :)) to get a better capture card, a better [S-]VHSplayer and a TBC - less noise, less image issues, better image/signal stability. For better results.
Especially with archiving-worth materials.
A better VHS (even better SVHS) player is cheaper now on ebay or analogue e-markets or garage sales, a TBC (again used) runs below 100€, a real capture card is again under 100€. You may even get these for next to nothing, yes, miracles happen.
torwart
14th April 2011, 18:55
You are right Ghitulescu. Ofcourse it is better to bye good things and to have a good result. But when you do not work with video professionally and you do it just for friends you have to expect miracles from avisynth. And this program does! :) For me was a miracle when my old 8mm film video(very dirty) was restored with Freds script. I had no words. :)
Ghitulescu
14th April 2011, 19:58
I repeat for the nth time: quality is personal. Everyone should decide (or be able to decide) where to draw the line between quality, costs and spent time.
I am glad you have found yours. :)
jmac698
15th April 2011, 18:59
Ghit,
For that you need however that the duplicate pixels fall exactly in the same place (so you need a TBC)
Very good observation! And that's what I did, in a software TBC. Remember I don't need a hardware TBC because I only need to line up the two videos relative to each other, which can be done quite easily (I'm using MVTools for this). I line them up line-by-line. Took quite a while to get a good performing script for this.
And yes, I do agree that some VCRs play a tape better, that's certainly important. I think one of my VCR's is noisy (I currently have 6 and experience with them). I wouldn't say the differences have been dramatic, however. As for sharpness, two have a sharpness control which looks like the others when set to normal (some have edit/soft settings).
As for capture cards, if it's a hardware compression card (like dvd recorder or mpeg capture card), the compression will always degrade the quality.
So, let me restate this more precisely, it is my belief that non-compressing capture cards hardly vary, assuming you can find the neutral sharpness settings in each (which vary wildy by driver/card), and calibrate the brightness/contrast/color/hue settings to colorbars.
A good reason for this is in the hardware itself, the simplest design rules and thus the settings tend to be quite logical, even sharpness is based on a standard mathematical digital filter, which probably even have the same type of filter and thus same coefficients. I mean hardware designs tend to converge to being equivalent because of the underlying mathematical truth.
There are VCRs which play better - in my case it's not my JVCR SHVS (which is one of the recommended ones), but a consumer RCA. One of my SVHS is actually pretty bad, even though it was hardly used.
Anyhow, I found fft3dfilter (sigma=2) worked good for medium amounts of noise.
jmac698
16th April 2011, 06:44
There's some scripts in here that might help you
http://forum.doom9.org/showthread.php?t=160622
torwart
16th April 2011, 14:55
the script was very helpful. now quality of the video is much better. Thank you!
William.Lemos.BR
8th September 2011, 17:16
Hi! I´m working with VHS restoration and while researching this topic found your research. Your ideas are very interesting. I have my owns but it will take a time to be able of implement them, since I´m new to avisinth (now I´m quite familiar with it, but still lightyears away from dealing with mvtools etc.).
You´ve mentioned this:
Remember I don't need a hardware TBC because I only need to line up the two videos relative to each other, which can be done quite easily (I'm using MVTools for this). I line them up line-by-line. Took quite a while to get a good performing script for this.
Please, could you show how you do that alignment? I´m using the median of multiple captures and would like to test if the results are affected if we line up each video before doing it.
Thanks in advance!
jmac698
8th September 2011, 19:15
If you have samples which aren't lined up, line-by-line, I'd like to see that. In the end I discovered that while crooked, each capture was crooked in the same way. My theory is that the hardware feature called UltraLock did the equivalent of a TBC, however it's TBC action was not perfect, but consistent.
The end result is that lining up the lines has no effect on the median.
William.Lemos.BR
13th September 2011, 14:39
Yes, you´re right. After some tests I found out that each line is lined up.
Anyway, I´ll keep folowing your work, which is very interesting. I´ll share with you anything I discover on this subject.
Thanks!
jmac698
13th September 2011, 15:35
Aha! That's good that someone confirmed that capture cards *do* have a TBC. And the median technique works great! As for my statement that capture cards hardly matter, here is a test
http://forum.doom9.org/showthread.php?t=162509
Ghitulescu
13th September 2011, 17:49
If you have samples which aren't lined up, line-by-line, I'd like to see that. In the end I discovered that while crooked, each capture was crooked in the same way. My theory is that the hardware feature called UltraLock did the equivalent of a TBC, however it's TBC action was not perfect, but consistent.
The end result is that lining up the lines has no effect on the median.
8x8 implement the UltraLock using a higher sampling rate to get more samples (logic, right?). Then the firmware tries to find where the synch occurs and selects the line accordingly.
Yes, it's a sort of rudimentary TBC. However, it doesn't fully reconstruct the synch in case it's missing, so you'll have dropped frames for really bad sources. A real TBC will at least cheat you, by repeating the last good field/frame.
jmac698
13th September 2011, 18:59
Ah... this seems to be a big controversy, what is a TBC? The video experts seem to dismiss that all capture cards have a TBC by default. Well I do agree with you, if the sync is missing due to a dropout (or copy protections etc.), the capture card will go ahead and digitize a default line, which may not be the position you want, and that line will be offset.
In normal cases, the purpose of a TBC with a VCR is to stabilize a strong sync signal, because the tape is being read mechanically and the motor varies slightly in speed. In that case, as long as the sync can be detected, the capture card should be a TBC which works line-by-line.
There is no concept here of "recreating stable sync" as external boxes do, because there is no analog output again - in a sense the recreated sync is virtual within the resulting picture. (If you know what I mean).
However, as far as this theory goes, it doesn't explain why external TBC boxes seem to line up the picture better than the capture card. That the sync detection of the capture card is pretty good, I think is proven by my thread where I show a normal SD card capturing a 480p signal. In this progressive signal, the sync width is about half of a normal one, and yet the card was able to create a stable image. I think that's impressive.
But thanks for bringing this up, I think I can prove it - if I can create an arbitrary video signal, and remove sync from one line or vary sync on one line, I can observe exactly how the card responds. And thanks to my other experiments, I realize how to do this with no special equipment. I can simply create a video image, such that when played back on a component output, creates a video signal - on the *color* outputs! It turns out that Pb/Pr signals of the component output range from +-350mV. I know that physically the sync signals are negative, so maybe it's enough to trigger sync detection. Yes - I think I know a simple test for this.. actually I'm pretty sure it's going to work (I might have to combine Y and Pb with a cable - this results in an exact addition of the two signals, with some stress on the output amplifiers :)
ronnylov
17th September 2011, 20:51
This reminds me of an old plugin that compares three captures and make average of the two most similar.
The filter is calles TooT. It can reduce dopouts and other random problems that only occurs in one of the captures (on that particular frame).
http://forum.doom9.org/showthread.php?s=&threadid=78338
And the even older hread: http://forum.doom9.org/showthread.php?t=78187
If you have 9 captures of the same video you can take 3 at the time and process with toot to get 3 cleaned clips and then average these 3 clips to get an even cleaner one (an average of 6 captures).
But if it is worth it is another story...
johnmeyer
17th September 2011, 22:07
This reminds me of an old plugin that compares three captures and make average of the two most similar ... But if it is worth it is another story...I went down this path eight years ago, and wrote about my results over in the Sony forum:
My "ultimate" VHS tape restoration recipe (http://www.sonycreativesoftware.com/forums/ShowMessage.asp?ForumID=4&MessageID=218982)
You don't need to bother reading that whole thread because here is the summary: it produces great results, but is a major PITA.
Why?
Because it is very difficult to get the two captures to align, and then keep them in alignment for the duration of your video.
Much depends on what your capture card does when it encounters difficulty. However, if you capture from VHS, and there is a dropout, or perhaps a section where nothing was recorded, the two captures will almost certainly have different numbers of frames. You will need to re-align the video at each of these hiccups.
This multiple capture technique did a great job on VHS "snow" noise, especially compared to the digital filters available back in 2003 when I first tried this. However, I'm pretty certain that MDegrain now does as good a job, with almost no artifacts (the multiple capture does have the advantage of not producing the usual artifacts associated with temporal and spatial denoisers).
Bottom line: multiple capture is almost never worth the incredible time it takes to do multiple captures, line them up, and combine them. If you do choose this approach, I recommend using Vegas (or GUI editor of your choice), rather than AVISynth, to combine them together, because alignment is tricky and requires an editing program's interactive GUI interface.
johnmeyer
17th September 2011, 23:21
P.S. Here's another old post in this forum about averaging multiple captures:
Averaging two analog captures for noise reduction (http://forum.doom9.org/showthread.php?s=&threadid=28438&perpage=20&highlight=vhs&pagenumber=1)
jmac698
18th September 2011, 03:49
Oh, it's possible to line them up automatically.. in fact there's a script posted to do that. I haven't tried it myself yet though.
I read those threads - basically they are all the same, it does work, and you have to double the number of captures each time to get an improvement, but some people don't believe it should work. Yes, it reduces noise from the tape onwards, but for example dropouts due to the carrier signal being lost can be in random spots and a good machine can't complete fix it. So the "white lines" can always be improved.
I also bought 3 copies of commercial tape just to see if that was better too, unfortunately one tape had bad problems anyhow.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.