Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
9th April 2018, 17:50 | #1 | Link |
Registered User
Join Date: Mar 2018
Location: The netherlands
Posts: 2
|
Avisynth script performance
I have been following this forum for some time, and I have already gained a lot of information for my avisynth script.
I learned a lot from: StainlessS, VideoFred, johnmeyer and many. First of all, thank you for that Only now I am looking if I can tune the performace of my avisynth script. I have already applied many of the mentioned tricks, but think that this is not yet the maximum possible. Because currently it is around 3.5fps. I have already thought about migrating to vaporsynth, only I wonder if that will get the desired speed (8fps minimum). That is why I hope that people can help here. The flow:
Note: indeed it is based on the script of videofred and many of the later mentioned improvements. if I harm someone with this script, let me know, I will of course remove it. If I have not given someone a credit, please let me know. Code:
#============================================================================================= # cleaning, degraining, resizing, stabilizing, sharpening, auto-levels and auto-white balance. #============================================================================================= SetFilterMTMode("DEFAULT_MT_MODE", 2) film= "Yourmovie.avi" # source clip, you must specify the full path here #PARAMETERS #================================================================================================================================= result="result1" # specify the wanted output here trim_begin=3 trim_end=10 play_speed=24 #SIZE, CROP AND BORDERS PARAMETERS #............................................................................................................... CLeft=40 CTop=56 CRight=56 CBottom=40 #crop values after Depan and before final resizing WDown = 1024 HDown=768 #Downscale size before actions WUp=1540 HUp=1084 #Upscale size after sharping bord_left=0 bord_top=0 bord_right=0 bord_bot=0 #STABILISING PARAMETERS #............................................................................................................... maxstabH=20 maxstabV=20 #maximum values for the stabiliser (in pixels) 20 is a good start value est_left=20 est_top=60 est_right=60 est_bottom=60 #crop values for special Estimate clip cutoff_value= 0.5 # no need to change this, but you can play with it and see what you get #CLEANING PARAMETERS #............................................................................................................... dirt_strenght=40 # set this lower for clean films. #DENOISING PARAMETERS #............................................................................................................... block_size= 16 #block size of MVDegrainMulti() block_over= 8 #block overlapping of MVDegrainMulti() # SHARPENING PARAMETERS #............................................................................................................... first_USM_radius= 5 #Radius for the first Unsharpmask second_USM_radius= 2 #Radius for the second Unsharpmask first_USM_sharpness= 40 #Radius for the first Unsharpmask second_USM_sharpness= 40 #Radius for the second Unsharpmask first_blur= 0.8 #this smooths out the heavy sharpening effects second_blur= 0.8 #this smooths out the heavy sharpening effects sharpen= 0.8 #Sharpening factor # END PARAMETERS, BEGIN SCRIPT #================================================================================================================================= #LOAD PLUGINS #............................................................................................................... Loadplugin("plugins/RemoveGrainSSE2.dll") Loadplugin("plugins/Repair.dll") Loadplugin("plugins/Depan.dll") Loadplugin("plugins/RemoveDirtSSE2.dll") Loadplugin("plugins/MVTools.dll") Loadplugin("plugins/mvtools2.dll") Loadplugin("plugins/gammac.dll") Loadplugin("plugins/warpsharp.dll") LoadPlugin("plugins/FredAverage.dll") LoadPlugin("plugins/unsharpHQ.dll") #START SCRIPT #............................................................................................................... source = DirectShowSource(film, audio=false, video=true).assumefps(play_speed).converttoYV12() source = source.trim(trim_begin,0) trimming = framecount(source)-trim_end source = trim(source,0,trimming) #Down scaling #............................................................................................................... source = source.Lanczos4Resize(WDown, HDown) #STABILIZING/CROPPING #............................................................................................................... mdata = source.crop(20,20,-20,-20).colorYUV(autogain=true).crop(est_left,est_top,-est_right,-est_bottom) vectors = source.MSuper().MAnalyse(isb=false) mdata = MDepan(mdata,vectors,rot=false, zoom=false) source =source.DePanStabilize(data=mdata,cutoff=cutoff_value, dxmax=maxstabH,dymax=maxstabV,zoommax=0,rotmax=0,method=0,info=false).deflicker() source = source.crop(CLeft,CTop,-CRight,-CBottom) #REMOVEDIRT #............................................................................................................... source = RemoveDirtSMC(source,dirt_strenght,false) #GAMMAC CORRECTION #............................................................................................................... source = source.converttoRGB24() Average = source.FredAverage(invert=true) source = source.gammac(dc = Average, show=false) source = source.converttoYV12() #UP scaling #............................................................................................................... source = source.Lanczos4Resize(WUp, HUp) #SHARPEN #............................................................................................................... source = source.unsharpmask(first_USM_sharpness,first_USM_radius,0) source = source.blur(first_blur,mmx=false) source = source.unsharpmask(second_USM_sharpness,second_USM_radius,0) source = source.blur(second_blur,mmx=false) source = source.sharpen(sharpen,mmx=false) #DENOISING #............................................................................................................... source = source.McDegrainSharp(2,bsrch=true,Precise=true) #RESULT #............................................................................................................... source = source.converttoYV12().addborders(bord_left, bord_top, bord_right, bord_bot) result1 = source Eval(result)# #REMOVE DIRT FUNCTIONS #............................................................................................................... function RemoveTempGrain(clip clp, int "_mode") { _mode = Default(_mode, 17) rg = RemoveGrain(clp, mode=_mode) return TemporalRepair(rg, clp) } function RemoveDirtS(clip clp, int "limit", bool "_grey") { _grey = Default(_grey, false) limit = Default(limit, 6) clensed = clp.Clense(grey=_grey, cache=4) alt = clp.RemoveGrain(10) return (RestoreMotionBlocks(clensed, clp, alternative=alt, pthreshold=4, cthreshold=6, gmthreshold=40, \ dist=1, dmode=2, debug=false, noise=limit, noisy=16, grey=_grey)) } function RemoveDirtSMC(clip clp, int "limit", bool "_grey") { _grey = Default(_grey, false) limit = Default(limit, 6) super1 = MSuper(clp, pel=2, sharp=2) bvec1 = MAnalyse(super1, isb=true, blksize=16, delta=1, truemotion=true) fvec1 = MAnalyse(super1, isb=false, blksize=16, delta=1, truemotion=true) backw1 = MFlow(clp, super1, bvec1) forw1 = MFlow(clp, super1, fvec1) clp = Interleave(backw1, clp, forw1) clp = clp.RemoveDirtS(limit, _grey).removetempgrain(10) clp = clp.SelectEvery(3, 1) return clp } function McDegrainSharp(clip c, int "frames", float "bblur", float "csharp", bool "bsrch", int"strenght", bool "Precise") { frames = default(frames, 2) strenght = default(strenght,400) bblur = default(bblur, 1.0) csharp = default(csharp, 1.0) bsrch = default(bsrch, true) blocks = 16 overl = block_over c2 = c.blur(bblur) super = bsrch ? c2.MSuper(pel=2, sharp=1) : c.MSuper(pel=2, sharp=1) super_rend = c.sharpen(csharp).MSuper(pel=2, sharp=1,levels=1) backward_vec3 = MAnalyse(super, isb = true, delta = 3, blksize=blocks, overlap=overl) backward_vec2 = MAnalyse(super, isb = true, delta = 2, blksize=blocks, overlap=overl) backward_vec1 = MAnalyse(super, isb = true, delta = 1, blksize=blocks, overlap=overl) forward_vec1 = MAnalyse(super, isb = false, delta = 1, blksize=blocks, overlap=overl) forward_vec2 = MAnalyse(super, isb = false, delta = 2, blksize=blocks, overlap=overl) forward_vec3 = MAnalyse(super, isb = false, delta = 3, blksize=blocks, overlap=overl) (frames<=0) ? c :\ (frames==1) ? c2.MDegrain1(super_rend, backward_vec1,forward_vec1,thSAD=strenght) :\ (frames==2) ? c2.MDegrain2(super_rend, backward_vec1,forward_vec1,backward_vec2,forward_vec2,thSAD=strenght) :\ c2.MDegrain3(super_rend, backward_vec1,forward_vec1,backward_vec2,forward_vec2,backward_vec3,forward_vec3,thSAD=strenght) return(last) } |
9th April 2018, 19:38 | #2 | Link |
Registered User
Join Date: Feb 2002
Location: California
Posts: 2,691
|
Suggestions:
1. Do tests to see if you must process everything at HD levels. See if you can tell any difference between SD (720x480) and higher resolutions when dealing with 8mm or Super 8 material. I do the capture with my Sony FX-1, which is HD, but then do a down-conversion in the camera and output, process, and deliver as SD. 2. Fully enable multi-threading. You didn't say what version of AVISynth you are using, but since I see a SetFilterMTMode() statement, I assume you are using AVISynth+. To get the best multi-threading performance, you need to specify this setting for each call from each plugin you are using. For instance, for MVTools2, these are some of the statements that need to be added: Code:
######################################### # Filters from MVTools v2.6.0.5 (from http://forum.doom9.org/showthread.php?p=1386559#post1386559 ) Tested On 2016/03/06 SetFilterMTMode("MDegrain2", MT_MULTI_INSTANCE) SetFilterMTMode("MSuper", MT_MULTI_INSTANCE) SetFilterMTMode("MAnalyse", MT_MULTI_INSTANCE) SetFilterMTMode("MFlowFps", MT_MULTI_INSTANCE) SetFilterMTMode("MRecalculate", MT_MULTI_INSTANCE) ######################################### Prefetch(threads) where "threads" is a variable you define that has the number of multi-threading cores you are going to use. If you have an 8-core computer, start out with threads=4 and work up from there. Since I don't see this line in your code, you are not getting any multi-threading. Start by adding this line and see if you don't get a 2x or more speed improvement. 3. Use a smaller block overlap. Block size and overlap make a HUGE difference in script performance. At the risk of making a generalization that isn't always true, larger block size is good when doing frame rate changes (such as changing the output speed) and smaller block sizes (even as small as 4) are good for denoising. 4. I optimized my version of VideoFred's script for speed, so you might want to consider using that. However, while I have a private version that uses GamMac, I don't have it working to my satisfaction, so I haven't uploaded it. But, you could try my old script. I think that #2 is probably what you will be most interested in, given how you asked your question. Play around with that Prefetch command. It has to be the last line and I'd start by adding it directly after the Eval() statement. Others will let you know if that is the correct place for it. |
9th April 2018, 23:00 | #3 | Link | ||
Registered User
Join Date: Mar 2018
Location: The netherlands
Posts: 2
|
Quote:
This will decrease my performance in the end. I build my own application were i can tweak the script and then apply that script to a complete folder. This program also devides the scripts over multiple cores on multiple computers. So 1 script is running 3.5fps now, but a lot of scripts are running simultaneously. (but you couldnt know that, my bad for not posting this (i am sorry), but thanks for the tip) Quote:
I am now playing with the idea to see if it is possible to translate the McDegrainSharp function to svp. Hoping that this tweak will improve the performance. anybody already did this before? Update 1:Already found someone that had the same idea: Link to post. Now i have to check why that version has artifacts. Update 2: further on in the post someone has already Less artifacts Last edited by flipkipse; 9th April 2018 at 23:24. |
||
Tags |
avisynth |
Thread Tools | Search this Thread |
Display Modes | |
|
|