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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 25th June 2015, 16:37   #1  |  Link
surgical
Dopax
 
Join Date: Dec 2009
Posts: 17
Help for improve my script

Greetings to all:
Recently, making some inquiries about using MP_pipeline on a Avisynth script, I received valuable advice regarding optimizing the code of the script (Thanks, colours).

Clearly, for maximum quality and efficiency with respect to what I wanted to achieve with this script , I've much to learn. Therefore, since that thread wasn't the right to further discuss that , I decided to seek help from experts in this excellent forum for further optimizing it. Not surprisingly, it's all of them, and the many hours reading these forums, where I started building my "primitive" script.

Never my intention wasn't to make a universal script; I know that each source has its peculiarities and filtering needs ; my intention is starting from a base with which to emphasize, define , "improve" visually (hopefully well be expressing the idea) HD high quality sources (mainly 1080, but also 720) before encoding (also with high scale quality) on x264, avoiding artifacts as far as possible. Something that would allow me, it could say , as a base template, range from uncompressed HD sources with low noise and smooth grain to those with less quality and more noise and / or grain.
I leave the script I posted in the beginning and then, changes, recommended by colours at first instance.
Thank you all in advance

" primitive script "

Quote:
Setmemorymax(1024)
SetMTMode(3,6)
LoadPlugin("C:\CODIFICACION VIDEO BD\MeGUI 2525\tools\dgindexnv\DGDecodeNV.dll")
DGSource("E:\CARPETA CODIFICACION\*******.dgi")
SelectRangeEvery(10000,500)

SetMTMode(2,0)
l_width = last.width
l_height = last.height
sss=1.5
dispWidth = round(sss*l_width/8)*8
dispHeight = round(sss*l_height/8)*8
mWidth = float(l_width)
mHeight = float(l_height)
ratio = (mWidth/mHeight)
newHeight= round((dispWidth/ratio)/8)*8
newHeight > dispHeight ? Eval("""
newHeight=dispHeight
newWidth=round((newHeight*ratio)/8)*8
""" ) : Eval("""
newWidth=dispWidth
""" )
LanczosResize(newWidth,newHeight)

Repair(Gaussresize(newWidth,newHeight,p=100),1)
source=last
s=60
w=12
w=w*(128/s)
subtract(source.binomialBlur(varY=0.4515, varC=0, Y=3, U=2, V=2, useMMX=true),source)
levels(0+s,1,255-s,0,255)
levels(127-w,1,128+w,127-w,128+w)
subtract(source,last)

LimitedSharpenFasterHC(strength=80)

UnsharpHQ(THRESHOLD=80,SHARPSTR=2.6,SMOOTH=0.0, SHOW=false)
aWarpSharp2(thresh=100, blur=2, type=0, depth=16, chroma=4)

source.mt_makediff(mt_makediff(source.binomialBlur(varY=0.0001, varC=0, Y=3, U=2, V=2, useMMX=true),last),U=2,V=2)

SMDegrain(tr=2,thSAD=180,prefilter=2,contrasharp=30,refinemotion=true,lsb=true,chroma=false,plane=0)
GradFun3()
FastLineDarkenMod()
LinearResize(1920,1080, kernel="spline36", mode=0)
changes recommended by colours ( with his comments )

Quote:
DGSource("E:\CARPETA CODIFICACION\*******.dgi")
SelectRangeEvery(10000,500)

sss = 1.5
newWidth = round(sss*width(last)/8)*8
newHeight = round(sss*height(last)/8)*8
LanczosResize(newWidth,newHeight)

source = last
s = 60
w = 24
mt_makediff(source.RemoveGrain(11),source)
mt_lut("x 128 - "+string(128.0/(128.0-s))+" * 128 + "+string(128-w)+" max "+string(128+w)+" min")
mt_makediff(source,last,u=2,v=2)

LimitedSharpenFasterHC(strength=80)

UnsharpHQ(THRESHOLD=80,SHARPSTR=2.6,SMOOTH=0.0, SHOW=false)
aWarpSharp2(thresh=100, blur=2, type=0, depth=16, chroma=4)
# do you really need four sharpening filters in a row?

last.MergeChroma(source)

FastLineDarkenMod() # moved this before denoising/debanding, but is this even necessary?

Spline36Resize(1920,1080)
# don't do the denoising/debanding with supersampling because
# that doesn't help with quality and makes things slower

SMDegrain(tr=2,thSAD=180,prefilter=2,contrasharp=30,refinemotion=true,lsb_in=false,lsb_out=true,chroma=false,plane=0)
GradFun3(lsb_in=true)
surgical is offline   Reply With Quote
Old 26th June 2015, 07:31   #2  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 308
My goal was to optimise for readability, not speed. (Mostly; mt_lut is a lot faster than Levels so I switched that in, even though RPN is kind of unreadable.)

Complicated scripts are often unnecessary, and even if they're necessary, you can often abstract huge chunks of the script into functions that can be reused for other scripts, rather than copy/pasting the same few lines every time.

What you're doing seems like the opposite: you copied some lines out of a dehaloing and sharpening filter directly into your script, rather than calling it as a function. In the process, you also got the implicit last mixed up so the dehaloing part does nothing at all. Don't do this.

If you need to modify a script filter's behaviour, don't copy its source into your script and edit that; edit the script filter directly. And of course, keep a backup of the original in case things break so you can easily roll back.
__________________
Say no to AviSynth 2.5.8 and DirectShowSource!
colours is offline   Reply With Quote
Old 26th June 2015, 11:02   #3  |  Link
surgical
Dopax
 
Join Date: Dec 2009
Posts: 17
Thanks colours .........obviously still have much to learn about this subject and, thanks to tips like these eventually go getting that knowledge. Again, thank you.

Regarding your script and, according to my claims and the kind of sources that I want to encode, agree on putting quality before speed and I would appreciate a lot, if not too much to ask, to accept and learn better in these last tips you have given me, you finished optimizing it, or polish (if they really need ..... if not express myself well) to take it as a good example of learning.

Regards
surgical is offline   Reply With Quote
Old 28th June 2015, 20:58   #4  |  Link
Keiyakusha
契約者
 
Keiyakusha's Avatar
 
Join Date: Jun 2008
Posts: 1,576
Taking colours' version, what I would do with this script is below.
It may sound a bit too harsh but I think you'll be best starting from scratch taking all colours' advices into account and using only filters that you understand and if video you are dealing with really can benefit from it. I hardly doubt that any video can benefit from your script if used as-is.

Code:
DGSource("E:\CARPETA CODIFICACION\*******.dgi")
SelectRangeEvery(10000,500)

sss = 1.5
newWidth = round(sss*width(last)/8)*8
newHeight = round(sss*height(last)/8)*8
LanczosResize(newWidth,newHeight)
# Get rid of this. If some sharpening function benefits from this, it should be already doing it internally

source = last
s = 60
w = 24
mt_makediff(source.RemoveGrain(11),source)
mt_lut("x 128 - "+string(128.0/(128.0-s))+" * 128 + "+string(128-w)+" max "+string(128+w)+" min")
mt_makediff(source,last,u=2,v=2)
# This is horrible. It might be useful as a part of some complex script but that's all.

LimitedSharpenFasterHC(strength=80)# This is some old function meant for realtime playback. Get rid of it

UnsharpHQ(THRESHOLD=80,SHARPSTR=2.6,SMOOTH=0.0, SHOW=false)# If you use this, don't use other sharpening
aWarpSharp2(thresh=100, blur=2, type=0, depth=16, chroma=4)# Never use this for sharpening something directly. Only as a building block for complex functions
# do you really need four sharpening filters in a row?
# You absolutely don't want to use more than one sharpening function.
# Whatever stick to UnsharpHQ if you think its good, or get proper limitedsharpen(faster)(mod)

last.MergeChroma(source) # This shouldn't be required assuming you remove everything above

FastLineDarkenMod() # moved this before denoising/debanding, but is this even necessary?
# this is mainly used for anime. Looking at what you did above, I really hope
# your source is not anime, but rather some horrible old blurred live-action DVDrip from some Indian DVD.
# Even if your source IS anime, you should reconsider using line darkening

Spline36Resize(1920,1080) # possibly not required assuming changes to the above will be made
# don't do the denoising/debanding with supersampling because
# that doesn't help with quality and makes things slower

SMDegrain(tr=2,thSAD=180,prefilter=2,contrasharp=30,refinemotion=true,lsb_in=false,lsb_out=true,chroma=false,plane=0)
# this might need some tweaking dpending on the stuff above. Like contrasharp off.
# Also I would use this before sharpening. If sharpening afterwards makes some artifacts/noise visible,
# that's because you're overdoing it.
GradFun3(lsb_in=true)

Last edited by Keiyakusha; 28th June 2015 at 21:12.
Keiyakusha is offline   Reply With Quote
Old 29th June 2015, 22:39   #5  |  Link
surgical
Dopax
 
Join Date: Dec 2009
Posts: 17
Thanks Kelyakusha..............i'll take in account your advices .
Greetings
surgical is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 22:31.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.