fvisagie
10th September 2015, 08:56
Further to my recent feature request (http://forum.doom9.org/showthread.php?t=172575), is there currently any way, however brutal, of modifying (including replacing) audio at runtime?
I've written a script that overcomes Avisynth's input filter limit (i.e. running out of memory after n simultaneous clips). The script's been successfully tested on up to 500 simultaneous artificial clips and 350+ real-life ones. However, it doesn't output any audio ;).
I'd be grateful for any help in making this work. Note that this is a proof of concept that has not been cleaned up or optimised yet - the focus is on getting audio output working first.
sourcescript = "_SetSource.txt"
# "output" is the desired name of the output clip, although the way the code is currently structured makes that immaterial
AVSCat("ADDSOURCE", "output", """AudioDub(BlankClip(length=48), Tone(length=2)).Subtitle("file000").ShowFrameNumber()""", sourcescript)
AVSCat("ADDSOURCE", "output", """AudioDub(BlankClip(length=48), Tone(length=2)).Subtitle("file001").ShowFrameNumber()""", sourcescript)
AVSCat("ADDSOURCE", "output", """AudioDub(BlankClip(length=48), Tone(length=2)).Subtitle("file002").ShowFrameNumber()""", sourcescript)
AVSCat("GETSOURCE", "output", "", sourcescript)
function AVSCat (string mode, string "clipname", string "source", string "sourcescript") {
mode == "ADDSOURCE" ? AddSource(clipname, source, sourcescript) : \
mode == "GETSOURCE" ? GetSource(clipname, sourcescript) : \
Assert(false, "AVSCat: invalid 'mode' '" + mode + "'")
}
function AddSource(string clipname, string source, string sourcescript) {
startframe = Eval("""
try {
FrameCount(Eval(clipname ))
}
catch (err_msg) {
Eval("global " + clipname + " = BlankClip(length=0)")
writestr = "function SetSource(int current_frame) {"
WriteFileStart(Eval(clipname), sourcescript, "writestr", append=false)
writestr = " global " + clipname + " = \"
WriteFileStart(Eval(clipname), sourcescript, "writestr", append=true)
0
}
""")
Eval("global " + clipname + "= BlankClip(" + source + ", length=FrameCount(" + clipname + ") + FrameCount(" + source + "))")
endframe = FrameCount(Eval(clipname))-1
writestr = " current_frame >= " + String(startframe) + " && current_frame <= " + String(endframe) + " ? " + source + \
".Trim(current_frame-" + String(startframe) + ", -1) : \"
WriteFileStart(Eval(clipname), sourcescript, "writestr", append=true)
}
function GetSource(string clipname, string sourcescript) {
writestr = " NOP()"
WriteFileStart(Eval(clipname), sourcescript, "writestr", append=true)
writestr = " return output"
WriteFileStart(Eval(clipname), sourcescript, "writestr", append=true)
writestr = "}"
WriteFileStart(Eval(clipname), sourcescript, "writestr", append=true)
Import(sourcescript)
ScriptClip(Eval(clipname), "SetSource(current_frame)", show=False, after_frame=false)
}
I've written a script that overcomes Avisynth's input filter limit (i.e. running out of memory after n simultaneous clips). The script's been successfully tested on up to 500 simultaneous artificial clips and 350+ real-life ones. However, it doesn't output any audio ;).
I'd be grateful for any help in making this work. Note that this is a proof of concept that has not been cleaned up or optimised yet - the focus is on getting audio output working first.
sourcescript = "_SetSource.txt"
# "output" is the desired name of the output clip, although the way the code is currently structured makes that immaterial
AVSCat("ADDSOURCE", "output", """AudioDub(BlankClip(length=48), Tone(length=2)).Subtitle("file000").ShowFrameNumber()""", sourcescript)
AVSCat("ADDSOURCE", "output", """AudioDub(BlankClip(length=48), Tone(length=2)).Subtitle("file001").ShowFrameNumber()""", sourcescript)
AVSCat("ADDSOURCE", "output", """AudioDub(BlankClip(length=48), Tone(length=2)).Subtitle("file002").ShowFrameNumber()""", sourcescript)
AVSCat("GETSOURCE", "output", "", sourcescript)
function AVSCat (string mode, string "clipname", string "source", string "sourcescript") {
mode == "ADDSOURCE" ? AddSource(clipname, source, sourcescript) : \
mode == "GETSOURCE" ? GetSource(clipname, sourcescript) : \
Assert(false, "AVSCat: invalid 'mode' '" + mode + "'")
}
function AddSource(string clipname, string source, string sourcescript) {
startframe = Eval("""
try {
FrameCount(Eval(clipname ))
}
catch (err_msg) {
Eval("global " + clipname + " = BlankClip(length=0)")
writestr = "function SetSource(int current_frame) {"
WriteFileStart(Eval(clipname), sourcescript, "writestr", append=false)
writestr = " global " + clipname + " = \"
WriteFileStart(Eval(clipname), sourcescript, "writestr", append=true)
0
}
""")
Eval("global " + clipname + "= BlankClip(" + source + ", length=FrameCount(" + clipname + ") + FrameCount(" + source + "))")
endframe = FrameCount(Eval(clipname))-1
writestr = " current_frame >= " + String(startframe) + " && current_frame <= " + String(endframe) + " ? " + source + \
".Trim(current_frame-" + String(startframe) + ", -1) : \"
WriteFileStart(Eval(clipname), sourcescript, "writestr", append=true)
}
function GetSource(string clipname, string sourcescript) {
writestr = " NOP()"
WriteFileStart(Eval(clipname), sourcescript, "writestr", append=true)
writestr = " return output"
WriteFileStart(Eval(clipname), sourcescript, "writestr", append=true)
writestr = "}"
WriteFileStart(Eval(clipname), sourcescript, "writestr", append=true)
Import(sourcescript)
ScriptClip(Eval(clipname), "SetSource(current_frame)", show=False, after_frame=false)
}