
我正在嘗試在批次檔中建立命令,如果某個 nVidia 檔案存在,它將使用顯示卡對視訊進行編碼 - 但如果該 nVidia 檔案不存在,它會跳到另一個標籤以使用另一個命令。
:SOFTWARE_ENCODE
如果該位置不存在 nvcuda.dll,則不會跳到標籤:
if exist "%SYSTEMDRIVE%\Windows\System32\nvcuda.dll" goto :NVIDIA_ENCODE
if not exist "%SYSTEMDRIVE%\Windows\System32\nvcuda.dll" goto :SOFTWARE_ENCODE
如果 nvcuda.dll 確實存在,則上述操作將起作用並跳至標籤:NVIDIA_ENCODE
。
我用谷歌搜尋了一下,看到有人透過使用else
括號來解決這個問題,但這也不起作用:
if exist "%SYSTEMDRIVE%\Windows\System32\nvcuda.dll" (goto NVIDIA_ENCODE) else goto SOFTWARE_ENCODE
發生相同的結果,如果 nvcuda.dll 不存在,它似乎只是跳過批次檔的其餘部分。
我知道 nVidia 編碼和軟體編碼都可以對視訊進行編碼,因為我已經註解掉了if exist
和if not exist
部分,並單獨測試了每個(ffmpeg)編碼命令。
(在測試軟體編碼時,我將 nvcuda.dll 重新命名為“.bak”)。
我記得過去發生過這種情況,不知道為什麼它會忽略goto
與 一起使用if not exist
。
任何解決方案都將受到高度讚賞。
編輯:這是整個批次檔......
if not DEFINED IS_MINIMIZED set IS_MINIMIZED=1 && start "" /min "%~dpnx0" %* && exit
:: ------------------------------------------------------------------------------
:: This part swaps the first and last 4 characters around...
:: (This processes all files in sub-folders, but I want to make it only process files next to the batch file)...
setlocal enabledelayedexpansion
echo.
for /f "delims= eol=:" %%f in ('dir /b /a-d G???????*.* ????G???*.*') do (
set filename=%%~nf
set firstfour=!filename:~0,4!
set secondfour=!filename:~4,4!
echo %%f ^> !secondfour!!firstfour!!filename:~8!%%~xf
ren %%f !secondfour!!firstfour!!filename:~8!%%~xf
)
set /a Index=1
:: ------------------------------------------------------------------------------
:: This part renames the files 001, 002, 003 and so on.
for /r %%i in (*.mp4) do (
rem if number is less than 10, append 9 to file name
if !Index! lss 10 (
rename "%%i" 00"!Index!.mp4"
) else (
rename "%%i" "0!Index!.mp4"
)
set /a Index+=1
)
:: ------------------------------------------------------------------------------
:: Delete junk files...
del "*.LRV"
del "*.THM"
:: ------------------------------------------------------------------------------
rem Create TEMP folder for files to be created in...
if not exist "TEMP" md "TEMP"
:: ------------------------------------------------------------------------------
:: Use nVidia to encode if that driver file is installed...
:: Not working, but will work if nvcuda.dll is there...
:: if exist %SYSTEMDRIVE%\Windows\System32\nvcuda.dll (goto NVIDIA_ENCODE) else goto SOFTWARE_ENCODE
:: Original lines also not working...
if exist "%SYSTEMDRIVE%\Windows\System32\nvcuda.dll" goto :NVIDIA_ENCODE
if not exist "%SYSTEMDRIVE%\Windows\System32\nvcuda.dll" goto :SOFTWARE_ENCODE
:: ------------------------------------------------------------------------------
:: Convert to 1080p...
:NVIDIA_ENCODE
rem Convert video files...
FOR /F "tokens=*" %%G IN ('dir /b *.mp4') DO start /wait /min ffmpeg.exe -y -i "%%G" -vcodec hevc_nvenc -vf scale=1920:-2,fps=23.976 -b:v 4000k -acodec aac -b:a 192k -ar 44100 -ac 2 "TEMP\%%~nG.mp4" -hide_banner
goto :JOIN_FILES
:SOFTWARE_ENCODE
rem Convert video files...
FOR /F "tokens=*" %%G IN ('dir /b *.mp4') DO start /wait /min ffmpeg.exe -y -i "%%G" -vcodec libx265 -vf scale=1920:-2,fps=23.976 -b:v 4000k -acodec aac -b:a 192k -ar 44100 -ac 2 "TEMP\%%~nG.mp4" -hide_banner
goto :JOIN_FILES
:: ------------------------------------------------------------------------------
:: Join the files into one video...
:JOIN_FILES
(for %%i in (TEMP\*.mp4) do @echo file '%%i') > mp4_file_list.txt
For %%a IN ("TEMP\*.mp4") DO Set "mp4file=%%~na"
start /wait /min ffmpeg.exe -y -f concat -safe 0 -i mp4_file_list.txt -c copy "%mp4file%_JOINED.mp4" -hide_banner
del mp4_file_list.txt
:: ------------------------------------------------------------------------------
:: Delete the TEMP folder...
rd /s /q "TEMP\"
:: ------------------------------------------------------------------------------
:: Rename the "*_JOINED.mp4" file with todays date and " - GoPro Video" at the end.
:: (The dating method follows the format: YYYY-MM-DD) [May not work on non-UK systems]
For /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%b-%%a)
ren "*_JOINED.mp4" "%mydate% - GoPro Video.mp4"
:: Create a folder "Converted Video" and move the newly converted video file to it.
if not exist "Converted Video" md "Converted Video"
MOVE /Y "%mydate% - GoPro Video.mp4" "Converted Video"
:: ------------------------------------------------------------------------------
:: Rename any old files back to mp4 again that got moved/renamed at the start...
for /r %%x in (*.S6C8JHVH2E7L4BX9) do ren "%%x" *.mp4
:: ------------------------------------------------------------------------------
:: Open folder with finished video...
explorer "Converted Video"
:: ------------------------------------------------------------------------------
exit
如果我使用資料夾中的 MP4 單獨運行它,那麼它確實可以工作:
:: ------------------------------------------------------------------------------
:: Use nVidia to encode if that driver file is installed...
if exist "%SYSTEMDRIVE%\Windows\System32\nvcuda.dll" goto :NVIDIA_ENCODE
if not exist "%SYSTEMDRIVE%\Windows\System32\nvcuda.dll" goto :SOFTWARE_ENCODE
:: ------------------------------------------------------------------------------
:: Convert to 1080p...
:NVIDIA_ENCODE
rem Convert video files...
FOR /F "tokens=*" %%G IN ('dir /b *.mp4') DO start /wait /min ffmpeg.exe -y -i "%%G" -vcodec hevc_nvenc -vf scale=1920:-2,fps=23.976 -b:v 4000k -acodec aac -b:a 192k -ar 44100 -ac 2 "TEMP\%%~nG.mp4" -hide_banner
goto :JOIN_FILES
:SOFTWARE_ENCODE
rem Convert video files...
FOR /F "tokens=*" %%G IN ('dir /b *.mp4') DO start /wait /min ffmpeg.exe -y -i "%%G" -vcodec libx265 -vf scale=1920:-2,fps=23.976 -b:v 4000k -acodec aac -b:a 192k -ar 44100 -ac 2 "TEMP\%%~nG.mp4" -hide_banner
goto :JOIN_FILES
:: ------------------------------------------------------------------------------
:JOIN_FILES
exit
我嘗試過使用pause
但無濟於事。