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 4th September 2003, 15:19   #1  |  Link
primitive
Registered User
 
Join Date: Mar 2002
Posts: 130
array type and for loop in avisynth?

Greetings all. I'm working on an Avisynth script to use in my anime encodes and I was wondering if there was an array type or a for loop-like expression in Avisynth. I didn't find any mention of either in the documentation, but since I read somewhere in this forum that the documentation often lagged behind the reality I thought I'd ask.
__________________
xvid + vorbis + ogm = dance all night
primitive is offline   Reply With Quote
Old 4th September 2003, 17:39   #2  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
AviSynth 2.5x and earlier have no array type or explicit looping expression. If you need a loop, you usually can use a recursive function instead.

Exactly what do you want to do?
stickboy is offline   Reply With Quote
Old 4th September 2003, 20:29   #3  |  Link
primitive
Registered User
 
Join Date: Mar 2002
Posts: 130
I'm writing a function that iterates over a clip, performs an operation on each frame, and uses the results to create a metric. I want the number of samples it takes from the clip in question to be user-defined. This means that I need something to hold the values for me while the script takes a look at each frame in the clip. It's nonsense for me to use variables like this:

Code:
s1 =
s2 =
s3 =
...
s128 =
because I can never be sure what the user is going to give for the number of desired samples. More important than the for loop is the array class, because even if I iterated over a series of frames I wouldn't have any place to put the values.
__________________
xvid + vorbis + ogm = dance all night
primitive is offline   Reply With Quote
Old 5th September 2003, 05:32   #4  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
Well, if you really want to, you could use strings as a poor-man's array.

First you'd write a recursive function with a string as its accumulator; something of the form:
Code:
# given an input n, this returns a string "1,2,...,n,"
function foo(int n, string "s")
{
    s = default(s, "")
    return (n > 0) ? foo(n - 1, String(n) + "," + s)
    \              : s
}
And then you could parse this string with another function:
Code:
# given a string "a0,a1,...,aN,", where a0,...,aN are numbers,
# this returns a0+a1+...+aN
function bar(string s, float "acc")
{
    acc = default(acc, 0.0)
    offset = FindStr(s, ",")
    # FindStr returns 0 if not found
    return (offset == 0) ? acc
    \                    : bar(MidStr(s, offset + 1),
    \                          acc + Value(LeftStr(s, offset - 1)))
}

# example usage
MessageClip(String(bar(foo(5))))

Last edited by stickboy; 5th September 2003 at 06:08.
stickboy is offline   Reply With Quote
Old 5th September 2003, 07:24   #5  |  Link
primitive
Registered User
 
Join Date: Mar 2002
Posts: 130
Wow, that's a neat trick that I never thought of, but sweet jesus is it ever a hack

Thanks!

-p
__________________
xvid + vorbis + ogm = dance all night
primitive is offline   Reply With Quote
Old 5th September 2003, 18:22   #6  |  Link
oof
Registered User
 
Join Date: Jul 2003
Location: Uranus
Posts: 44
stickboy
You appear to be quite good at this and seem to enjoy
good puzzles.
I have one I've been trying to do for a long time. I finaly
cheated and used Unix AWK on it but I'd like an Avisynth script

I sometimes get videos with a duplicate frame every so often.
I want to eliminate one of the duplicate frames in each instance.
If there was a looping structure, I think I could do it.

Compare() doesnt seem to return anything - just makes a logfile
Conditional Filter or Script Clip look promising.

I think a recursive function that increments a frame number and uses DeleteFrame(n) might be close.

You have any tricky ideas ?
oof is offline   Reply With Quote
Old 5th September 2003, 18:45   #7  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
How do you detect the duplicate frames? Do they occur on regular intervals?

What does your awk script look like? If AviSynth had an explicit iterative looping construct, what would your script look like?
stickboy is offline   Reply With Quote
Old 5th September 2003, 19:25   #8  |  Link
oof
Registered User
 
Join Date: Jul 2003
Location: Uranus
Posts: 44
The Kluge consists of writing a compare log to a file with:

avisource( "movie.avi" )
v2 = trim( last, 1,0 )
Compare(last, v2, "", "compare.log", true)

then run AWK
$2 == 0 {print "DeleteFrame( " $1 " )" "\r" }

now we have another AVS which deletes all the desired frames.


If it was C I would write

output( Frame[ FIRST_FRAME ] ) ;
for( i = FIRST_FRAME + 1 ; i <= LAST_FRAME ; i++ )
{ if( Frame[ i ] != Frame[ i - 1 ] )
output( Frame[ i ] ;
/* Else skip this one */
}
oof is offline   Reply With Quote
Old 5th September 2003, 21:55   #9  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
No, idea what the smartest way is. Maybe the following works:

1) subtract frame j and j+1
2) if averageluma of the resulting frame is close to 128 (check that by using ScriptClip) => delete that frame
Wilbert is offline   Reply With Quote
Old 5th September 2003, 22:34   #10  |  Link
oof
Registered User
 
Join Date: Jul 2003
Location: Uranus
Posts: 44
This is a nasty one. DeleteFrame reqires a frame number.
What if you delete frame N ? How are they numbered after that ?
I deleted them High numbers first to avoid that.

Another problem with the Kluge method is that the first AVS that
does the compare won't execute on all frames unless you frames serve to something that reads all the frames. The only thing I could think of
was play it in Vdub. That takes 2 hours if it's a 2 hour movie.
If I had /dev/null I could send it there as an AVI, does window have a
null file ?
Anybody know of a frameclient that requests frames as fast as it can
go ? Another AVS might do.

I don't really NEED to do this, I just want to solve the puzzle.
oof is offline   Reply With Quote
Old 6th September 2003, 06:12   #11  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
Hmmm... I need to think about this for a while.
stickboy 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 18:15.


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