Publisher
Joined: 4/23/2009
Posts: 1283
arkiandruski wrote:
I've made a few changes based off the errors that I'm getting, but now I'm getting a new error message that stumps me.(I'm trying to learn the logic of the program. It seems that variables don't persist outside of functions here. Am I correct?) "Avisynth open failure: "Script error:Invalid arguments to function "showFrameDiff" "(C:\Users\filepath.avs, line 61)" http://pastebin.com/fRSHJxqx If anyone can find a more elegant solution, please let me know. What I'm trying to do is write a function that keeps track of frames saved, so all the user of the script has to do is input frame numbers. I'm almost definitely not the best person to do this, but at least I'm willing to try, right?
That's correct. Variables in a function are called local variables that are only inside that function. What you want is to create a global variable. Read about it here: http://avisynth.org/mediawiki/Script_variables
Reviewer, Active player (277)
Joined: 12/14/2006
Posts: 717
Can anyone tell me where my invalid argument is? I changed FrameDiff to a global variable and I still got that error message. The line being referred to is my subtitle line.
Publisher
Joined: 4/23/2009
Posts: 1283
arkiandruski wrote:
Can anyone tell me where my invalid argument is? I changed FrameDiff to a global variable and I still got that error message. The line being referred to is my subtitle line.
You would need to post the script with your changes, but I suspect the problem is you didn't define the global variable outside of the function. It might also need to be before the function is defined.
Reviewer, Active player (277)
Joined: 12/14/2006
Posts: 717
Okay, so if I define a global variable outside a function and then change it within a function, the change will be permanent, right? That pastebin link has my new code. Everyone else was using the site, so I figured that was the goto place for these kind of things.
Publisher
Joined: 4/23/2009
Posts: 1283
arkiandruski wrote:
Okay, so if I define a global variable outside a function and then change it within a function, the change will be permanent, right? That pastebin link has my new code. Everyone else was using the site, so I figured that was the goto place for these kind of things.
Yes, that's the point of a global. Whoever changes it it will stay like that.
Reviewer, Active player (277)
Joined: 12/14/2006
Posts: 717
I've made a large leap forward! I have video now! http://www.mediafire.com/?7l9q2gso1b84ogx It's still not right, though. There's no audio and it only plays the last section of everything I've written down. Here's the script I used to make this video.
function formatTime(int ms) { s = ms / 1000 ms = ms % 1000 m = s / 60 s = s % 60 h = m / 60 m = m % 60 return String(m,"%02.0f") + ":" + String(s,"%02.0f") + "." + String(ms,"%03.0f") } function addBlankClip(clip a, clip b) { max = Max(a.FrameCount, b.FrameCount) result = (a.FrameCount != max) ? (a + BlankClip(a, length=max- a.FrameCount)).FreezeFrame(a.FrameCount, max - 1, a.FrameCount - 1) : a return result } function showFrameDiff (clip a, clip b){ frameGain = (a.FrameCount - b.FrameCount) FrameDiff = (FrameDiff + frameGain) return FrameDiff } global FrameDiff = 0 a = AVISource("jackicgunstar.avi").AddBorders(2,20,2,20).Subtitle("Jackic", align=2, text_color=$00FFFFFF) b = AVISource("arkiandruskigunstar.avi").AddBorders(2,20,2,20).Subtitle("arkiandruski", align=2, text_color=$00FFFFFF) c = a.ScriptClip("""Subtitle("Frame: " + String(current_frame) + "\nTime: " + formatTime(Round(float(current_frame * 1000) * float(a.FrameRateDenominator) / float(a.FrameRateNumerator))), text_color=$00FFFFFF, lsp=1, size=10.0)""") d = b.ScriptClip("""Subtitle("Frame: " + String(current_frame) + "\nTime: " + formatTime(Round(float(current_frame * 1000) * float(b.FrameRateDenominator) / float(b.FrameRateNumerator))), text_color=$00FFFFFF, lsp=1, size=10.0)""") e = c.trim(0, 787) f = d.trim(0, 985) g = addBlankClip(e, f) h = addBlankClip(f, e) i = showFrameDiff (e, f) e = c.trim(788, 1685) f = d.trim(986, 2036) g = addBlankClip(e, f) h = addBlankClip(f, e) i = showFrameDiff (e, f) e = c.trim(1686, 2129) f = d.trim(2037, 2299) g = addBlankClip(e, f) h = addBlankClip(f, e) i = showFrameDiff (e, f) e = c.trim(2130, 3054) f = d.trim(2300, 3354) g = addBlankClip(e, f) h = addBlankClip(f, e) i = showFrameDiff (e, f) e = c.trim(3055, 4349) f = d.trim(3355, 4555) g = addBlankClip(e, f) h = addBlankClip(f, e) i = showFrameDiff (e, f) e = c.trim(4350, 7494) f = d.trim(4556, 7536) g = addBlankClip(e, f) h = addBlankClip(f, e) i = showFrameDiff (e, f) e = c.trim(7495, 8591) f = d.trim(7537, 8509) g = addBlankClip(e, f) h = addBlankClip(f, e) i = showFrameDiff (e, f) e = c.trim(8592, 9801) f = d.trim(8510, 9719) g = addBlankClip(e, f) h = addBlankClip(f, e) i = showFrameDiff (e, f) m = StackHorizontal(e, f) n = MixAudio(e, f, 1.0, 0.0) last = AudioDub(m, n) trim(0, 75009) Subtitle("Frames Gained:" + String(FrameDiff, "%05.0f"), align=2, size=15) ConvertToYV24(matrix="PC.601", chromaresample="point") ConvertToYV12(matrix="PC.601", chromaresample="lanczos4") return last
EDIT: I've figured out the audio issue. Now my video has sound! (but not the one I posted)
creaothceann
He/Him
Editor
Joined: 4/7/2005
Posts: 1874
Location: Germany
Don't know what the problem is, but... lots of one-letter variables are bad.
global FrameDiff = 0
global last_a    = BlankClip(0)
global last_b    = BlankClip(0)


a = Open(      "jackicgunstar.avi", "Jackic"      )
b = Open("arkiandruskigunstar.avi", "arkiandruski")

AddFrameDiff(a.Trim(   0,  787), b.Trim(   0,  985))
AddFrameDiff(a.Trim( 788, 1685), b.Trim( 986, 2036))
AddFrameDiff(a.Trim(1686, 2129), b.Trim(2037, 2299))
AddFrameDiff(a.Trim(2130, 3054), b.Trim(2300, 3354))
AddFrameDiff(a.Trim(3055, 4349), b.Trim(3355, 4555))
AddFrameDiff(a.Trim(4350, 7494), b.Trim(4556, 7536))
AddFrameDiff(a.Trim(7495, 8591), b.Trim(7537, 8509))
AddFrameDiff(a.Trim(8592, 9801), b.Trim(8510, 9719))

AudioDub(StackHorizontal(last_a, last_b), MixAudio(last_a, last_b, 1.0, 0.0))
Trim(0, 75009)
Subtitle("Frames gained: " + String(FrameDiff, "%05.0f"), align=2, size=15)
ConvertToYV24(matrix="PC.601", chromaresample="point"   )
ConvertToYV12(matrix="PC.601", chromaresample="lanczos4")




function AddBlankClip(clip a, clip b)  {
        m = Max(a.FrameCount, b.FrameCount)
        result1 = a + BlankClip(a, length=m - a.FrameCount).FreezeFrame(a.FrameCount, m - 1, a.FrameCount - 1)
        result2 = a
        return (a.FrameCount != m)  ?  result1  :  result2
}


function AddFrameDiff(clip a, clip b)  {
        last_a = a
        last_b = b
        FrameDiff = FrameDiff + (a.FrameCount - b.FrameCount)
        return FrameDiff
}


function FormatTime(int ms)  {
        s  = ms / 1000
        ms = ms % 1000
        m  = s  / 60
        s  = s  % 60
        h  = m  / 60
        m  = m  % 60
        return String(m, "%02.0f") + ":" + String(s, "%02.0f") + "." + String(ms, "%03.0f")
}


function Open(string FileName, string Title)  {
        AVISource(FileName)
        AddBorders(2, 20, 2, 20)
        Subtitle(Title, align=2, text_color=$00FFFFFF)
        ScriptClip("""Subtitle("Frame: " + String(current_frame) + "\nTime: " + FormatTime(Round(Float(current_frame * 1000) * Float(FrameRateDenominator) / Float(FrameRateNumerator))), text_color=$00FFFFFF, lsp=1, size=10.0)""")
}
Reviewer, Active player (277)
Joined: 12/14/2006
Posts: 717
When I tried to open that code, I got a movie file that's zero frames long. The code looks like it never pulls up the clips or uses the blank clip function.
creaothceann
He/Him
Editor
Joined: 4/7/2005
Posts: 1874
Location: Germany
arkiandruski wrote:
The code looks like it never pulls up the clips
I didn't really test the code, just restructured it. Anyway, that's what last_a and last_b are for.
arkiandruski wrote:
or uses the blank clip function
Well, your code never uses g and h.
Reviewer, Active player (277)
Joined: 12/14/2006
Posts: 717
EDIT: Nevermind, figured it out. I have a video now. The problem is the FrameDiff variable isn't updating. This is because the entire video is dumped at once, which apparently doesn't give FrameDiff a chance. I'm going to mess around a bit with this code to see if I can't get it to work. It's not going to be pretty. Just telling you, but cleaning is for later. I'd rather have something sloppy that works.
Reviewer, Active player (277)
Joined: 12/14/2006
Posts: 717
http://www.mediafire.com/?5cizveg2zb7fqmp I found a solution. Like I said before. It's not elegant, but we can spruce it up a bit and make it shine. I found out a few things while doing this. Functions can't return more than one variable. You can't change global variables within functions. The downside to this script is you have to keep track of which v value you're on. The upside is it's still much easier than trying to do the math yourself (especially with copy paste).
a = Open( "jackicgunstar.avi", "Jackic" ) b = Open("arkiandruskigunstar.avi", "arkiandruski") v = 0 old = a.Trim(0, 787) new = b.Trim(0, 985) final = Format (old, new, v) v1 = v + AddFrameDiff (old, new) old = a.Trim(788, 1685) new = b.Trim(986, 2036) final = final + Format (old, new, v1) v2 = v1 + AddFrameDiff (old, new) old = a.Trim(1686, 2129) new = b.Trim(2037, 2299) final = final + Format (old, new, v2) v3 = v2 + AddFrameDiff (old, new) old = a.Trim(2130, 3054) new = b.Trim(2300, 3354) final = final + Format (old, new, v3) v4 = v3 + AddFrameDiff (old, new) old = a.Trim(3055, 4349) new = b.Trim(3355, 4555) final = final + Format (old, new, v4) v5 = v4 + AddFrameDiff (old, new) old = a.Trim(4350, 7494) new = b.Trim(4556, 7536) final = final + Format (old, new, v5) v6 = v5 + AddFrameDiff (old, new) old = a.Trim(7495, 8590) new = b.Trim(7537, 8508) final = final + Format (old, new, v6) v7 = v6 + AddFrameDiff (old, new) old = a.Trim(8591, 9801) new = b.Trim(8509, 9719) final = final + Format (old, new, v7) return final function addBlankClip(clip a, clip b) { max = Max(a.FrameCount, b.FrameCount) result = (a.FrameCount != max) ? (a + BlankClip(a, length=max- a.FrameCount)).FreezeFrame(a.FrameCount, max - 1, a.FrameCount - 1) : a return result } function FormatTime(int ms) { s = ms / 1000 ms = ms % 1000 m = s / 60 s = s % 60 h = m / 60 m = m % 60 return String(m, "%02.0f") + ":" + String(s, "%02.0f") + "." + String(ms, "%03.0f") } function AddFrameDiff(clip a, clip b) { FrameDiff = (a.FrameCount - b.FrameCount) return FrameDiff } function Open(string FileName, string Title) { AVISource(FileName) AddBorders(2, 20, 2, 20) Subtitle(Title, align=2, text_color=$00FFFFFF) ScriptClip("""Subtitle("Frame: " + String(current_frame) + "\nTime: " + FormatTime(Round(Float(current_frame * 1000) * Float(FrameRateDenominator) / Float(FrameRateNumerator))), text_color=$00FFFFFF, lsp=1, size=10.0)""") ConvertToYV24(matrix="PC.601", chromaresample="point" ) ConvertToYV12(matrix="PC.601", chromaresample="lanczos4") } function Format (clip a, clip b, int FrameDiff) { left = AddBlankClip (a, b) right = AddBlankClip (b, a) AudioDub(StackHorizontal(left, right), MixAudio(left, right, 1.0, 0.0)) Subtitle("Frames gained: " + String(FrameDiff, "%05.0f"), align=2, size=15) }
Comments?
Publisher
Joined: 4/23/2009
Posts: 1283
functions are able to change global variables. It is global for a reason.
Reviewer, Active player (277)
Joined: 12/14/2006
Posts: 717
So, I'm almost done with my first official full run video. It's a comparison of the first two runs of Sonic and Knuckles and Sonic 3 that were published to the site, taking into account that the timing in those runs uses game time rather than real time. I have a couple of questions? Should I post them in the topics when I'm done? Also, I'm starting the comparison of the second to the third and I found out that nitsuja's run reaches the first check point a little later in real time than Sprintgod's run. However, that's because he uses Tails to start moving in the level early, meaning he has a head start when the level happens. I could key the movie to when the level starts, but that wouldn't give a good side by side comparison. Should I ignore the cut scene skip and play them side by side (thus showing the frame loss), have the segments both start when the timer starts (thus showing the gain by the timing we're using, but losing the direct side to side comparison), or show the levels properly, but have the frame indicator take game time into account? There's advantages and disadvantages to each.
Publisher
Joined: 4/23/2009
Posts: 1283
arkiandruski wrote:
Should I post them in the topics when I'm done?
(late) sure!
Reviewer, Active player (277)
Joined: 12/14/2006
Posts: 717
Just necroing this topic to say that I've started this project up again. I'll post the script I'm using so other people can make them, too. It would be nice if we can eventually get to the point where there's one for every movie we can reasonably do it for (not holding my breath, though). It would help people understand where improvements come from, making the site a little more user friendly (maybe?). Also, I noticed in another thread that someone thought it was a mistake I was only using the left channel. I do this because I put sync points in more often than the music changes. Thus as the movie goes along, the music between the two tracks would get more and more out of sync, which I would find annoying. I use the left channel, since it's the slower one and would have the music "stop" less often. My script. some numbers may have to be changed based on the system the game comes from.
a = Open( "oldermovie.avi", "oldauthor" ) b = Open("newermovie.avi", "newauthor") v = 0 p = 0 old = a.Trim(0, 362) new = b.Trim(0, 360) final = Format (old, new, v, p) p = AddFrameDiff (old, new) v = v + AddFrameDiff (old, new) old = a.Trim(1829, 2578) new = b.Trim(1829, 2515) final = final + Format (old, new, v, p) p = AddFrameDiff (old, new) v = v + AddFrameDiff (old, new) return final function addBlankClip(clip a, clip b) { max = Max(a.FrameCount, b.FrameCount) result = (a.FrameCount != max) ? (a + BlankClip(a, length=max- a.FrameCount)).FreezeFrame(a.FrameCount, max - 1, a.FrameCount - 1) : a return result } function FormatTime(int ms) { s = ms / 1000 ms = ms % 1000 m = s / 60 s = s % 60 h = m / 60 m = m % 60 return String(m, "%02.0f") + ":" + String(s, "%02.0f") + "." + String(ms, "%03.0f") } function AddFrameDiff(clip a, clip b) { FrameDiff = (a.FrameCount - b.FrameCount) return FrameDiff } function Open(string FileName, string Title) { AVISource(FileName) AddBorders(2, 20, 2, 20) Subtitle(Title, align=2, text_color=$00FFFFFF) ScriptClip("""Subtitle("Frame: " + String(current_frame) + "\nTime: " + FormatTime(Round(Float(current_frame * 1000) * Float (FrameRateDenominator) / Float(FrameRateNumerator))), text_color=$00FFFFFF, lsp=1, size=10.0)""") ConvertToYV24(matrix="PC.601", chromaresample="point" ) ConvertToYV12(matrix="PC.601", chromaresample="lanczos4") } function Format (clip a, clip b, int FrameDiff, int FrameGain) { left = AddBlankClip (a, b) right = AddBlankClip (b, a) AudioDub(StackHorizontal(left, right), MixAudio(left, right, 1.0, 0.0)) Subtitle("Frames gained (last): " + String (FrameGain, "%.0f"), y=250, align=2, size=10) Subtitle("Frames gained (total): " + String(FrameDiff, "%05.0f"), align=2, size=10) }
Publisher
Joined: 4/23/2009
Posts: 1283
I saw one of your videos. and it looks great! Keep it up =)
Joined: 7/30/2011
Posts: 129
Location: Watching a TAS in the basement...
Can I help? (I can put some on YouTube)
I am the future ruler of the world! My forum: http://elderyoshisisland.forumotion.com/
Reviewer, Active player (277)
Joined: 12/14/2006
Posts: 717
Sure. That's part of the reason I posted the script. Now, if you'll excuse me, I have some links to post (should have a long time ago. Hopefully it isn't seen as spamming).
Site Admin, Skilled player (1237)
Joined: 4/17/2010
Posts: 11274
Location: RU
For those who don't know, you can create a YT account (or check your current one) & unlimit it. http://tasvideos.org/forum/viewtopic.php?p=288366#288366
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.
Reviewer, Active player (277)
Joined: 12/14/2006
Posts: 717
Alright. Youtube uncapped. Unfortunately, I can't reupload the Sonic 3 and Knuckles runs because I have deleted the video files off my computer. But future runs over the cap should be fine.
Joined: 7/30/2011
Posts: 129
Location: Watching a TAS in the basement...
I keep getting a syntax error message on line 22, column 0. This is the line:
function addBlankClip(clip a, clip b) {
Do I need to replace something here?
I am the future ruler of the world! My forum: http://elderyoshisisland.forumotion.com/
Reviewer, Active player (277)
Joined: 12/14/2006
Posts: 717
What do you have as your two movie files? Youtube doesn't seem to like my video. Shame that. I'm not quite sure what the problem is and probably don't have time to really look into it right now. Will try later.
Joined: 7/30/2011
Posts: 129
Location: Watching a TAS in the basement...
Rockman 2 aglasscage,FinalFighter,pirohiko,Shinryuu-rockman2improvement.avi shinryuu,pirohiko,finalfighter-rockman2.avi
I am the future ruler of the world! My forum: http://elderyoshisisland.forumotion.com/
Reviewer, Active player (277)
Joined: 12/14/2006
Posts: 717
Remove the commas from the file names then try again.
Joined: 7/30/2011
Posts: 129
Location: Watching a TAS in the basement...
No luck. It gives me the same message.
I am the future ruler of the world! My forum: http://elderyoshisisland.forumotion.com/