feos
10th May 2022, 21:45
I made a script for comparing speedrun gameplay videos and figuring out how many frames something was improved by.
It's main purpose is aligning the 2 videos together by compensating for segments that are now shorter (I just inject blank frames there) and reporting how many frames it's now shorter by, as well as the overall difference for the current frame (it was hard!).
I managed to resolve all the problems I stumbled upon, but I want to know if I did something in a dumb way that can instead be done neatly by using more in-depth avisynth knowledge. So I would love to see some expert advises on now to improve this script.
Here's the video that I got with it:
https://www.youtube.com/watch?v=YRJPlbjp9bA
The main feature is the insert() function that heavily uses global variables and decides which clip it should be inserting blank frames into. If it's an improvement, the length argument is positive and the new clip is used, but if length is negative, the old clip is faster in that segment so I use it instead.
Reporting total difference was hard because I couldn't just put the value on top of the 2 stacked horizontally clips, it needed to change only when either of the clips is changing.
Since subtitles just stacked on top of one another I had to overlay a black rectangle before printing each subtitle, since avisinth font has fixed-size halo.
global f = 1
global total = 0
global subsize = 10*f
global subalign = 8
global boxh = subsize
global boxw = subsize*6
global format_str = "%4.0f"
global old = AVISource("old.avi").ResampleAudio(44100)
global new = AVISource("new.avi").ResampleAudio(44100)
global old = old.PointResize(old.width*f, old.height*f).Subtitle( "feos", align=8, size=subsize)
global new = new.PointResize(new.width*f, new.height*f).Subtitle("DreamYao", align=8, size=subsize)
##################
# actual usage #
##################
insert( 2705, 6)
insert( 4093, 3)
insert( 5168, 12)
insert( 7784, 9)
insert( 8008, -1)
insert( 9225, 59)
insert(11771, 56)
insert(14054,113)
insert(15372, 14)
insert(15897, 11)
insert(17748, 2)
insert(20293, 10)
insert(21061, 6)
insert(24002, 97)
insert(24524, 5)
insert(28675, 45)
insert(30425, 67)
insert(30957, -3)
insert(36329,101)
insert(36617, 4)
insert(37410, 12)
insert(39489,165)
insert(40660, 16)
insert(41882, 7)
insert(44006, 9)
insert(45416, 2)
##################
StackHorizontal(old, new)
KillAudio
audio = MonoToStereo(GetChannel(old, 1), GetChannel(new, 1))
AudioDub(audio, last)
Trim(0, 328220)
function insert(int start, int length) {
global total = total + length
if (length > 0) {
c = new
length_temp = length
} else {
c = old
length_temp = -length
}
global suby = c.height - subsize
subx = c.width/2
BlankClip(c, length_temp)
ScriptClip("""Subtitle(string(current_frame+1), \
align=subalign, y=suby, size=subsize, font="Consolas", text_color=color_lime)""")
c.Trim(0, start-1) ++ last ++ c.Trim(start, -0) \
.Overlay(BlankClip(width=boxw, height=boxh, color=color_black), \
x=subx-boxw/2, y=suby) \
.Subtitle("last: "+string(length_temp, format_str), \
y=suby, align=subalign, size=subsize, font="Consolas", text_color=color_lime)
if (length > 0) {
global new = last
} else {
global old = last
}
global new = new.Trim(0, start+length) ++ new.Trim(start+length+1, -0) \
.Overlay(BlankClip(width=boxw, height=boxh, color=color_black), \
x=subx-boxw/2, y=suby-subsize) \
.Subtitle("total: "+string(total, format_str), \
y=suby-subsize, align=subalign, size=subsize, font="Consolas")
}
It's main purpose is aligning the 2 videos together by compensating for segments that are now shorter (I just inject blank frames there) and reporting how many frames it's now shorter by, as well as the overall difference for the current frame (it was hard!).
I managed to resolve all the problems I stumbled upon, but I want to know if I did something in a dumb way that can instead be done neatly by using more in-depth avisynth knowledge. So I would love to see some expert advises on now to improve this script.
Here's the video that I got with it:
https://www.youtube.com/watch?v=YRJPlbjp9bA
The main feature is the insert() function that heavily uses global variables and decides which clip it should be inserting blank frames into. If it's an improvement, the length argument is positive and the new clip is used, but if length is negative, the old clip is faster in that segment so I use it instead.
Reporting total difference was hard because I couldn't just put the value on top of the 2 stacked horizontally clips, it needed to change only when either of the clips is changing.
Since subtitles just stacked on top of one another I had to overlay a black rectangle before printing each subtitle, since avisinth font has fixed-size halo.
global f = 1
global total = 0
global subsize = 10*f
global subalign = 8
global boxh = subsize
global boxw = subsize*6
global format_str = "%4.0f"
global old = AVISource("old.avi").ResampleAudio(44100)
global new = AVISource("new.avi").ResampleAudio(44100)
global old = old.PointResize(old.width*f, old.height*f).Subtitle( "feos", align=8, size=subsize)
global new = new.PointResize(new.width*f, new.height*f).Subtitle("DreamYao", align=8, size=subsize)
##################
# actual usage #
##################
insert( 2705, 6)
insert( 4093, 3)
insert( 5168, 12)
insert( 7784, 9)
insert( 8008, -1)
insert( 9225, 59)
insert(11771, 56)
insert(14054,113)
insert(15372, 14)
insert(15897, 11)
insert(17748, 2)
insert(20293, 10)
insert(21061, 6)
insert(24002, 97)
insert(24524, 5)
insert(28675, 45)
insert(30425, 67)
insert(30957, -3)
insert(36329,101)
insert(36617, 4)
insert(37410, 12)
insert(39489,165)
insert(40660, 16)
insert(41882, 7)
insert(44006, 9)
insert(45416, 2)
##################
StackHorizontal(old, new)
KillAudio
audio = MonoToStereo(GetChannel(old, 1), GetChannel(new, 1))
AudioDub(audio, last)
Trim(0, 328220)
function insert(int start, int length) {
global total = total + length
if (length > 0) {
c = new
length_temp = length
} else {
c = old
length_temp = -length
}
global suby = c.height - subsize
subx = c.width/2
BlankClip(c, length_temp)
ScriptClip("""Subtitle(string(current_frame+1), \
align=subalign, y=suby, size=subsize, font="Consolas", text_color=color_lime)""")
c.Trim(0, start-1) ++ last ++ c.Trim(start, -0) \
.Overlay(BlankClip(width=boxw, height=boxh, color=color_black), \
x=subx-boxw/2, y=suby) \
.Subtitle("last: "+string(length_temp, format_str), \
y=suby, align=subalign, size=subsize, font="Consolas", text_color=color_lime)
if (length > 0) {
global new = last
} else {
global old = last
}
global new = new.Trim(0, start+length) ++ new.Trim(start+length+1, -0) \
.Overlay(BlankClip(width=boxw, height=boxh, color=color_black), \
x=subx-boxw/2, y=suby-subsize) \
.Subtitle("total: "+string(total, format_str), \
y=suby-subsize, align=subalign, size=subsize, font="Consolas")
}