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

Reply
 
Thread Tools Search this Thread Display Modes
Old 10th September 2015, 08:56   #1  |  Link
fvisagie
Registered User
 
Join Date: Aug 2008
Location: Isle of Man
Posts: 586
How to replace and/or modify audio at runtime?

Further to my recent feature request, 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.

Code:
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)
}

Last edited by fvisagie; 10th September 2015 at 09:37. Reason: Specified input clip examples that produce audio ;-)
fvisagie is offline   Reply With Quote
Old 13th September 2015, 19:28   #2  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,377
The easiest way to handle hundreds of clips would be to concatenate them all into one, then Trim() your subclips as needed.
If the sources are AVI and hopefully intra-frame-only, you can do this live with VirtualDub "append AVI segment" + frameserving.
Otherwise you would have to create a physical intermediate file.
raffriff42 is offline   Reply With Quote
Old 14th September 2015, 09:32   #3  |  Link
fvisagie
Registered User
 
Join Date: Aug 2008
Location: Isle of Man
Posts: 586
In my case, input clips are generally in M2TS format. Also, the typical sizes of projects make intermediate file versions very undesirable.

Both of which led me to doing the concatenation in Avisynth in the first post. However, the runtime audio problem will probably see me fitting in the VirtualDub approach for the time being.

Thanks for the suggestions.
fvisagie is offline   Reply With Quote
Old 14th September 2015, 10:46   #4  |  Link
shekh
Registered User
 
Join Date: Mar 2015
Posts: 517
If you want to concatenate m2ts in VirtualDub:
I have implemented concatenation with my input driver based on ffmpeg. However I have never tried to concatenate more than 2 files and with 300 it will eat enormous amount of memory for sure. But if you claim it solves some fundamental problem then this issue is fixable Link to try: https://sourceforge.net/projects/vdfiltermod/
Btw your input clips must be joinable sample-to-sample, otherwise you get audio sync problem.
shekh is offline   Reply With Quote
Old 14th September 2015, 12:47   #5  |  Link
fvisagie
Registered User
 
Join Date: Aug 2008
Location: Isle of Man
Posts: 586
Quote:
Originally Posted by shekh View Post
If you want to concatenate m2ts in VirtualDub:
I have implemented concatenation with my input driver based on ffmpeg.
Very interesting. If I understand you and the Wiki correctly, that means you've also overcome VirtualDub's insistence on only concatenating AVI files.

Quote:
However I have never tried to concatenate more than 2 files and with 300 it will eat enormous amount of memory for sure. But if you claim it solves some fundamental problem then this issue is fixable Link to try: https://sourceforge.net/projects/vdfiltermod/
Btw your input clips must be joinable sample-to-sample, otherwise you get audio sync problem.
Thanks. I'll let you know if this becomes my last resort, but I'm not convinced audio sync will not be a problem. Each file was created independently by the camera, and I haven't found documentation on whether or not provision is made for sample-level joining. In case you know more (or can find out more about this) than me, the camera is a Canon Legria/Vixia HF G30.
fvisagie is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 14:11.


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