Create multiple videos with Avisynth

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

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

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

+7
source share
3 answers

I never found a way to pass a command line parameter directly to an AVS script. Scripting on the fly is the only way I could get it to work.

I know that this is not the answer you are looking for - nevertheless, there are two approaches for generating scripts:

Script template

I use this when I have an AVS script, where the only parameter that changes is the original input file.

I have a script template.avs that expects a variable ( v ) containing the full path of the source video. The script package then simply adds a line with a 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 multiple source videos onto the package.

Import

Using the Import command, you can export all variable declarations to your own script.

 Import("variables.avs") 

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

+4
source

Another answer to this question is to let the AviSynth script get its own name indicating the file you want to process. If you want the script to work on movie.mp4 , you can rename it to movie.mp4.avs . The script will look something like this:

 function GetVideoName() { Try { assert(false) } Catch(err_msg) { err_msg = MidStr(err_msg, FindStr(err_msg, "(") + 1) filename = LeftStr(err_msg, StrLen(err_msg) - FindStr(RevStr(err_msg), ".")) return filename } } video_to_process=GetVideoName() #return BlankClip(color=$000000, pixel_type="RGB24").Subtitle("You would process the video [" + video_to_process + "]") DirectShowSource(video_to_process, convertfps=true) 

You can perform the same operations with different videos by simply renaming the script (provided that the videos and .avs are in the same folder). Uncomment next to the last line to understand what I mean.

0
source

It appears that each AviSynth script represents one video.

To get around this (similar to marapet's answer), I also developed a .BAT file in which you can drag and drop video files onto it, and for each of them an AVS file and a path to the video are created. automatically inserted.

AviSynth Script Generator

I think this is a little more flexible since placeholders are used in the script. In addition, it can optionally run ffmpeg (or whatever command you prefer) for each of them to visualize and encode the final result.

Setup Instructions

  1. Save the following script as a .BAT file
  2. Create a subfolder under .BAT called AviSynth Templates
  3. Create your main AVS script (for example, master.avs ) in this subfolder and use the [CLIP] placeholder wherever you want to paste the path to the video. (You can also use [CLIP-NO-EXTENSION] to exclude the file extension if you have additional resources associated with this video.)

     AviSource("[CLIP]") # ...do more tasks here... 
  4. Drag and drop the video files onto the BAT to create an individual AVS file for each. If you put the same video files on the BAT again, AVS will be overwritten with the new version.

Create AVS files.bat

 @ECHO OFF :: INSTRUCTIONS: :: 1. Create an AviSynth script :: 2. Use [CLIP] and/or [CLIP-NO-EXTENSION] as placeholders in the script. :: [CLIP-NO-EXTENSION] will exclude the file-extension in case you want to use it for including subtitles or other files that use the same base name. :: eg AviSource("[CLIP]") :: 3. Place the master .avs script in a folder called "AviSynth Templates", immediately beneath the folder containing this .BAT :: 4. Drag and drop video files onto this BAT and each will be given an AVS file with the same name (video1.avi.avs will be created for video1.avi) :: The placeholders will be filled in with the full absolute path of the dropped files. SET TemplateName=master.avs SET TemplatePath=%~dp0AviSynth Templates\%TemplateName% echo Creating AVS scripts from master template %TemplatePath%... :: Loop through every file dropped onto the .BAT FOR %%A IN (%*) DO ( REM :: Here we create a .AVS file for each video dropped onto the bat REM :: We read in the master script, replace the placeholders and then write the output to a text file using the video filename and .avs extension REM :: REM :: %%A - this contains the full path to the video file, including surrounding double-quotes REM :: %%~A - this contains the full path to the video file, without surrounding double-quotes REM :: %%~dpnA - this contains the full path to the video file, with drive, path and name (dpn) but no file extension (without quotes) echo Creating "%%~A.avs" powershell -Command "(Get-Content '%TemplatePath%').replace('[CLIP]', '%%~A').replace('[CLIP-NO-EXTENSION]', '%%~dpnA') | Out-File -encoding ASCII '%%~A.avs'" REM :: If you want to then run ffmpeg to render and transcode the AVS file you could run it here REM :: eg ffmpeg -i "%%~A.avs" "%%~dpnA.h264.mp4" ) ECHO. ECHO Script creation finished. ECHO. PAUSE 
-1
source

All Articles