【问题标题】:Creating multiple videos with Avisynth使用 Avisynth 创建多个视频
【发布时间】:2014-01-29 18:48:35
【问题描述】:

我有一堆单独的文件,我希望每个文件都通过 Avisynth 运行。但是,一个 AVS 文件只能创建一个视频。据我所知,没有办法从命令行声明变量的值。

我知道您可能可以创建一个脚本来生成一堆 AVS 文件,然后以某种方式将每个 AVS 文件转换为视频。然而,由于 Avisynth 是一个脚本系统,这似乎有点复杂。一定有某种方法可以通过脚本运行不同的视频,对吧?

最好的方法是什么?提前致谢。

【问题讨论】:

    标签: batch-file video batch-processing avisynth


    【解决方案1】:

    我从未找到将命令行参数直接传递给 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 脚本需要多个变量时,这很有用。

    【讨论】:

    • 谢谢,我最终编写了一个 Python 脚本来做与此非常相似的事情。
    • 如果在您的主要 avisynth 脚本中的任何函数中使用,请不要忘记声明全局变量
    【解决方案2】:

    这个问题的另一个答案是让 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 位于同一文件夹中)。取消注释倒数第二行以了解我的意思。

    【讨论】:

    • 这真是太棒了。使用堆栈跟踪从内部提取当前文件名比生成/模板具有不同内容的脚本要简单得多!可以只生成一堆指向单个文件的符号链接,以便仅编辑原始脚本:for f in *.mkv;执行 ln -s process.avs "$f".avs;完成
    【解决方案3】:

    似乎每个 AviSynth 脚本都代表一个视频。

    为了解决这个问题(与 marapet 的回答类似),我还开发了一个 .BAT 文件,您可以在该文件上拖放视频文件,并为每个文件和路径创建一个 AVS 文件视频会自动插入。

    我认为这更灵活一些,因为它在脚本中使用了占位符。它还可以选择在每个命令上运行 ffmpeg(或您喜欢的任何命令)来渲染和编码最终结果。

    设置说明

    1. 将以下脚本另存为.BAT 文件
    2. .BAT 下创建一个名为AviSynth Templates 的子文件夹
    3. 在此子文件夹中创建您的主 AVS 脚本(例如 master.avs),并在您希望注入视频路径的任何位置使用占位符 [CLIP]。 (如果您有与该视频相关的额外资产,也可以使用[CLIP-NO-EXTENSION] 排除文件扩展名。)

      AviSource("[CLIP]")
      # ...do more tasks here...
      
    4. 将视频文件拖放到您的 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
    

    【讨论】:

    • 不知道为什么我投了反对票。 ? 很高兴收到有关脚本的反馈。
    • 另一位评论者提到包含单引号的视频文件会使脚本崩溃。如果有人可以为此提供简单的解决方法,请发布并让其他人知道。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 2013-09-28
    相关资源
    最近更新 更多