Hi folks,
I'm using Avisynth to edit my VHS files. (I'm a beginner using this software)
I wrote the script that I'm using below. This script really improved some videos.
However, it is taking almost 44 hours to process a video of one and a half hour (I'm using a core i7). And I have dozens of videos that I need to edit using Avisynth.
So, please, Are there some ways for decrease the process time? (if possible using the same script)
Thank you so much!
# Plugins: - RemoveGrain
# - MaskTools2
# - Depan + DepanEstimate
# - MVTools2
mpeg2source("m:\temp2\test.d2v")
crop(0,64,-0,-64,true)
bob(0,0.5)
a=last
clense(reduceflicker=false).merge(last,0.5).clense (reduceflicker=false)
mot=removegrain(11,0).removegrain(20,0).DepanEstim ate(range=2)
take2=a.depaninterleave(mot,prev=2,next=2,subpixel =2)
clean1=take2.TMedian2().selectevery(5,2)
sup1 = clean1.minblur(1).removegrain(11,0).removegrain(11 ,0)
\ .mt_lutxy(clean1,"x 1 + y < x 2 + x 1 - y > x 2 - y ? ?",U=2,V=2)
\ .msuper(pel=2,sharp=0)
sup2 = a.msuper(pel=2,levels=1,sharp=2)
#bv23=sup1.manalyse(isb=true, truemotion=false,global=true,delta=3,blksize=16,ov erlap=8,search=5,searchparam=4,DCT=5)
bv22=sup1.manalyse(isb=true, truemotion=false,global=true,delta=2,blksize=16,ov erlap=8,search=5,searchparam=4,DCT=5)
bv21=sup1.manalyse(isb=true, truemotion=false,global=true,delta=1,blksize=16,ov erlap=8,search=5,searchparam=4,DCT=5)
fv21=sup1.manalyse(isb=false,truemotion=false,glob al=true,delta=1,blksize=16,overlap=8,search=5,sear chparam=4,DCT=5)
fv22=sup1.manalyse(isb=false,truemotion=false,glob al=true,delta=2,blksize=16,overlap=8,search=5,sear chparam=4,DCT=5)
#fv23=sup1.manalyse(isb=false,truemotion=false,glo bal=true,delta=3,blksize=16,overlap=8,search=5,sea rchparam=4,DCT=5)
#a.mdegrain3(sup2,bv21,fv21,bv22,fv22,bv23,fv23,th SAD=499) # << this is the "2-fold" variant
interleave(a.mcompensate(sup2,fv22),a.mcompensate( sup2,fv21),a,a.mcompensate(sup2,bv21),a.mcompensat e(sup2,bv22))
TMedian2().selectevery(5,2)
sup3 = last.msuper(pel=2,sharp=2)
bv33=sup3.manalyse(isb=true, truemotion=false,global=true,delta=3,blksize=8,ove rlap=4,search=5,searchparam=4,DCT=5)
bv32=sup3.manalyse(isb=true, truemotion=false,global=true,delta=2,blksize=8,ove rlap=4,search=5,searchparam=4,DCT=5)
bv31=sup3.manalyse(isb=true, truemotion=false,global=true,delta=1,blksize=8,ove rlap=4,search=5,searchparam=4,DCT=5)
fv31=sup3.manalyse(isb=false,truemotion=false,glob al=true,delta=1,blksize=8,overlap=4,search=5,searc hparam=4,DCT=5)
fv32=sup3.manalyse(isb=false,truemotion=false,glob al=true,delta=2,blksize=8,overlap=4,search=5,searc hparam=4,DCT=5)
fv33=sup3.manalyse(isb=false,truemotion=false,glob al=true,delta=3,blksize=8,overlap=4,search=5,searc hparam=4,DCT=5)
last.mdegrain3(sup3,bv31,fv31,bv32,fv32,bv33,fv33, thSAD=499)
#stackvertical(a,last) # Alterado por mim.
return(last)
#--------------------------------------------------------------
# Helper functions
function MinBlur(clip clp, int r, int "uv")
{
uv = default(uv,3)
uv2 = (uv==2) ? 1 : uv
rg4 = (uv==3) ? 4 : -1
rg11 = (uv==3) ? 11 : -1
rg20 = (uv==3) ? 20 : -1
medf = (uv==3) ? 1 : -200
RG11D = (r==0) ? mt_makediff(clp,clp.sbr(),U=uv2,V=uv2)
\ : (r==1) ? mt_makediff(clp,clp.removegrain(11,rg11),U=uv2,V=u v2)
\ : (r==2) ? mt_makediff(clp,clp.removegrain(11,rg11).removegra in(20,rg20),U=uv2,V=uv2)
\ : mt_makediff(clp,clp.removegrain(11,rg11).removegra in(20,rg20).removegrain(20,rg20),U=uv2,V=uv2)
RG4D = (r<=1) ? mt_makediff(clp,clp.removegrain(4,rg4),U=uv2,V=uv2 )
\ : (r==2) ? mt_makediff(clp,clp.medianblur(2,2*medf,2*medf),U= uv2,V=uv2)
\ : mt_makediff(clp,clp.medianblur(3,3*medf,3*medf),U= uv2,V=uv2)
DD = mt_lutxy(RG11D,RG4D,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?",U=uv2,V=uv2)
clp.mt_makediff(DD,U=uv,V=uv)
return(last)
}
# median of 5 clips from Helpers.avs by G-force
Function Median2(clip "input_1", clip "input_2", clip "input_3", clip "input_4", clip "input_5", string "chroma")
{
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(reduceflicker=false) : Clense(reduceflicker=false,grey=true)
m1 = selectevery(3,1)
#MAX(MIN(i1,i3,i5),i2)
m2 = input_1.MT_Logic(input_3,"min",chroma=chroma).MT_L ogic(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_L ogic(input_5,"max",chroma=chroma).MT_Logic(input_4 ,"min",chroma=chroma)
Interleave(m1,m2,m3)
chroma == "process" ? Clense(reduceflicker=false) : Clense(reduceflicker=false,grey=true)
selectevery(3,1)
chroma == "copy first" ? last.MergeChroma(input_1) : chroma == "copy second" ? last.MergeChroma(input_2) : last
Return(last)
}
function TMedian2(clip c) {
Median2( c.selectevery(1,-2), c.selectevery(1,-1), c, c.selectevery(1,1), c.selectevery(1,2) ) }
+ Reply to Thread
Results 1 to 21 of 21
-
-
Remove grain from a VHS source?
Seems like you are doing a lot of processing. Throwing a bunch of filters at a video can often do more harm than good especially when the source if problematic.
I would be interested in seeing a couple of seconds of pre and post.
-
I agree. I don't think you really meant to say you're editing your "VHS files". I think you mean you're editing a VHS capture. Also looks like you captured directly to MPEG, which isn't a great idea. Despite the long script, it will take more than mdegrain to clean up VHS-to-MPEG artifacts -- and those artifacts will consist of a lot more than just "grain".
I second newpball's request for a video sample. You appear to know how to use DGIndex, which you can use to cut an .m2v sample and post here. Up to 10 seconds of unprocessed video with motion in it will suffice.- My sister Ann's brother -
Hi folks,
I uploaded 20 seconds of the video on youtube with the pre and pos Avisynth.
Only 20 seconds took 12 minutes. But many errors have been corrected.
Observation: I captured the VHS(NTSC) with the Panasonic AG1980 and I recorded it to DVD with the Panasonic DMRES15 (it's a DVD recorder). All Panasonic's filters were turned on during the process.
Pre Avisynth
https://www.youtube.com/watch?v=MqknHaOm_wk
Pos Avisynth
https://www.youtube.com/watch?v=JD7O52EHd_4
Thank you guys!Last edited by NLP; 7th Feb 2015 at 16:22.
-
Ideally you would want to show a sample of the captured video not the one that is put on a DVD.
-
My quad core i5 2500K (stock clock) encodes that script at about 2 fps with single threaded AviSynth, 7.5 fps with multithreaded AviSynth and six threads.
But I agree with others who have posted. If you want quality you don't want to capture with a DVD recorder and you don't want to use the DVD recorder's filters. You want to use the DVD recorder in pass-through mode (with the noise and sharpening filters disabled) to reduce the horizontal time base jitter, then capture with a device that lets you save the video uncompressed or losslessly compressed. THEN start filtering. -
Sorry for the late reply.
I converted the file to m2v. Follow below the pre and pos videos.
I installed the Avisynth 2.6 MT 20150125 in another PC (AMD 8350 8 core).
The Avisynth script was processing with 2.9 fps. I did some changes in the script. Thus, now it's processing with 14 fps and it's taking 1m28s (before it was taking 12 minutes). In the processing I'm using the 8 core with 100% - AVI without compression.
This change decreased a lot the process time but seems that the errors increased a lot too - specially after the first 5 minutes.
What do you think?
Is there some way to improve the first script (posted in the first post) aiming spend less time in the process?
Script Change:
SetMemoryMax(512)
SetMTMode(3)
LoadPlugin("m:\temp2\RemoveGrain.dll")
LoadPlugin("m:\temp2\MaskTools2-25.dll")
LoadPlugin("m:\temp2\Depan.dll")
LoadPlugin("m:\temp2\DepanEstimate.dll")
LoadPlugin("m:\temp2\MVTools2.dll")
mpeg2source("m:\temp2\test.d2v")
SetMTMode(2)
crop(0,64,-0,-64,true)
bob(0,0.5)
a=last
Thanks!Last edited by NLP; 10th Feb 2015 at 08:53.
-
How did you manage to capture an MPEG with a 2.045:1 aspect ratio?
Why are you cropping?
What do you want for final output?Last edited by LMotlow; 10th Feb 2015 at 13:01.
- My sister Ann's brother -
-
Well.okay. New one one me. So be it.
Anyway, I typed wrong. The AR in MediaInfo is 2.045:1, the cropped AVI is the same image AR (2.045:1, close enough) but with part of the top and bottom cut off.
Without cropping, the full m2v image looks correct at 4:3. I guess the O.P. wants 2:1 regardless.
I'll figure that out later.- My sister Ann's brother -
I have a Panasonic AG1980 VCR connected in S-video with a Panasonic DMRES10 (this product was referred by some videohelp members).
The DMRES10 is connected with one DVD Record LG RH397H by a component pass-thru. I have recorded the video into LG's internal HD or using the HDMI output that's connected with an Avermedia CO27 PCIe HD Capture Device. Therewith, I can record to DVD or Blu-ray resolution.
Like, I already said, I'm a beginner with Avisynth. The scripts that I used above was created by Didée and Pirej.
I have a lot of VHS(ntsc) tapes with many problems like: horizontal waves (lines), white waves, sometimes a color changing and some jumps (or skips).
If it's possible, I would like for a final output: improve the image with a good process time. I mean, where the process doesn't spend so much time.
Please, Do you know another script or some example to solve this problem?
Thank you in advance!
-
The Panasonic AG-1980 already has a built-in tbc. Why are you adding the DVD pass-thru? It's not doing anything. Your LG recorder might output HDMI, but the source display aspect ratio is still 4:3. Recording it to "HD" won't make it 16:9.
The long script might work to smooth the problems, but many here don't clean up VHS captured to lossy MPEG2. It's better than no capture at all, but capturing to lossy codecs makes the work more difficult than it should be.
If you are encoding to a 2:1 image ratio, you should know that HD formats are 16:9, and standard definition DVD/BluRay is either 4:3 or 16:9 (interlaced). If your intention is to upsample and encode to "HD" frame sizes (not a good idea with VHS source), it would have to be encoded as 1280x720p at 59.94 fps or upsampled and re-interlaced to 1920x1080 at 29.97fps, and both formats would have letterboxing and/or side pillars to display properly for standard HD. 1920x1080 BluRay HD progressive or SD 720x480 progressive at 59.94 fps is not allowed by the BluRay standard. So I assume that your final display intention is PC only or via external media player to a TV, at a 2:1 image aspect ratio. You cannot encode to 2:1 at standard definition for DVD or BluRay authored disc. A 2:1 image played on your PC or to a TV will add borders to fill a 16x9 screen, regardless of the way you encode.
Why your script and encoding are taking a long time depends on several factors, but what are you encoding to? If you're encoding for 1920x1080 for BluRay, your frames have to be resized, reinterlaced, and encoded.- My sister Ann's brother -
Using such strong filtering to remove dropouts is destroying all the detail in the picture. Consider using gentler filtering and frame replacement with ReplaceFramesMC(), aka RX().
https://forum.videohelp.com/threads/352741-Frame-interpolation?p=2226119&viewfull=1#post2226119
It's a lot more work since you have to view the video frame by frame to pick out those which need replacing. Attached is an example with just QTGMC and ReplaceFramesMC. -
-
That's absolutely true. And I might ask, "What detail?" -- meaning, what with camera shake, zooming, serious tape damage, and capturing to a lossy codec, it's a wonder that anything could survive filtering at all. We tell people that capturing bad crappy noisy damaged tape to lossy formats is The Big No-No, but.....what can ya do?
There must be something in between the two methods, probably something different but that takes up Jagabo's suggested functions while minimizing the obvious distortion that will happen when the people shots come around. OTOH, the slow script posted earlier has its own problems (anybody notice how parts of the airplane disappear into the background now and then?)
I think the O.P.'s idea of somehow making this into "HD" will prove a waste, even at 4:3 blown up to 1440x1080. Cropping the video gets into non-standard frame territory and some odd viewing effects. The image cropped to 2:1 but not enlarged will look mighty tiny on papa's 16x9 TV. Enlarged, all the defects get amplified and detail starts looking like crude etchings instead of video. Just too slim in the detail department for cropping/blowing-up.
I used the long, slow script posted earlier. Playing with jagabo's idea now, but any way you look at it the video looks better at its original aspect ratio rather than chopping away at it. By the time you get to 720p, the clip really falls apart. The attached samples are all encoded for HD and SD BluRay/AVCHD. I think maybe the O.P. doesn't know that BluRay includes standard defintion video at high bitrates.
And the original m2v is captured with too high an IRE level and looks washed out.Last edited by LMotlow; 10th Feb 2015 at 23:07.
- My sister Ann's brother -
Thank you very much guys.
I will take your advice and knowledge. I'm learning so many things here.
I will do more tests with others Vhs videos.
Please LMotlow, Can you show me what script specifically that you used?
P.s: I know that you wrote about the slow script with the jagabo's ideas, but as I don't know yet how to manage scripts. Know specifically what you put on Avisynth will help a lot.
Thanks again! -
Here's the basic script I used:
Code:import("C:\Program Files (x86)\AviSynth 2.5\plugins\ReplaceFramesMC.avs") Mpeg2Source("Pre Test m2v.demuxed.d2v", CPU2="ooooxx", Info=3) Crop(8,0,-8,-0) QTGMC(preset="fast") ReplaceFramesMC(45,1) ReplaceFramesMC(74,1) ReplaceFramesMC(101,1) ReplaceFramesMC(103,1) ReplaceFramesMC(106,1) ReplaceFramesMC(108,1) ReplaceFramesMC(116,1) ReplaceFramesMC(118,1) ReplaceFramesMC(123,1) ReplaceFramesMC(125,1) ReplaceFramesMC(128,1) ReplaceFramesMC(150,1) ReplaceFramesMC(152,1) ReplaceFramesMC(156,1) ReplaceFramesMC(185,1) ReplaceFramesMC(192,1) ReplaceFramesMC(200,1) ReplaceFramesMC(209,1) ReplaceFramesMC(256,1) ReplaceFramesMC(330,1) ReplaceFramesMC(334,2) ReplaceFramesMC(352,1) ReplaceFramesMC(355,1) ReplaceFramesMC(357,1) ReplaceFramesMC(393,1) ReplaceFramesMC(395,1) ReplaceFramesMC(442,1) ReplaceFramesMC(446,1) ReplaceFramesMC(449,1) ReplaceFramesMC(451,1) ReplaceFramesMC(453,1) ReplaceFramesMC(455,1) ReplaceFramesMC(483,1) ReplaceFramesMC(492,1)
Frame 74 original and after ReplaceFramesMC(74,1):
And the same frame from NLP's processed video:
Last edited by jagabo; 11th Feb 2015 at 08:05.
-
I used the original slow script mainly because it was already there, and time was getting late here. I think the script and images jagabo posted above would be better. I just didn't have time to run through all the bad frames last night.
You can use the same QTGMC that jagabo used and replace your slow script with the MC frame replacements jagabo used. Everyone will do this with some differences, but here is what I used for deintelace, reconstructing the frames for different output, and color tweaks:
In your first script I replaced this:
Code:bob(0,0.5)
Code:MPEG2Source("drive:\path\to\d2v\PreTestm2v.d2v") AssumeTFF().QTGMC(preset="very fast") Crop(6,0,-6,-4).AddBorders(6,2,6,2)
I saved the denoised video as a separate file that I named "Version1". Then I opened that denoised file and used this code for the 4:3 version:
Code:AviSource("Drive:\path\to\PreTest_version1.avi") ColorYUV(cont_y=15,off_y=-16,off_v=3) SmoothLevels(15, 1.0, 255, 15, 255) SmoothTweak(saturation=1.1) MergeChroma(awarpsharp2(depth=30)) AssumeTFF().SeparateFields().SelectEvery(4,0,3).Weave() Crop(0,4,0,-4).AddBorders(0,4,0,4)
Code:AviSource("Drive:\path\to\PreTest_version1.avi") Crop(4,60,-4,-60) ColorYUV(cont_y=15,off_y=-16,off_v=3) SmoothLevels(15, 1.0, 255, 15, 255) SmoothTweak(saturation=1.1) MergeChroma(awarpsharp2(depth=30)) Dither_convert_8_to_16 () Dither_resize16 (712, 472, kernel="spline36", cplace="MPEG2") DitherPost() AddBorders(4,4,4,4) AssumeTFF().SeparateFields().SelectEvery(4,0,3).Weave() Santiag()
For the 720p HD version, I opened the previous "Version1" denoised file with this code:
Code:AviSource("Drive:\path\to\PreTest_version1.avi") Santiag(2,2) Crop(4,60,-4,-60) ColorYUV(cont_y=15,off_y=-16,off_v=3) SmoothLevels(15, 1.0, 255, 15, 255) SmoothTweak(saturation=1.1) MergeChroma(awarpsharp2(depth=30)) Dither_convert_8_to_16 () Dither_resize16 (1272, 712, kernel="spline36", cplace="MPEG2") DitherPost() AddBorders(4,4,4,4)
SmoothLevels() and SmoothTweak() are functions in the SmoothAdjust plugin.
dithered 16-bit resizing is a function in the dither plugin package.
If you use jagabo's idea, you probably won't need Santiag() to clean the noisy edges.Last edited by LMotlow; 11th Feb 2015 at 09:04.
- My sister Ann's brother