我有一堆单独的文件,我希望每个文件都通过 Avisynth 运行。但是,一个 AVS 文件只能创建一个视频。据我所知,没有办法从命令行声明变量的值。
我知道您可能可以创建一个脚本来生成一堆 AVS 文件,然后以某种方式将每个 AVS 文件转换为视频。然而,由于 Avisynth 是一个脚本系统,这似乎有点复杂。一定有某种方法可以通过脚本运行不同的视频,对吧?
做这个的最好方式是什么?提前致谢。
我有一堆单独的文件,我希望每个文件都通过 Avisynth 运行。但是,一个 AVS 文件只能创建一个视频。据我所知,没有办法从命令行声明变量的值。
我知道您可能可以创建一个脚本来生成一堆 AVS 文件,然后以某种方式将每个 AVS 文件转换为视频。然而,由于 Avisynth 是一个脚本系统,这似乎有点复杂。一定有某种方法可以通过脚本运行不同的视频,对吧?
做这个的最好方式是什么?提前致谢。
我从未找到将命令行参数直接传递给 AVS 脚本的方法。动态生成脚本是我能够让它工作的唯一方法。
我知道这不是您要寻找的答案 - 但是有两种生成脚本的方法:
当我有一个 AVS 脚本时,我会使用它,其中唯一更改的参数是源输入文件。
我有一个脚本,它需要一个包含源视频完整路径的template.avs
变量 ( )。v
然后,批处理脚本会简单地将每个视频文件的变量添加到该行之前,类似于:
@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
这使我可以简单地将几个源视频拖放到批处理中。
使用Import指令,可以将所有变量声明外部化到它自己的脚本中。
Import("variables.avs")
当模板 AVS 脚本需要多个变量时,这很有用。
这个问题的另一个答案是让 AviSynth 脚本获得自己的名称来指向您要处理的文件。如果您希望脚本继续运行movie.mp4
,您可以将其重命名为movie.mp4.avs
. 脚本将类似于:
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)
您可以对不同的视频执行相同的操作,只需重命名脚本(前提是视频和.avs
它们位于同一文件夹中)。取消注释倒数第二行以了解我的意思。
似乎每个 AviSynth 脚本都代表一个视频。
为了解决这个问题(以与 marapet 的回答类似的方式),我还开发了一个.BAT
文件,您可以在该文件上拖放视频文件,并为每个文件创建一个 AVS 文件,并自动插入视频的路径.
我认为这更灵活一些,因为它在脚本中使用了占位符。它还可以选择在每个命令上运行 ffmpeg(或您喜欢的任何命令)来渲染和编码最终结果。
.BAT
文件.BAT
在被调用的下创建一个子文件夹AviSynth Templates
在此子文件夹中创建您的主 AVS 脚本(例如),并在您希望注入视频路径的任何位置master.avs
使用占位符。[CLIP]
([CLIP-NO-EXTENSION]
如果您有与该视频相关的额外资产,您也可以使用排除文件扩展名。)
AviSource("[CLIP]")
# ...do more tasks here...
将视频文件拖放到您的 BAT 上,为每个文件创建一个自定义的 AVS 文件。如果您再次将相同的视频文件放到 BAT 上,AVS 将被新版本覆盖。
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.
:: e.g. 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's 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 :: e.g. ffmpeg -i "%%~A.avs" "%%~dpnA.h264.mp4"
)
ECHO.
ECHO Script creation finished.
ECHO.
PAUSE