Code: Select all
@echo off
setlocal
REM Set the directory containing your MKV video files and HandBrakeCLI.exe
set "VideoDir=%~dp0"
REM Set the directory where you want to save the compressed videos
set "OutputDir=%~dp0"
REM Set the path to your HandBrakeCLI.exe
set "HandBrakeCLI=%~dp0\HandBrakeCLI.exe"
REM Set the path to your ffprobe.exe
set "ffprobe=%~dp0\ffprobe.exe"
REM Set the path to your log file
set "LogFile=%~dp0\log.txt"
for /R "%VideoDir%" %%F in (*.mkv) do (
for /f "tokens=2 delims=x" %%a in ('"%ffprobe%" -v error -select_streams v:0 -show_entries stream=height -of default=noprint_wrappers=1:nokey=1 "%%F"') do (
set "height=%%a"
)
if !height! geq 720 (
"%HandBrakeCLI%" --input "%%F" --output "%%~dpnF.mp4" --all-audio --all-subtitles --mixdown 5point1 -R 44.1 -e nvenc_h265 -q 27 -x cabac=1:ref=5:analyse=0x133:me=umh:subme=9:chroma-me=1:deadzone-inter=21:deadzone-intra=11:b-adapt=2:rc-lookahead=60:vbv-maxrate=10000:vbv-bufsize=10000:qpmax=69:bframes=5:b-adapt=2:direct=auto:crf-max=51:weightp=2:merange=24:chroma-qp-offset=-1:sync-lookahead=2:psy-rd=1.00,0.15:trellis=2:min-keyint=23:partitions=all --maxWidth 1280 --maxHeight 720 --keep-display-aspect --modulus 2
) else (
"%HandBrakeCLI%" --input "%%F" --output "%%~dpnF.mp4" --all-audio --all-subtitles --mixdown 5point1 -R 44.1 -e nvenc_h265 -q 27 -x cabac=1:ref=5:analyse=0x133:me=umh:subme=9:chroma-me=1:deadzone-inter=21:deadzone-intra=11:b-adapt=2:rc-lookahead=60:vbv-maxrate=10000:vbv-bufsize=10000:qpmax=69:bframes=5:b-adapt=2:direct=auto:crf-max=51:weightp=2:merange=24:chroma-qp-offset=-1:sync-lookahead=2:psy-rd=1.00,0.15:trellis=2:min-keyint=23:partitions=all
)
if errorlevel 1 (
echo %%F >> "%LogFile%"
echo ERROR >> "%LogFile%"
) else (
echo %%F >> "%LogFile%"
echo SUCCESS >> "%LogFile%"
REM Unremark the following line to delete Source files
REM del "%%F"
)
)
endlocal
Windows 11, AMD Ryzen 7 3700X with 32 GBs Ram
HandBrake Activity Log ***required*** (see How-to get an activity log)
Code: Select all
Encoding: task 1 of 1, 0.00 %
Encoding: task 1 of 1, 0.00 %
Encoding: task 1 of 1, 0.00 %
Encoding: task 1 of 1, 1.99 %
Encoding: task 1 of 1, 5.45 %
Encoding: task 1 of 1, 9.82 %
Encoding: task 1 of 1, 13.68 %
Encoding: task 1 of 1, 17.85 %
Encoding: task 1 of 1, 22.07 %
Encoding: task 1 of 1, 25.96 %
Encoding: task 1 of 1, 30.10 %
Encoding: task 1 of 1, 34.23 %
Encoding: task 1 of 1, 38.49 %
Encoding: task 1 of 1, 42.58 %
Encoding: task 1 of 1, 46.88 %
Encoding: task 1 of 1, 51.01 %
Encoding: task 1 of 1, 54.91 %
Encoding: task 1 of 1, 58.69 %
Encoding: task 1 of 1, 63.10 %
Encoding: task 1 of 1, 67.12 %
Encoding: task 1 of 1, 71.13 %
Encoding: task 1 of 1, 75.19 %
Encoding: task 1 of 1, 79.24 %
Encoding: task 1 of 1, 83.06 % (505.47 fps, avg 499.88 fps, ETA 00h00m01s)
Encoding: task 1 of 1, 87.36 % (505.47 fps, avg 499.88 fps, ETA 00h00m01s)
Encoding: task 1 of 1, 91.33 % (505.47 fps, avg 499.88 fps, ETA 00h00m01s)
Encoding: task 1 of 1, 95.71 % (505.47 fps, avg 499.88 fps, ETA 00h00m01s)
Encoding: task 1 of 1, 99.60 % (505.47 fps, avg 499.88 fps, ETA 00h00m01s)
Encoding: task 1 of 1, 99.60 % (505.47 fps, avg 499.88 fps, ETA 00h00m01s)
Encoding: task 1 of 1, 99.60 % (505.47 fps, avg 499.88 fps, ETA 00h00m01s)
Encoding: task 1 of 1, 0.00 %
Encoding: task 1 of 1, 0.00 %
Encoding: task 1 of 1, 0.00 %
Encoding: task 1 of 1, 0.78 %
Encoding: task 1 of 1, 4.24 %
Encoding: task 1 of 1, 7.21 %
Encoding: task 1 of 1, 10.45 %
Encoding: task 1 of 1, 13.59 %
Encoding: task 1 of 1, 16.83 %
Encoding: task 1 of 1, 19.80 %
Encoding: task 1 of 1, 23.18 %
Encoding: task 1 of 1, 26.55 %
Encoding: task 1 of 1, 29.61 %
Encoding: task 1 of 1, 33.07 %
Encoding: task 1 of 1, 36.18 %
Encoding: task 1 of 1, 39.64 %
Encoding: task 1 of 1, 42.93 %
Encoding: task 1 of 1, 46.08 %
Encoding: task 1 of 1, 49.27 %
Encoding: task 1 of 1, 52.78 %
Encoding: task 1 of 1, 56.30 %
Encoding: task 1 of 1, 59.22 %
Encoding: task 1 of 1, 62.41 %
Encoding: task 1 of 1, 65.92 % (345.79 fps, avg 345.42 fps, ETA 00h00m02s)
Encoding: task 1 of 1, 68.98 % (345.79 fps, avg 345.42 fps, ETA 00h00m02s)
Encoding: task 1 of 1, 72.13 % (345.79 fps, avg 345.42 fps, ETA 00h00m02s)
Encoding: task 1 of 1, 75.41 % (345.79 fps, avg 345.42 fps, ETA 00h00m02s)
Encoding: task 1 of 1, 78.88 % (345.79 fps, avg 345.42 fps, ETA 00h00m02s)
Encoding: task 1 of 1, 81.93 % (353.21 fps, avg 348.37 fps, ETA 00h00m01s)
Encoding: task 1 of 1, 84.85 % (353.21 fps, avg 348.37 fps, ETA 00h00m01s)
Encoding: task 1 of 1, 88.46 % (353.21 fps, avg 348.37 fps, ETA 00h00m01s)
Encoding: task 1 of 1, 91.83 % (353.21 fps, avg 348.37 fps, ETA 00h00m01s)
Encoding: task 1 of 1, 95.12 % (353.21 fps, avg 348.37 fps, ETA 00h00m01s)
Encoding: task 1 of 1, 99.54 % (348.26 fps, avg 346.43 fps, ETA 00h00m00s)
Encoding: task 1 of 1, 99.54 % (348.26 fps, avg 346.43 fps, ETA 00h00m00s)
Encoding: task 1 of 1, 99.54 % (348.26 fps, avg 346.43 fps, ETA 00h00m00s)
Encoding: task 1 of 1, 99.54 % (348.26 fps, avg 346.43 fps, ETA 00h00m00s)