2

所以我创建了一个 Windows 批处理脚本来使用 HandbrakeCLI 转换视频

批处理脚本:

@echo off
::SET TO CURRENT CODE PAGE:::::::::::::::::::::::::::
FOR /F "tokens=4 delims= " %%G in ('chcp') DO (
chcp %%G >nul
) 
:::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal EnableExtensions
title AniCoder v2.5 by Nightsanity
color 0a
cd "%~d0%~p0"

::PREVENT MULTIPLE HANDBRAKE PROCESSES::::::::::::::::
set ignore=INFO:
for /f "usebackq" %%A in (`tasklist /nh /fi "imagename eq HandBrakeCLI.exe"`) do if not %%A==%ignore% (
exit
)
::::::::::::::::::::::::::::::::::::::::::::::::::::::

::PREREQUISITES CHECK:::::::::::::::::::::::::::::::::
if not exist "HandBrakeCLI.exe" (
echo HandBrakeCLI is missing!
pause 
exit
)
if exist "Jobs.txt" del "Jobs.txt"
if not exist "ToConvert" mkdir "ToConvert"
if not exist "Converted" mkdir "Converted"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::

::CREATE A LIST OF VIDEOS TO CONVERT:::::::::::::::::::
for /F %%i in ('dir /s /b "ToConvert\*.*"') do (
dir/s/b "ToConvert\*" >> "Jobs.txt"
goto MAIN
)
goto NOFILES
:::::::::::::::::::::::::::::::::::::::::::::::::::::::

::LOOP THROUGH JOBS LIST AND CONVERT FILES:::::::::::::
:MAIN
for /f "tokens=* delims= " %%a in (Jobs.txt) do (
HandBrakeCLI -i "./ToConvert/%%~nxa" -f mp4 -o "./Converted/%%~na.mp4" -q 22 -e x264 -x cabac=0:ref=2:me=hex:bframes=0:weightp=0:subme=6:8x8dct=0:trellis=0 -E faac --mixdown mono -B 64 -X 480 -l 272 -s 1 --subtitle-burn -a 1
)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::

::CLEAN UP FILES:::::::::::::::::::::::::::::::::::::::
if exist "Jobs.txt" del "Jobs.txt"
:Question
cls
echo Encode Done!
echo.
set DELFILES=
set /p DELFILES="Do you want to delete original files (Y/N)?:"
if "%DELFILES%" == "y" goto DELNOW
if "%DELFILES%" == "Y" goto DELNOW
if "%DELFILES%" == "n" goto ENDNOW
if "%DELFILES%" == "N" goto ENDNOW
goto Question
:DELNOW
if exist "ToConvert\*.*" del /Q "ToConvert\*.*"
:ENDNOW
endlocal
exit
:::::::::::::::::::::::::::::::::::::::::::::::::::::::

::WHEN NO FILES ARE INSIDE TOCONVERT FOLDER::::::::::::
:NOFILES
echo No video files found in:
echo ToConvert folder
echo.
pause
:::::::::::::::::::::::::::::::::::::::::::::::::::::::

HandbrakeCLI 参考: trac.handbrake.fr/wiki/CLIGuide

我遇到了一个问题,如果路径中有特殊字符,例如德语变音符号,它不会解释它或其他东西,因为它不会转换并关闭窗口。

我该如何解决这个问题?

运行 Windows 7 家庭高级版 Sp1

4

1 回答 1

1

我建议你改变

for /F %%i in ('dir /s /b "ToConvert\*.*"') do (
 dir/s/b "ToConvert\*" >> "Jobs.txt"

for /F "delims=" %%i in ('dir /s /b "ToConvert\*.*"') do (
 echo(%%~dspnxi >> "Jobs.txt"

将短名称输出到jobs.tst.

也许

 echo(%%~dspi%%~nxi >> "Jobs.txt"

可能更好。

(无法测试 - 我没有可用的测试目录)

于 2014-05-08T05:11:57.020 回答