簡體   English   中英

使用 Avisynth 創建多個視頻

[英]Creating multiple videos with 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("variables.avs")

當模板 AVS 腳本需要多個變量時,這很有用。

似乎每個 AviSynth 腳本都代表一個視頻。

為了解決這個問題(以與 marapet 的回答類似的方式),我還開發了一個.BAT文件,您可以在其中拖放視頻文件,並為每個文件創建一個 AVS 文件,視頻的路徑是自動插入。

AviSynth 腳本生成器

我認為這更靈活一些,因為它在腳本中使用占位符。 它還可以選擇在每個上運行 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

這個問題的另一個答案是讓 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在同一文件夾中)。 取消對倒數第二行的注釋以了解我的意思。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM