Question

So I created a windows batch script to convert videos using the HandbrakeCLI

Batch script:

@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 reference: trac.handbrake.fr/wiki/CLIGuide

I have ran into a problem where if there is a special character in the path for example a German Umlaut it will not interpret it or something as it wont convert and close the window.

How can I workaround this issue?

Running Windows 7 Home Premium Sp1

Was it helpful?

Solution

I'd suggest you change

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

to

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

to output the shortname to jobs.tst.

or perhaps

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

may be better.

(can't test - no test directories available to me)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top