-1

好的,所以我尝试进行批处理视频处理,我想将其压缩为单个批处理文件而不是 5,但我无法将变量传递给内部函数,就像我将它们传递给外部 .bat 文件一样.

这是我的“一体式”版本

mkdir new

mkdir new\fonts

forfiles /M *.mkv /C "cmd /c call :mkvextract @file @fname" >> log.txt 2>&1

forfiles /M *.mkv /C "cmd /c call :mkvmerge @file" >> merge.txt 2>&1

forfiles /M *.mkv /C "cmd /c call :makeavs @file @fname" >> log.txt 2>&1

forfiles /M *.mkv /C "cmd /c call :getfonts @file @fname" >> fonts.txt 2>&1

forfiles /M *.ttf /C "cmd /c call :movefonts @file" >> fonts.txt 2>&1

forfiles /M *.TTF /C "cmd /c call :movefonts @file" >> fonts.txt 2>&1

forfiles /M *.otf /C "cmd /c call :movefonts @file" >> fonts.txt 2>&1

forfiles /M *.OTF /C "cmd /c call :movefonts @file" >> fonts.txt 2>&1

:mkvextract

"C:\Program Files (x86)\MKVToolNix\mkvextract.exe" --ui-language en tracks "%~1" 2:"%CD%\new\%~2_track3_eng.ass"

goto :EOF

:mkvmerge

set mkvorig=%CD%\%~1
set mkvorig=%mkvorig:\=\\%

set mkvnew=%CD%\new\%~1
set mkvnew=%mkvnew:\=\\%

"C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "%mkvnew%"  "--language" "0:jpn" "--default-track" "0:yes" "--forced-track" "0:no" "--display-dimensions" "0:1920x1080" "--language" "1:jpn" "--default-track" "1:yes" "--forced-track" "1:no" "-a" "1" "-d" "0" "--no-attachments" "-S" "-T" "--no-global-tags" "--no-chapters" "(" "%mkvorig%" ")" "--track-order" "0:0,0:1"

goto :EOF

:makeavs

echo Directshowsource("new\%~1") >"new\%~2.avs"
echo textsub("new\%~2_track3_eng.ass") >>"new\%~2.avs"

goto :EOF

:getfonts

"C:\Program Files (x86)\MKVToolNix\mkvextract.exe" attachments "%~1" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

goto :EOF


:movefonts

move %~1 new\fonts

goto :EOF

“五个.bat文件”版本如下:

mkdir new

mkdir new\fonts

forfiles /M *.mkv /C "cmd /c mkvextract.bat @file @fname" >> log.txt 2>&1

forfiles /M *.mkv /C "cmd /c mkvmerge.bat @file" >> merge.txt 2>&1

forfiles /M *.mkv /C "cmd /c makeavs.bat @file @fname" >> log.txt 2>&1

forfiles /M *.mkv /C "cmd /c getfonts.bat @file @fname" >> fonts.txt 2>&1

forfiles /M *.ttf /C "cmd /c movefonts.bat @file" >> fonts.txt 2>&1

forfiles /M *.TTF /C "cmd /c movefonts.bat @file" >> fonts.txt 2>&1

forfiles /M *.otf /C "cmd /c movefonts.bat @file" >> fonts.txt 2>&1

forfiles /M *.OTF /C "cmd /c movefonts.bat @file" >> fonts.txt 2>&1

我不太确定我是否正确地执行函数调用,但它看起来很正确,因为我在这里找到了:http: //batcheero.blogspot.com/2007/07/function-call-in-batch.html

4

1 回答 1

2

forfiles 执行的命令在一个全新的 CMD.EXE 会话中。它们不再在您的母批处理上下文中,因此您不能在您的母批处理脚本中调用子例程。

您可以重组您的主脚本以调用自身并将例程的名称作为参数传递。如果标签存在,您的脚本可以转到该标签。

您的第一个脚本在第一个子例程之前也缺少 EXIT /B 或 GOTO :EOF。

您不需要制作中间目录。您可以直接制作new\fontsnew如果它尚不存在将被创建。

@echo off

:: If first argument is a valid label then GOTO that label
if "%~1" neq "" findstr /bc:":%~1" "%~f0" >nul && (
  shift /1
  goto %~1
)

::Main program
if not exist new\fonts mkdir new\fonts
forfiles /M *.mkv /C "cmd /c "%~f0" mkvextract @file @fname" >> log.txt 2>&1
forfiles /M *.mkv /C "cmd /c "%~f0" mkvmerge @file" >> merge.txt 2>&1
forfiles /M *.mkv /C "cmd /c "%~f0" makeavs @file @fname" >> log.txt 2>&1
forfiles /M *.mkv /C "cmd /c "%~f0" getfonts @file @fname" >> fonts.txt 2>&1
forfiles /M *.ttf /C "cmd /c "%~f0" movefonts @file" >> fonts.txt 2>&1
forfiles /M *.TTF /C "cmd /c "%~f0" movefonts @file" >> fonts.txt 2>&1
forfiles /M *.otf /C "cmd /c "%~f0" movefonts @file" >> fonts.txt 2>&1
forfiles /M *.OTF /C "cmd /c "%~f0" movefonts @file" >> fonts.txt 2>&1
exit /b

:mkvextract
"C:\Program Files (x86)\MKVToolNix\mkvextract.exe" --ui-language en tracks "%~1" 2:"%CD%\new\%~2_track3_eng.ass"
exit /b

:mkvmerge
set mkvorig=%CD%\%~1
set mkvorig=%mkvorig:\=\\%
set mkvnew=%CD%\new\%~1
set mkvnew=%mkvnew:\=\\%
"C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "%mkvnew%"  "--language" "0:jpn" "--default-track" "0:yes" "--forced-track" "0:no" "--display-dimensions" "0:1920x1080" "--language" "1:jpn" "--default-track" "1:yes" "--forced-track" "1:no" "-a" "1" "-d" "0" "--no-attachments" "-S" "-T" "--no-global-tags" "--no-chapters" "(" "%mkvorig%" ")" "--track-order" "0:0,0:1"
exit /b

:makeavs
echo Directshowsource("new\%~1") >"new\%~2.avs"
echo textsub("new\%~2_track3_eng.ass") >>"new\%~2.avs"
exit /b

:getfonts
"C:\Program Files (x86)\MKVToolNix\mkvextract.exe" attachments "%~1" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
exit /b

:movefonts
move %~1 new\fonts
exit /b
于 2012-10-17T22:34:05.170 回答