Log in

View Full Version : Question about ApplyRange


Chainmax
31st December 2004, 20:23
I want to use FunkyDeblock() on certain frames of a clip. Should the call line be ApplyRange (Startframe,Endframe,"FunkyDeblock",()) ? If not, then I guess the correct call would be ApplyRange (Startframe,Endframe,"FunkyDeblock"), would that slow down the encoding due to not using the parenthesis?

stickboy
31st December 2004, 20:59
Originally posted by Chainmax
I want to use FunkyDeblock() on certain frames of a clip. Should the call line be ApplyRange (Startframe,Endframe,"FunkyDeblock",()) ?No, that would be a syntax error. () is not an argument.
If not, then I guess the correct call would be ApplyRange (Startframe,Endframe,"FunkyDeblock"), would that slow down the encoding due to not using the parenthesis?I don't think it will matter.

stickboy
31st December 2004, 21:31
Okay, I take that back. I'm surprised that the parenthesis quirk is still a problem (and I'm still puzzled at how it affects speed at all).

I tried:AVISource("someClip.avi", pixel_type="yuy2")
MipSmooth
MipSmooth
MipSmoothloaded it in VirtualDub, did a fast-recompress to Huffyuv, and got a render rate of ~0.5 fps on my system.

With the parentheses, I got a render rate of ~5 fps.

Okay, so back to the original topic:
FWIW, with or without arguments, my JDL_ApplyRange function seems to do about 20% better than the internal ApplyRange function on my box. YMMV.

Edit:
Also, if you need to apply multiple filters to the same range, JDL_ApplyRange appears to beat the pants off of ApplyRange:
JDL_ApplyRange(0, FrameCount() - 1, "MipSmooth().MipSmooth().MipSmooth()")trounces
ApplyRange(0, FrameCount() - 1, "MipSmooth")
ApplyRange(0, FrameCount() - 1, "MipSmooth")
ApplyRange(0, FrameCount() - 1, "MipSmooth")and even

function Foo(clip c, int unused)
{
return c.MipSmooth().MipSmooth().MipSmooth()
}

ApplyRange(0, FrameCount() - 1, "Foo", 0)

stickboy
31st December 2004, 22:13
Bah, I take that back too!

I tried using SSIQ instead of MipSmooth, and I didn't see any different in rendering times with or without parentheses nor between ApplyRange and JDL_ApplyRange.

Perhaps this funny business is filter-specific. MipSmooth seems to be having strangely; I expect that:Subtract(MipSmooth(), ApplyRange(0, FrameCount() - 1, "MipSmooth"))
Levels(117, 1.0, 137, 0, 255)
would give me totally gray frames, but it doesn't. (A similar thing happens with JDL_ApplyRange.) Maybe MipSmooth doesn't like being called multiple times? Beats me. (Doesn't happen when MipSmooth is given presets, though.)

Sorry to derail your thread. :)

Chainmax
31st December 2004, 23:18
So, what should I do then? You have managed to confuse me :confused: Not that it's a difficult thing to do though :o :P.

stickboy
31st December 2004, 23:56
You should run your own test and see which works faster for you for the filters you want to use.

Chainmax
1st January 2005, 05:20
I wasn't asking about the speed as I will do the tests myself, I was asking wether () was useable as a parameter for ApplyRange.

stickboy
1st January 2005, 05:43
Originally posted by Chainmax
I wasn't asking about the speed as I will do the tests myself, I was asking wether () was useable as a parameter for ApplyRange.And I already said no. It's invalid syntax. () is not an argument.
ApplyRange(Startframe,Endframe,"FunkyDeblock",())is the same asApplyRange(Startframe,Endframe,"FunkyDeblock",)For a long while, ApplyRange didn't even work at all with argument-less filters.

(Sorry if I wasn't clear all my "I take that back"s. I was talking only about the performance quirk.)

Chainmax
1st January 2005, 18:25
Originally posted by stickboy
ApplyRange(Startframe,Endframe,"FunkyDeblock",)

Typo spotting skills +1 :P :)
Seriously though, thanks for clearing that up. I hope it works with either ApplyRange or JDL_ApplyRange :).

canuckerfan
15th May 2007, 00:12
I didn't want to open another thread so I'll just post my question here...

if I have applyrange() called ~950 times in a script will it render those 950 lines every time the video moves forward a frame OR does applyrange simply execute those commands for the specified frames and then continuing moving the video forward without re-rendering?

I ask this because i've hit a snag with my script. its dreadfully slow with that many applyrange commands...

IanB
15th May 2007, 01:39
ApplyRange is really just Animate under the covers. So it will "compile" the "ranged function" on demand.

Use some technology (ConditionalReader, JDL utilities, etc) that doesn't continually compile segments of your script at runtime. The included online help files have specific examples about this problem conditionalreader.htm#ApplyRange (file:///C:/Program Files/AviSynth 2.5/Docs/english/corefilters/conditionalreader.htm#ApplyRange)

canuckerfan
15th May 2007, 03:56
^that link doesn't work for me.... is it supposed to be clickable?

IanB
15th May 2007, 07:32
No! It's a hint to go and look at the help files on your hard disk. RTFM!

ChiDragon
15th May 2007, 07:32
It's a link to a file on your computer, and not the default install path either... Try this (file:///C:/Program%20Files/AviSynth%202.5/Docs/english/corefilters/conditionalreader.htm#ApplyRange) or find the file manually in your AviSynth install dir. (middle-clicking in Firefox doesn't seem to work with it though)

EDIT: Posted at the same time as IanB's response...

canuckerfan
30th May 2007, 09:50
sorry, I should've caught that.

I've tried using conditional reader + scriptclip with marginal success. This is what I have so far

function hq_filter(clip c)
{
c=c.RemoveNoiseMC(rdlimit=6,rgrain=1,denoise=0,sharp=true)
# c=c.LimitedSharpenFaster(Smode=4,strength=18,overshoot=0,wide=false,ss_x=1.3,ss_y=1.3)
return c
}

ScriptClip("hq_filter()")
ConditionalReader("File.txt","myvar",false)

contents of "File.txt" are

Type bool
Default true

833 true
1199 true
1209 true
1215 true
1218 true
1241 true
1249 true
1270 true

The script works without errors. However, hq_filter is applied to all the frames, not the ones specified in File.txt. I'm missing something critical, I know it. Any help is greatly appreciated. thanks.

Leak
30th May 2007, 12:35
function hq_filter(clip c)
{
c=c.RemoveNoiseMC(rdlimit=6,rgrain=1,denoise=0,sharp=true)
# c=c.LimitedSharpenFaster(Smode=4,strength=18,overshoot=0,wide=false,ss_x=1.3,ss_y=1.3)
return c
}

ScriptClip("hq_filter()")
ConditionalReader("File.txt","myvar",false)
You're not using myvar in your hq_filter function, so what did you think would happen?

Try
c=(myvar ? c.RemoveNoiseMC(...) : c)
up there.

Type bool
Default true

833 true
1199 true
1209 true
1215 true
1218 true
1241 true
1249 true
1270 true
The way you wrote that means myvar will be true by default, and it will be set to true for the frames you listed below - which doesn't change anything, of course...

Either use "Default false", or use "false" in your list.

Also, you might want to consider replacing "myvar" with a better name. Oh, and did you know that ConditionalReader has it's own dedicated page in the AviSynth docs, along with several examples? You might want to read that sometime... :D

canuckerfan
30th May 2007, 20:15
^thanks, Leak. your suggestions worked:)

canuckerfan
1st August 2007, 02:50
hmmm.... i've run into a big of a snag here. i've got a script in which im processing roughly 1257 frames via conditionalreader (File_A.txt has 1257 frames selected for processing). here's my script:

setmemorymax(512)

function hq_filter(clip c)
{
c=(ABC ? c.RemoveNoiseMC(rdlimit=17,rgrain=1,denoise=0,sharp=true) : c)
return c
}

AVISource("G:\final_A.avi")
ScriptClip("hq_filter()")
ConditionalReader("File_A.txt","ABC",false)

but when I pop this script into xvid via megui. it just grinds to a halt. it starts off REAL slow at around .25 fps and then just quits. I tried using lagarith via avsp and the same thing happens. does conditionalreader have a limit to the number of frames it can process or am I doing something wrong? any help is appreciated. thanks

IanB
1st August 2007, 03:07
Don't scriptclip the RemoveNoiseMC, scriptclip only the decision....
AVISource("G:\final_A.avi")
Filtered = RemoveNoiseMC(rdlimit=17,rgrain=1,denoise=0,sharp=true)
ScriptClip("ABC ? Filtered : Last")
ConditionalReader("File_A.txt","ABC",false)All these animate/applyrange/scriptclip type funtions compile a piece of script every frame. Don't do anything slow to compile or resource intensive in the conditional part. Do the slow part once and select the appropriate clip in the conditional.

EuropeanMan
16th July 2008, 21:43
I've run into a snag...using CR...

I have a dvd that i'm trying to fix cropping in many many areas into an x264 codec file...

so basically I have 23 regions where cropping is different...

I've named my file: ranges.txt


Type int
Default 2 50 -2 -50

R 0 6532 2 52 -2 -60
R 6533 18546 2 52 -2 50
R 18547 24395 2 58 -2 -56
R 24396 82208 2 52 -2 -52
R 82209 83155 2 50 -2 -60
R 83156 85565 2 50 -2 -50
R 85566 87457 2 50 -2 -60
R 87458 98309 2 50 -2 -50


That is just an example...of some ranges

The last 4 numbers above are the cropping values for those ranges...


ScriptClip("crop(string(a),string(b),string(c),string(d))")
ConditionalReader("c:\users\farooq\desktop\ranges.txt", "a", "b", "c", "d", false)


{this is what i am trying above to no avail...error: invalid ranges to conditional reader}

How would I call this in my .avs script?

EuropeanMan
16th July 2008, 22:12
Ok...I've changed my ranges file to ONLY include the top cropping value

when i change my scriptclip line to ("crop(0,a,0,-26)")
conditionalreader("c:\users\farooq\desktop\ranges.txt", "a", false)

the error NOW says

ScriptClip: Function did not return a video clip with the same height as source clip!

What am I doing wrong...grrrr

IanB
16th July 2008, 23:33
@EuropeanMan,

I will take this as an enhancement request to handle multiple variables in 1 file.

Currently ConditionalReader does not handle strings and only parses 1 variable.


You would need multiple reader calls, like this :-ScriptClip("crop(a, b, c, d)")
ConditionalReader("c:\users\farooq\desktop\ranges A.txt", "a", false)
ConditionalReader("c:\users\farooq\desktop\ranges B.txt", "b", false)
ConditionalReader("c:\users\farooq\desktop\ranges C.txt", "c", false)
ConditionalReader("c:\users\farooq\desktop\ranges D.txt", "d", false)ranges B.txt would be this, the other files similarType int
Default 50

R 0 6532 52
R 6533 18546 52
R 18547 24395 58
R 24396 82208 52Of course as the resulting frame sizes are all different, it is not going to work as it is.

You are going to need to resize each segment to a single standard size. An option is to use the crop options on a resizer thus :-...
ScriptClip("Spline16Resize(720, 576, a, b, c, d)") # But this is an expensive thing to do!

ConditionalReader("c:\users\farooq\desktop\ranges A.txt", "a", false)
ConditionalReader("c:\users\farooq\desktop\ranges B.txt", "b", false)
ConditionalReader("c:\users\farooq\desktop\ranges C.txt", "c", false)
ConditionalReader("c:\users\farooq\desktop\ranges D.txt", "d", false)But as I said in previous posts do not ScriptClip anything expensive to compile, just ScriptClip a decision!

So you want something like this :-...
V0=Spline16Resize(720, 576, 2 50 -2 -50)
V1=Spline16Resize(720, 576, 2 50 -2 -60)
V2=Spline16Resize(720, 576, 2 52 -2 -50)
V3=Spline16Resize(720, 576, 2 52 -2 -52)
V4=Spline16Resize(720, 576, 2 52 -2 -60)
V5=Spline16Resize(720, 576, 2 58 -2 -56)

ScriptClip("Select(VarS, V0, V1, V2, V3, V4, V5")

ConditionalReader("c:\users\farooq\desktop\ranges I.txt", "VarS", false)And "ranges I.text" contains indexes to the preselected resizer clips.Type int
Default 0

R 0 6532 4
R 6533 18546 2
R 18547 24395 5
R 24396 82208 3
R 82209 83155 1
R 83156 85565 0
R 85566 87457 1
R 87458 98309 0

EuropeanMan
17th July 2008, 00:00
(shocked) wow....

i just realised a different solution as well...on my own...it seems to work...

a=last
b=a.trim(0,6532).crop(2,52,-2,-60).spline36resize(624,272)
c=a.trim(6533,18546).crop(2,52,-2,-50).spline36resize(624,272)
d=a.trim(18547,24395).crop(2,58,-2,-56).spline36resize(624,272)
e=
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v


b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+u+v
-------------

what do you think?

Gavino
17th July 2008, 00:37
I will take this as an enhancement request to handle multiple variables in 1 file.
Currently ConditionalReader does not handle strings and only parses 1 variable.

Strangely, I was thinking just yesterday of adding a multiple-variable, string-handling ConditionalReader to my GRunT plugin. But if you're going to do it anyway, perhaps there's no need.

You would need multiple reader calls, like this :-ScriptClip("crop(string(a),string(b),string(c),string(d))")
ConditionalReader("c:\users\farooq\desktop\ranges A.txt", "a", false)
...

In fact it would have been
ScriptClip("crop(a, b, c, d)")
(crop takes ints, not strings!) but as you say the design was wrong anyway 'cos you can't have a clip with frames of different sizes.

Gavino
17th July 2008, 00:52
b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+u+v
-------------
what do you think?
It will work, and in fact if all 21 clips have different crop values, you can't do much better.(*)

If there is only a smaller number of combinations, with repetitions, then I prefer IanB's solution as it's probably more flexible and less resource-intensive, eg 6 instantiations of Spline36Resize instead of 21.

Ed. (*) though you could tidy it up by packaging the trim+crop+resize into a function of your own.

EuropeanMan
17th July 2008, 00:55
my solution above worked...now I think what I'll do is resize to 720,480 and have all my other filters process on those and then at the end resize to my desired size :) thanks all for the help...

i ended up having 35 different crop values...yes, the DVD9 was horribly framed :(

@Gavino - any help on that function? would appreciate it...thanks

Gavino
17th July 2008, 01:53
@Gavino - any help on that function? would appreciate it...thanks

function f(clip c, int start, int end, int left, int top, int right, int bottom, int "w", int "h") {
w = Default(w, 624) # amend to suit
h = Default(h, 272) # and here
Trim(c, start, end)
Spline36Resize(w, h, left, top, -right, -bottom)
}
...
a = last
b = a.f(0, 6532, 2, 52, 2, 60)
c = a.f(...)
etc

I've combined the Crop with the resize here. Note that I've defined it so that you pass only positive numbers to the function, the -ve sign for right and bottom is applied inside.

I'm sure you can think of a better name than 'f' :), but it's late on our continent and I'm off to sleep...

EuropeanMan
18th July 2008, 06:30
Gavino - just wanted to say thanks :)

EuropeanMan
23rd July 2008, 04:10
function f(clip c, int start, int end, int left, int top, int right, int bottom, int "w", int "h") {
w = Default(w, 624) # amend to suit
h = Default(h, 272) # and here
Trim(c, start, end)
Spline36Resize(w, h, left, top, -right, -bottom)
}
...
a = last
b = a.f(0, 6532, 2, 52, 2, 60)
c = a.f(...)
etc

I've combined the Crop with the resize here. Note that I've defined it so that you pass only positive numbers to the function, the -ve sign for right and bottom is applied inside.

I'm sure you can think of a better name than 'f' :), but it's late on our continent and I'm off to sleep...

for SOME odd reason, i tried your function as is...and it crashed MeGUI & VDM!!! don't know why it didn't work...

i ended up using:


a=last
b=a.trim(0,5449).crop(2,50,-2,-60).spline36resize(688,304)
c=a.trim(5450,15470).crop( 2,52,-2,-52).spline36resize(688,304)
d=a.trim(15471,20346).crop( 2,58,-2,-54).spline36resize(688,304)
e=a.trim(20347,68576).crop( 2,50,-2,-52).spline36resize(688,304)
f=a.trim(68577,69365).crop( 2,50,-2,-60).spline36resize(688,304)
g=a.trim(69366,71376).crop( 2,50,-2,-50).spline36resize(688,304)
h=a.trim(71377,72954).crop( 2,50,-2,-62).spline36resize(688,304)
i=a.trim(72955,76465).crop( 2,50,-2,-54).spline36resize(688,304)
i2=a.trim(76466,76536).crop( 2,50,-2,-62).spline36resize(688,304)
i3=a.trim(76537,82006).crop( 2,50,-2,-52).spline36resize(688,304)
j=a.trim(82007,84244).crop( 2,50,-2,-62).spline36resize(688,304)
k=a.trim(84245,91270).crop(2,50,-2,-54).spline36resize(688,304)
l=a.trim(91271,91579).crop(2,50,-2,-62).spline36resize(688,304)
m=a.trim(91580,106389).crop(2,50,-2,-52).spline36resize(688,304)
n=a.trim(106390,106899).crop(2,50,-2,-62).spline36resize(688,304)
o=a.trim(106900,107855).crop(2,52,-2,-52).spline36resize(688,304)
p=a.trim(107856,113502).crop(2,52,-2,-60).spline36resize(688,304)
q=a.trim(113503,127049).crop(2,48,-2,-52).spline36resize(688,304)
q1=a.trim(127050,127249).crop(2,52,-2,-60).spline36resize(688,304)
q2=a.trim(127250,133835).crop(2,50,-2,-54).spline36resize(688,304)
r=a.trim(133836,134293).crop(2,56,-2,-58).spline36resize(688,304)
s=a.trim(134294,138546).crop(2,50,-2,-54).spline36resize(688,304)
s1=a.trim(138547,138648).crop(2,56,-2,-58).spline36resize(688,304)
s2=a.trim(138649,138705).crop(2,50,-2,-52).spline36resize(688,304)
s3=a.trim(138706,138771).crop(2,56,-2,-56).spline36resize(688,304)
s4=a.trim(138772,138855).crop(2,50,-2,-52).spline36resize(688,304)
s7=a.trim(138856,138969).crop(2,56,-2,-58).spline36resize(688,304)
s8=a.trim(138970,150684).crop(2,52,-2,-50).spline36resize(688,304)
s5=a.trim(150685,150841).crop(2,52,-2,-58).spline36resize(688,304)
s6=a.trim(150842,151764).crop(2,50,-2,-50).spline36resize(688,304)
t=a.trim(151765,152082).crop(2,50,-2,-60).spline36resize(688,304)
u=a.trim(152083,152786).crop(2,50,-2,-52).spline36resize(688,304)
v=a.trim(152787,153020).crop(2,50,-2,-62).spline36resize(688,304)
w=a.trim(153021,217985).crop(2,52,-2,-50).spline36resize(688,304)
x=a.trim(217986,222123).crop(2,50,-2,-60).spline36resize(688,304)

b+c+d+e+f+g+h+i+i2+i3+j+k+l+m+n+o+p+q+q1+q2+r+s+s1+s2+s3+s4+s7+s8+s5+s6+t+u+v+w+x


I'd really love to learn why that function didn't work...

I did all deinterlacing & heavy filtering before applying the above...
results turned out great i felt

http://maxupload.com/img/62FB1D2F.png
http://maxupload.com/img/4AD4B9F5.png
http://maxupload.com/img/4642BD05.png
http://maxupload.com/img/B1C0E5EE.png
http://maxupload.com/img/EA69A134.png
http://maxupload.com/img/50058FBB.png
http://maxupload.com/img/DF71F0C9.png
http://maxupload.com/img/86942E61.png

So NOW I will have to figure out HOW I can run a CCE...

After the above, would it be WISE to use:

AddBorders(0,XX,0,XX)
Lanczos4Resize(720,480)

? or what do you suggest...

Gavino
23rd July 2008, 08:39
for SOME odd reason, i tried your function as is...and it crashed MeGUI & VDM!!! don't know why it didn't work...
i ended up using:

a=last
b=a.trim(0,5449).crop(2,50,-2,-60).spline36resize(688,304)
c=a.trim(5450,15470).crop( 2,52,-2,-52).spline36resize(688,304)
...
b+c+d+e+f+g+h+i+i2+i3+j+k+l+m+n+o+p+q+q1+q2+r+s+s1+s2+s3+s4+s7+s8+s5+s6+t+u+v+w+x

I'd really love to learn why that function didn't work...

So would I ;)
When you say crashed, did you get any specific error message?
Did you call it exactly as I described (no minus signs)?
I see in your final version you are resizing to 688x304. For that you would have needed to change the defaults for w and h inside the function (or pass them explicitly as extra parameters).
What happens if you change it to:
function f(clip c, int start, int end, int left, int top, int right, int bottom, int "w", int "h") {
w = Default(w, 688) # amend to suit
h = Default(h, 304) # and here
Trim(c, start, end)
# Spline36Resize(w, h, left, top, -right, -bottom) replaced by:
Crop(left, top, -right, -bottom)
Spline36Resize(w, h)
}
which is directly equivalent to your script.

Alex_ander
23rd July 2008, 10:38
Can there be a conflict between variables 'c' in function definition and in the processed 'c' video cut?

Gavino
23rd July 2008, 20:31
@Alex_ander.

No - function parameters and any variables assigned in the function are purely local and exist in a separate namespace from script-level variables.