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 9th February 2022, 22:14   #1  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
ScriptClip AverageLuma Value in Function

Im trying to make a function that will detect an average luma of the image and use the resulting number into levels approximately like this:
(but without printing the result with Subtitle)
Code:
ScriptClip(Last, """
    threshold = 55
    luma = AverageLuma ## gives the average luma of the current frame
    luma < threshold 
    \ ? Levels(0, 1.0+0.5*(threshold-luma)/threshold, 255, 0, 255) 
    \ : last
    Subtitle("luma=" + String(luma), align=2)
""")

function AutoL(clip c)
{
c.ex_levels((luma/340),(luma/6100),237,0,170)
return last
}
Okay I don't have a clue how to get ScriptClip to work inside a function also and I would also know if there is possible to make rounding: luma/6100<---here, inside of the "ex_levels"-line.
Thanks!

EDIT: Thought I figured out the "rounding" thing
Code:
ex_levels((luma/340%.0f),(luma/6100%.2f),237,0,170)
but I didn't.
Anyway I got it to work sort of but its really slow:
Code:
function AutoL(clip c)
{
current_frame = 0
luma=Averageluma(c)
c.ex_levels((luma/340),(luma/6100),237,0,170)
return last
}
So could this be restricted so that AverageLuma only grabs the value from the first frame of the clip instead of every frames during the whole clip? Wouldn't that be faster?

EDIT2:
Changing to:
Code:
function AutoL(clip c)
{
current_frame = -1
luma=Averageluma(c)
c.ex_levels((luma/340),(luma/6100),237,0,170)
return last
}
made it faster

Last edited by anton_foy; 10th February 2022 at 00:53.
anton_foy is offline   Reply With Quote
Old 10th February 2022, 00:52   #2  |  Link
Dogway
Registered User
 
Join Date: Nov 2009
Posts: 2,361
What about this:

Code:
function AutoL(clip c, int "thr") {
    thr = Default(thr, 55)
    ScriptClip(c,function[thr] () {
        luma = AverageLuma() ## gives the average luma of the current frame
        luma < thr
        \ ? ex_levels((luma/340),1.0+0.5*(thr-luma)/thr,237,0,170)
        \ : last
    } ) }
I'm working on SceneStats so you can get AverageLuma of the entire scene to do some filtering based on that.
__________________
i7-4790K@Stock::GTX 1070] AviSynth+ filters and mods on GitHub + Discussion thread
Dogway is offline   Reply With Quote
Old 10th February 2022, 01:06   #3  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
Quote:
Originally Posted by Dogway View Post
What about this:

Code:
function AutoL(clip c, int "thr") {
    thr = Default(thr, 55)
    ScriptClip(c,function[thr] () {
        luma = AverageLuma() ## gives the average luma of the current frame
        luma < thr
        \ ? ex_levels((luma/340),1.0+0.5*(thr-luma)/thr,237,0,170)
        \ : last
    } ) }
I'm working on SceneStats so you can get AverageLuma of the entire scene to do some filtering based on that.
Thank you Dogway! Fast and nice. What if I want to extend my function adding more lines before and after ex_levels, is that tricky? Im not too familiar with this runtime-stuff
BTW looking forward to SceneStats!
anton_foy is offline   Reply With Quote
Old 10th February 2022, 01:43   #4  |  Link
Dogway
Registered User
 
Join Date: Nov 2009
Posts: 2,361
You can use Eval() or use a pointer, I prefer the second.

Code:
function AutoL(clip c, int "thr") {
    thr = Default(thr, 55)
    ScriptClip(c,function[thr] () {
        luma = AverageLuma()
        orig = last
        ex_levels((luma/340),1.0+0.5*(thr-luma)/thr,237,0,170)
        blabla()
        luma < thr : last : orig
    } ) }
Maybe by March I have SceneStats, first I'm making SceneChange() for robust SC detection with lookahead.
__________________
i7-4790K@Stock::GTX 1070] AviSynth+ filters and mods on GitHub + Discussion thread
Dogway is offline   Reply With Quote
Old 10th February 2022, 10:20   #5  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
Quote:
Originally Posted by Dogway View Post
You can use Eval() or use a pointer, I prefer the second.

Code:
function AutoL(clip c, int "thr") {
    thr = Default(thr, 55)
    ScriptClip(c,function[thr] () {
        luma = AverageLuma()
        orig = last
        ex_levels((luma/340),1.0+0.5*(thr-luma)/thr,237,0,170)
        blabla()
        luma < thr : last : orig
    } ) }
Maybe by March I have SceneStats, first I'm making SceneChange() for robust SC detection with lookahead.
Thanks! Although when I try to fit this code into it I run into problems:
Code:
function AutoNR(clip c, string "Preset", int "TR", int "BLK", int "THSAD", float "SHARP",
\	 	 int "WARP")
{

# Select presets:
    Preset = default( Preset, "Medium" )
    pNum = (Preset == "Low"   ) ? 0 : \
           (Preset == "Medium" ) ? 1 : \
           (Preset == "High"    ) ? 2 : \
           Assert( FALSE , "'Preset' choice is invalid" )


	# Preset defaults:                                    Low       Medium     High
	TR           = default( TR,           Select( pNum,    1 ,         3 ,       4  ) )
	BLK          = default( BLK,          Select( pNum,    16,         16,       16 ) )
	THSAD        = default( THSAD,        Select( pNum,   220,         340,     470 ) )
	SHARP        = default( SHARP,        Select( pNum,  0.16,       0.20,     0.24 ) )
	WARP         = default( WARP,         Select( pNum,    4 ,         6 ,       7  ) )

  ### Temporal color NR
v=c.vsCnr2(mode="ooo",ln=5,un=40,vn=40,sceneChroma=false).vsCnr2(mode="ooo",ln=5,un=40,vn=40,sceneChroma=false)

  ### Spatial NR
s=v.fft3dgpu(sigma=0.3,sigma2=0.4,sigma3=1.4,sigma4=1,plane=3,bt=3).
\	fft3dgpu(sigma=0.3,sigma2=0.4,sigma3=1.6,sigma4=2.7,plane=0,bt=3).ex_vibrance(1.2)

  ### Dynamic NR mask
emask=v.ex_levels((luma/340),(luma/6100),237,0,170)
m=mt_merge(v,s,emask.mt_invert().mt_inpand(),Y=3,U=3,V=3, luma=true)

  ### Dynamic prefilter
p=m.coloryuv(autogain=true).vdmc()

  ### Temporal NR
sm=m.SmDegrain(prefilter=p,tr=tr,thsad=thsad,blksize=blk).tweak(sat=1.06)

sh=sm.awarpsharp2(depth=warp)
sh = sh.sharpen(sharp)

  ### Debanding
sh.neo_f3kdb(grainY=40,grainC=3,mt=true)

return last
}
I also tried this code but I get a strange error that fft3dgpu.hlsl is missing a ')':
Code:
function AutoNR3(clip c, string "Preset", int "TR", int "BLK", int "THSAD", float "SHARP",
\	 	 int "WARP")
{

        # Select presets:
    Preset = default( Preset, "Medium" )
    pNum = (Preset == "Low"   ) ? 0 : \
           (Preset == "Medium" ) ? 1 : \
           (Preset == "High"    ) ? 2 : \
           Assert( FALSE , "'Preset' choice is invalid" )


	# Preset defaults:                                    Low       Medium     High
	TR           = default( TR,           Select( pNum,    1 ,         3 ,       4  ) )
	BLK          = default( BLK,          Select( pNum,    16,         16,       16 ) )
	THSAD        = default( THSAD,        Select( pNum,   220,         340,     470 ) )
	SHARP        = default( SHARP,        Select( pNum,  0.16,       0.20,     0.24 ) )
	WARP         = default( WARP,         Select( pNum,    4 ,         6 ,       7  ) )

ScriptClip(c,function[tr,blk,thsad,sharp,warp] () {
        luma = AverageLuma()
        orig = last


  ### Temporal color NR
vsCnr2(mode="ooo",ln=5,un=40,vn=40,sceneChroma=false)
vsCnr2(mode="ooo",ln=5,un=40,vn=40,sceneChroma=false)

  ### Spatial NR
s=fft3dgpu(sigma=0.3,sigma2=0.4,sigma3=1.4,sigma4=1,plane=3,bt=3).
\	fft3dgpu(sigma=0.3,sigma2=0.4,sigma3=1.6,sigma4=2.7,plane=0,bt=3).ex_vibrance(1.2)

f = last

  ### Dynamic NR mask
emask=ex_levels((luma/340),(luma/6100),237,0,170)
mt_merge(f,s,emask.mt_invert().mt_inpand(),Y=3,U=3,V=3, luma=true)

  ### Dynamic prefilter
p=coloryuv(autogain=true).vdmc()

  ### Temporal NR
SmDegrain(prefilter=p,tr=tr,thsad=thsad,blksize=blk).tweak(sat=1.06)

  ### Sharpen
awarpsharp2(depth=warp)
sharpen(sharp)

  ### Debanding
neo_f3kdb(grainY=40,grainC=3,mt=true)

#return last
        luma < last 
    } ) }
Im sure this is totally wrong what I just tried though. Yes I skipped the "thr" part since I didn't get the levels right with it included.
This line looks good:
Code:
ex_levels((luma/340),(luma/6100),237,0,170)
But this line doesn't get it quite right:
Code:
ex_levels((luma/340),1.0+0.5*(thr-luma)/thr,237,0,170)
anton_foy is offline   Reply With Quote
Old 10th February 2022, 10:49   #6  |  Link
kedautinh12
Registered User
 
Join Date: Jan 2018
Posts: 2,156
Just copy fft3dgpu.hlsl next to fft3dgpu.dll
kedautinh12 is offline   Reply With Quote
Old 10th February 2022, 13:07   #7  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
Quote:
Originally Posted by kedautinh12 View Post
Just copy fft3dgpu.hlsl next to fft3dgpu.dll
Thanks but it already is. FFT3DGpu worked without any problems before I made that script I just posted.
anton_foy is offline   Reply With Quote
Old 11th February 2022, 22:23   #8  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
Quote:
Originally Posted by Dogway View Post
You can use Eval() or use a pointer, I prefer the second.

Code:
function AutoL(clip c, int "thr") {
    thr = Default(thr, 55)
    ScriptClip(c,function[thr] () {
        luma = AverageLuma()
        orig = last
        ex_levels((luma/340),1.0+0.5*(thr-luma)/thr,237,0,170)
        blabla()
        luma < thr : last : orig
    } ) }
Maybe by March I have SceneStats, first I'm making SceneChange() for robust SC detection with lookahead.
I had to remove "current_frame" because it screws up the resulting numbers completely so I must go with the ScriptClip.
As I read about ScriptClip and how it works I find:
Code:
Calling a lot of filters / functions inside the runtime script will slow down your encoding speed. Those filters will be created and destroyed on every frame; thus you pay initialisation/cleanup costs at every frame.
If you can, put outside the runtime environment those filter calls not essential for the runtime processing; break the runtime script into more scripts if you have to. For example, instead of doing this:
http://avisynth.nl/index.php/The_scr...considerations

I tested out my new function and found that I need to use "RDifferenceFromPrevious()" instead of AverageLuma. Still need to
get scriptclip to work inside my function and for more than one line.

Like this:
Code:
function AutoNR(clip c, int "TR", int "BLK", float "SHARP", int "WARP")
{
    tr = Default(tr, 4)
    blk = Default(blk, 16)
    sharp = Default(sharp, 0.24)
    warp = Default(warp, 7)

###ScriptClip lines in BOLD
rex = ex_levels(0,0.48,48).converttorgb24().ExtractR()
red = RDifferenceFromPrevious(rex)
low = red/4.6
mid = low/1.7
ths = int(red)*36

c.fft3dgpu(sigma=0.3,sigma2=0.4,sigma3=(MID),sigma4=(LOW),plane=4,bt=3)
FluxSmoothT(temporal_threshold=10, luma=false, chroma=true)
vsCnr2(mode="ooo",ln=5,un=40,vn=40,sceneChroma=false)
p=coloryuv(autogain=true).vdmc()
SmDegrain(prefilter=p,tr=tr,thsad=ths,blksize=blk).tweak(sat=1.06)
awarpsharp2(depth=warp)
sharpen(sharp)
neo_f3kdb(grainY=40,grainC=3,mt=true)

return last
}
"Simply" what I want is to feed the resulting number from RDifferenceFromPrevious to "MID", "LOW" and "THS" so I guess these two lines
Code:
fft3dgpu(sigma=0.3,sigma2=0.4,sigma3=(MID),sigma4=(LOW),plane=4,bt=3)
SmDegrain(prefilter=p,tr=tr,thsad=ths,blksize=blk)
have to be separated with a Scriptclip call? I have a hard time to wrap my head around this.

Last edited by anton_foy; 11th February 2022 at 22:27.
anton_foy is offline   Reply With Quote
Old 18th February 2022, 00:21   #9  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
This test is working how I want it resulting in a number:

Code:
ScriptClip(last, """
    red = ex_levels(0,0.48,48).converttorgb().ExtractR().invert()
    redavg = RDifferenceFromPrevious(red)
Subtitle("luma=" + String(redavg), align=2)
""")
But not if I want to make a function like this to feed the number into fft3dgpu:
Code:
function ANR(clip c)
s=ScriptClip(last, """
    red = ex_levels(0,0.48,48).converttorgb().ExtractR().invert()
    redavg = RDifferenceFromPrevious(red)
    #return last
""")

sig  = s/4.6
sig2 = s/1.6
c.fft3dgpu(sigma=sig,sigma2=sig2)
return last
Not getting this to work. Is my way of thinking totally off? To feed the 'RDifferenceFromPrevious' resulting number to sigma (for example) and divide it (or do some other math).

Last edited by anton_foy; 18th February 2022 at 00:45.
anton_foy is offline   Reply With Quote
Old 18th February 2022, 00:53   #10  |  Link
Dogway
Registered User
 
Join Date: Nov 2009
Posts: 2,361
You have to put everything that's dynamic inside ScriptClip, that's the basis.
Sometimes you can do some tricks/cheats like writing to frameprops and then retrieving them but it's not standard practice.
__________________
i7-4790K@Stock::GTX 1070] AviSynth+ filters and mods on GitHub + Discussion thread
Dogway is offline   Reply With Quote
Old 18th February 2022, 01:33   #11  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
Quote:
Originally Posted by Dogway View Post
You have to put everything that's dynamic inside ScriptClip, that's the basis.
Sometimes you can do some tricks/cheats like writing to frameprops and then retrieving them but it's not standard practice.
Thanks! Then I have to cheat I guess using frameprops to retrieve them. What you say makes more sense now but I still am not sure how it is suppose to be written. More testing ahead.
anton_foy is offline   Reply With Quote
Old 18th February 2022, 10:49   #12  |  Link
Dogway
Registered User
 
Join Date: Nov 2009
Posts: 2,361
This? also I really don't like fft3dgpu, unless you are doing some dirty job (very damaged clips) and it gets the job done I would rather use the CPU version which is totally different (more correct?)
Code:
ScriptClip(last, """
    red = ex_levels(0,0.48,48).converttorgb().ExtractR().invert()
    redavg = RDifferenceFromPrevious(red)
    sig  = redavg/4.6
    sig2 = redavg/1.6
    fft3dgpu(sigma=sig,sigma2=sig2)
""")
__________________
i7-4790K@Stock::GTX 1070] AviSynth+ filters and mods on GitHub + Discussion thread
Dogway is offline   Reply With Quote
Old 18th February 2022, 15:08   #13  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
Quote:
Originally Posted by Dogway View Post
This? also I really don't like fft3dgpu, unless you are doing some dirty job (very damaged clips) and it gets the job done I would rather use the CPU version which is totally different (more correct?)
Code:
ScriptClip(last, """
    red = ex_levels(0,0.48,48).converttorgb().ExtractR().invert()
    redavg = RDifferenceFromPrevious(red)
    sig  = redavg/4.6
    sig2 = redavg/1.6
    fft3dgpu(sigma=sig,sigma2=sig2)
""")
Dogway!!! Thanks man!!! I lost hair over this. Yes I agree I noticed this too with fft3dgpu but for now to speed things up a bit. Probably will use neo_fft3d in the end. Checked your grainfactory3mod.avsi which use scriptclip in the end so I was in the area of correct usage but this was a bomb what you just put. I will have to use the 'redavg' results later in the script with your version of smdegrain aswell. Would you suggest I do another scriptclip line again replacing fft3dgpu with smdegrain or is there a more effective way? I hope I dont push it, I learn so much from you.

Btw. your new smdegrain version is so fast and pleasant looking at default. The reason I dumped fastdegrain.

Last edited by anton_foy; 18th February 2022 at 15:12.
anton_foy is offline   Reply With Quote
Old 18th February 2022, 22:16   #14  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
Quote:
Originally Posted by Dogway View Post
This? also I really don't like fft3dgpu, unless you are doing some dirty job (very damaged clips) and it gets the job done I would rather use the CPU version which is totally different (more correct?)
Code:
ScriptClip(last, """
    red = ex_levels(0,0.48,48).converttorgb().ExtractR().invert()
    redavg = RDifferenceFromPrevious(red)
    sig  = redavg/4.6
    sig2 = redavg/1.6
    fft3dgpu(sigma=sig,sigma2=sig2)
""")
Tried it but it gives me error "invalid arguments to function ScriptClip":
Code:
function anr(clip c){
ScriptClip(last, """
    red = ex_levels(0,0.48,48).converttorgb().ExtractR().invert()
    redavg = RDifferenceFromPrevious(red)
    sig  = redavg/4.6
    sig2 = redavg/1.6
    fft3dgpu(sigma=sig,sigma2=sig2)
""") #<--- error on this line
vsCnr2(mode="ooo",ln=5,un=40,vn=40,sceneChroma=false)
return last
}
anton_foy is offline   Reply With Quote
Old 18th February 2022, 23:14   #15  |  Link
Dogway
Registered User
 
Join Date: Nov 2009
Posts: 2,361
Maybe this:
Quote:
Originally Posted by anton_foy View Post
Tried it but it gives me error "invalid arguments to function ScriptClip":
Code:
function anr(clip c){
ScriptClip(c, """
    red = ex_levels(0,0.48,48).converttorgb().ExtractR().invert()
    redavg = RDifferenceFromPrevious(red)
    sig  = redavg/4.6
    sig2 = redavg/1.6
    fft3dgpu(sigma=sig,sigma2=sig2)
""")
vsCnr2(mode="ooo",ln=5,un=40,vn=40,sceneChroma=false)
return last
}
__________________
i7-4790K@Stock::GTX 1070] AviSynth+ filters and mods on GitHub + Discussion thread
Dogway is offline   Reply With Quote
Old 19th February 2022, 03:35   #16  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
Quote:
Originally Posted by Dogway View Post
Maybe this:
Thanks it works now but the number from RDifferenceFromPrevious
seems to get wrong when fed into the sigma's. For example on frame 1 on my test clip I got 12.524107 according to
Code:
Subtitle("redavg=" + String(redavg), align=2)
So I would think that
Code:
csig4 = redavg/6
would result in: 2.087351166666667 (although I would like it to be rounded to just 2.0 or 2.1)
When I try the script below sigma's seem to be super high like 40 or something, totally smeared out the chroma.
Do I need to convert into string(redavg, "%0.1f") and then to float or something to get correct values?

Code:
function anr(clip c){
ScriptClip(c, """
    red = ex_levels(0,0.48,48).converttorgb().ExtractR()
    redavg = RDifferenceFromPrevious(red)
    csig3 = redavg/30
    csig4 = redavg/6
mergechroma(temporalsoften(4,0,255,0,2).
\	neo_fft3d(sigma=0,sigma2=0,sigma3=csig3,sigma4=csig4,bt=1,y=1,u=3,v=3))""")
vsCnr2(mode="ooo",ln=5,un=40,vn=40,sceneChroma=false)
return last
}
EDIT: Update, tried the whole script as intended (think I got the numbers correct at last) but it is unusable, too slow to even start and my cpu goes up to 100% for 10 minutes without anything happening. Because I put almost everything into ScriptClip? Feels like such a hassle with ScripClip only to get one number to recalculate and feed the different parameters in the script. But I guess the whole filter (fft3dgpu for example) must be in runtime mode for it to work and not just the parameters in it.

Code:
function anr(clip c){
ScriptClip(c, """
    red = ex_levels(0,0.48,48).converttorgb().ExtractR()
    redavg = RDifferenceFromPrevious(red)
    csig3 = redavg/8400
    csig4 = redavg/1700
    sig3  = redavg/1700
    sig4  = redavg/1260
    ths_  = redavg*0.138
    ths   = int(ths_)
    shr   = redavg*0.00006
mergechroma(temporalsoften(4,0,255,0,2).
\	neo_fft3d(sigma=0,sigma2=0,sigma3=csig3,sigma4=csig4,bt=1,y=1,u=3,v=3))
vsCnr2(mode="ooo",ln=5,un=40,vn=40,sceneChroma=false)
neo_fft3d(sigma=0.4,sigma2=0.6,sigma3=sig3,sigma4=sig4,y=3,u=2,v=2,bt=3)
p=convertbits(8).coloryuv(autogain=true).TemporalSoften(3,4,8,scenechange=0,mode=2)
SmDegrain(prefilter=p,tr=4,thsad=ths)
sharpen(shr)""")
awarpsharp2(depth=7)
neo_f3kdb(grainY=40,grainC=3,mt=true)
return last
}
Edit2:
Look here at "mdiff2" by raffriff42: https://forum.doom9.org/showthread.p...52#post1756852
This shows difference from the previous frame without the use of scriptclip. Is there no way of getting resulting numbers instead of visual difference by using this technique?

Last edited by anton_foy; 20th February 2022 at 01:29.
anton_foy is offline   Reply With Quote
Old 5th March 2022, 14:12   #17  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
At it again...this code below gives me error
Code:
"MAnalyse: Clip must be YUV or YUY2 ...SmDegrain.avsi, line 294, line 345, line 634"
Code:
Code:
function anv(clip c){
converttoPlanarRGB(c)
fft3dfilter(sigma=0.3,sigma2=0.4,sigma3=1.7,sigma4=2.1,plane=4,bt=4)
S=ScriptClip("""
    lum = converttorgb().invert().averageG
    rgb = converttorgb().RGBDifferenceFromPrevious
luma = int(lum + rgb)
ltr  = int(luma*0.00009)
ths  = int(luma*0.01)

p = convertbits(8).TemporalSoften(3,4,6,0,2).ex_levels(10,0.95,126)
SmDegrain(prefilter=p,tr=ltr,thsad=ths,DCT=1)
	#Subtitle("luma=" + String(ths) +","+ String(ltr), align=2)
""")
n = s.converttoyuv444()
n = n.vsCnr2(mode="ooo",ln=5,un=40,vn=40,sceneChroma=false)
n = n.neo_f3kdb(grainY=40,grainC=3,mt=true).tweak(sat=1.16)
return n
}
Although SmDegrain works in Planar RGB outside scriptclip...why not here?

EDIT: Aaah I missed the "c,"
Now it is working but damn it is slow (I feared it would be) and only because of scriptclip since without it is pretty fast

New code:
Code:
function anv(clip c){
converttoPlanarRGB(c) #
S=ScriptClip(c,"""
    lum = converttorgb().invert().averageG
    rgb = converttorgb().RGBDifferenceFromPrevious
luma = int(lum + rgb)
ltr  = int(luma*0.00009)
ths  = int(luma*0.01)
    
p = convertbits(8).TemporalSoften(3,4,6,0,2).ex_levels(10,0.95,126)
SmDegrain(prefilter=p,tr=ltr,thsad=ths,DCT=1)
	#Subtitle("luma=" + String(ths) +","+ String(ltr), align=2)
""")
n = s.fft3dfilter(sigma=0.3,sigma2=0.4,sigma3=1.7,sigma4=2.1,plane=4,bt=1)
n = n.converttoyuv444()
n = n.vsCnr2(mode="ooo",ln=5,un=40,vn=40,sceneChroma=false)
n = n.neo_f3kdb(grainY=40,grainC=3,mt=true).tweak(sat=1.16)
return n
}

Last edited by anton_foy; 5th March 2022 at 14:44.
anton_foy is offline   Reply With Quote
Old 5th March 2022, 15:04   #18  |  Link
kedautinh12
Registered User
 
Join Date: Jan 2018
Posts: 2,156
You can try neo_fft3d, i think it's faster
kedautinh12 is offline   Reply With Quote
Old 5th March 2022, 15:41   #19  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Totally untested. [No idea what its supposed to be doing - my best guess at intended use]
[EDIT: Ignore this, methinks the later EDIT is as intended.]
Code:
Function anv(clip c){
    converttoPlanarRGB(c)           # Last is planar RGB, input bitdepth : ## c clip NOT used after here.
    rgbInvertC = invert()           # Inverted rgb, input depth
    Rgb8       = convertbits(8)     # planar RGB, 8 bit
    p          = Rgb8.TemporalSoften(3,4,6,0,2).ex_levels(10,0.95,126)    # SmDegrain Prefilter clip
    SSS = """
        lum  = rgbInvertC.averageG
        rgb  = RGBDifferenceFromPrevious # on last, ie planar RGB, input bitdepth
        luma = int(lum + rgb)
        ltr  = int(luma*0.00009)
        ths  = int(luma*0.01)
        SmDegrain(prefilter=p,tr=ltr,thsad=ths,DCT=1)           # Horrible, real slow call to SmDegrain at every frame.
        #Subtitle("luma=" + String(ths) +","+ String(ltr), align=2)
        return last
    """
    # ScriptClip: Input Last, ie PlanarRgb at input depth
    ScriptClip(Last,SSS,args="rgbInvertC,p",local=true)                     # NEEDS Grunt Plugin for Args.
    fft3dfilter(sigma=0.3,sigma2=0.4,sigma3=1.7,sigma4=2.1,plane=4,bt=1)
    converttoyuv444()
    vsCnr2(mode="ooo",ln=5,un=40,vn=40,sceneChroma=false)
    neo_f3kdb(grainY=40,grainC=3,mt=true).tweak(sat=1.16)
    return Last
}


__END__

# HERE old script. After above __END__ is not executed.


Function anv(clip c){
    converttoPlanarRGB(c) #
    # *** NOTE, NOT calling below scriptclip with planarRGB, is input clip c ***
    S=ScriptClip(c,"""
        lum = converttorgb().invert().averageG
        rgb = converttorgb().RGBDifferenceFromPrevious
        luma = int(lum + rgb)
        ltr  = int(luma*0.00009)
        ths  = int(luma*0.01)

        p = convertbits(8).TemporalSoften(3,4,6,0,2).ex_levels(10,0.95,126)
        SmDegrain(prefilter=p,tr=ltr,thsad=ths,DCT=1)
            #Subtitle("luma=" + String(ths) +","+ String(ltr), align=2)
    """)
    n = s.fft3dfilter(sigma=0.3,sigma2=0.4,sigma3=1.7,sigma4=2.1,plane=4,bt=1)
    n = n.converttoyuv444()
    n = n.vsCnr2(mode="ooo",ln=5,un=40,vn=40,sceneChroma=false)
    n = n.neo_f3kdb(grainY=40,grainC=3,mt=true).tweak(sat=1.16)
    return n
}
EDIT: SmDegrain called on input bitdepth planar RGB [ie Last], but with 8bit prefilter,
dont know if intended nor if works properley, I dont use SmDegrain.

EDIT:
On 2nd thoughts, maybe this as intended [again untested at all]
But p clip is 8 bits and function input clip c may not be, dont know if smdegrain will handle correctly. [maybe below in RED needs removal]
Code:
Function anv(clip c){
    InputPlanarRGB = converttoPlanarRGB(c)
    rgbInvertC     = InputPlanarRGB.invert()           # Inverted rgb, input depth
    p              = c.convertbits(8).TemporalSoften(3,4,6,0,2).ex_levels(10,0.95,126)    # SmDegrain Prefilter clip
    SSS = """
        lum  = rgbInvertC.averageG
        rgb  = InputPlanarRGB.RGBDifferenceFromPrevious # on planar RGB, input bitdepth
        luma = int(lum + rgb)
        ltr  = int(luma*0.00009)
        ths  = int(luma*0.01)
        SmDegrain(prefilter=p,tr=ltr,thsad=ths,DCT=1)           # Horrible, real slow call to SmDegrain at every frame.
        #Subtitle("luma=" + String(ths) +","+ String(ltr), align=2)
        return last
    """
    # ScriptClip: Input c, ie Input clip
    ScriptClip(c,SSS,args="rgbInvertC,p,InputPlanarRGB",local=true)                     # NEEDS Grunt Plugin for Args.
    fft3dfilter(sigma=0.3,sigma2=0.4,sigma3=1.7,sigma4=2.1,plane=4,bt=1)
    converttoyuv444()
    vsCnr2(mode="ooo",ln=5,un=40,vn=40,sceneChroma=false)
    neo_f3kdb(grainY=40,grainC=3,mt=true).tweak(sat=1.16)
    return Last
}
SmDegrain() in scriptclip will execute the smdegrain script code eg process default args and preparation code for every frame.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 5th March 2022 at 16:15.
StainlessS is offline   Reply With Quote
Old 5th March 2022, 16:16   #20  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
@StailessS
Thank you! I have to change to
Code:
rgb = converttorgb().RGBDifferenceFromPrevious
Since RGBDifferencefromPrevious needs packed RGB but then
SmDegrain get this again:
Code:
"MAnalyse: Clip must be YUV or YUY2 ...SmDegrain.avsi, line 294, line 345, line 634"
Quote:
No idea what its supposed to be doing
I found that a combo of averageG and RGBDifference gives me a pretty good estimation for how much denoising is needed (at least for my footage) so I feed those values (ltr, ths) to the parameters of SmDegrain to make it dynamic/automatic. In short auto denoise attempt.

@kedautinh12
Thanks but for me neo_fft3d is a bit slower than fft3dfilter at the same ncpu setting.

Last edited by anton_foy; 5th March 2022 at 16:19.
anton_foy 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 00:03.


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