Search code examples
batch-filevideobatch-processingavisynth

Creating multiple videos with Avisynth


I have a bunch of individual files that I want to each run through Avisynth. However, an AVS file can only create one video. As far as I know, there is no way to declare a variable's value from the command line.

I know that you can probably create a script that generates a bunch of AVS files and then somehow convert each AVS file to a video. However, since Avisynth is a scripting system, this seems kind of complicated. There must be some way to run different videos through a script, right?

What is the best way to do this? Thanks in advance.


Solution

  • I've never found a way to pass a command line parameter directly to a AVS script. Generating scripts on the fly is the only way I was able to get it working.

    I know this is not the answer you're looking for - nevertheless two approaches for generating scripts:

    Template script

    I use this when I have a AVS script where the only parameter which changes is the source input file.

    I have a script template.avs which expects a variable (v) containing the full path of the source video. A batch script then simply prepends the line with the variable for each video file, similar to this:

    @echo off
    if "%1" == "" (
        echo No input video found
        pause
        GOTO :EOF
    )
    set pth=%~dp0
    
    :loop
    IF "%1"=="" GOTO :EOF
    
    echo v="%1">"%pth%_tmp.avs"
    type "%pth%template.avs">>"%pth%_tmp.avs"
    
    :: Do whatever you want with the script
    :: I use virtualdub...
    "%vdub%" /i "%pth%Template.vdscript" "%pth%_tmp.avs"
    
    del "%pth%_tmp"
    
    SHIFT
    GOTO loop
    

    This allows me to simply drag-and-drop several source videos onto the batch.

    Import

    Using the Import instruction, it is possible to externalize all the variable declarations into its own script.

    Import("variables.avs")
    

    This is useful when the template AVS script expects multiple variables.