Last active
January 17, 2026 14:57
-
-
Save eladkarako/18e0d34cf3402c5e31a98b1f82107b62 to your computer and use it in GitHub Desktop.
run to auto loop all videos in a folder. takes a lot of time (you can copy audio to speed it up).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ::@echo off | |
| chcp 65001 1>nul 2>nul | |
| for %%a in (*.mkv *.mp4) do ( | |
| call :PROCEDURE_DELETE_THUMBNAIL "%%a" | |
| call :PROCEDURE_FFMPEG "%%a" | |
| ) | |
| goto :END | |
| ::---------------------------------------------------- | |
| :PROCEDURE_DELETE_THUMBNAIL | |
| pushd "%~dp1" | |
| "mkvpropedit.exe" --verbose "%~1" --delete-attachment "mime-type:image/jpg" | |
| "mkvpropedit.exe" --verbose "%~1" --delete-attachment "mime-type:image/jpeg" | |
| "mkvpropedit.exe" --verbose "%~1" --delete-attachment "mime-type:image/png" | |
| "mkvpropedit.exe" --verbose "%~1" --delete-attachment "mime-type:image/webp" | |
| timeout /t 2 | |
| popd | |
| goto :eof | |
| :PROCEDURE_FFMPEG | |
| pushd "%~dp1" | |
| mkdir "output" 1>nul 2>nul | |
| set "ARGS_PRE=" | |
| ::set ARGS_PRE=%ARGS_PRE% -hide_banner | |
| ::set ARGS_PRE=%ARGS_PRE% -stats | |
| ::set ARGS_PRE=%ARGS_PRE% -loglevel "verbose" | |
| ::set ARGS_PRE=%ARGS_PRE% -loglevel "error+repeat" | |
| set ARGS_PRE=%ARGS_PRE% -loglevel "info" | |
| set ARGS_PRE=%ARGS_PRE% -strict experimental | |
| set ARGS_PRE=%ARGS_PRE% -err_detect "ignore_err" | |
| set ARGS_PRE=%ARGS_PRE% -y | |
| set ARGS_PRE=%ARGS_PRE% -flags "+cgop+loop-unaligned-output_corrupt" | |
| set ARGS_PRE=%ARGS_PRE% -fflags "+genpts+autobsf+discardcorrupt+igndts+ignidx" | |
| set ARGS_PRE=%ARGS_PRE% -probesize "800M" | |
| set ARGS_PRE=%ARGS_PRE% -analyzeduration "600M" | |
| set ARGS_PRE=%ARGS_PRE% -thread_queue_size 16384 | |
| set ARGS_PRE=%ARGS_PRE% -copy_unknown | |
| set ARGS_PRE=%ARGS_PRE% -threads 2 | |
| set ARGS_PRE=%ARGS_PRE% -max_interleave_delta 0 | |
| set ARGS_PRE=%ARGS_PRE% -use_wallclock_as_timestamps 1 | |
| set ARGS_PRE=%ARGS_PRE% -i "%~nx1" | |
| set "ARGS_STEP1=" | |
| set ARGS_STEP1=%ARGS_STEP1% -map "0:v:0" | |
| set ARGS_STEP1=%ARGS_STEP1% -preset ultrafast | |
| set "ARGS_STEP2=" | |
| set ARGS_STEP2=%ARGS_STEP2% -map 0 | |
| set ARGS_STEP2=%ARGS_STEP2% -map "-0:v" | |
| set ARGS_STEP2=%ARGS_STEP2% -map "0:v:0" | |
| set ARGS_STEP2=%ARGS_STEP2% -map "-0:a" | |
| set ARGS_STEP2=%ARGS_STEP2% -map "0:a:m:language:eng" | |
| set ARGS_STEP2=%ARGS_STEP2% -preset veryslow | |
| set "ARGS_POST=" | |
| set ARGS_POST=%ARGS_POST% "-c:v" libx264 | |
| set ARGS_POST=%ARGS_POST% "-c:s" copy | |
| set ARGS_POST=%ARGS_POST% "-c:t" copy | |
| set ARGS_POST=%ARGS_POST% "-c:d" copy | |
| set ARGS_POST=%ARGS_POST% "-c:a" copy | |
| ::set ARGS_POST=%ARGS_POST% "-c:a" aac | |
| ::set ARGS_POST=%ARGS_POST% "-b:a" "192k" | |
| ::set ARGS_POST=%ARGS_POST% "-minrate:a" "192k" | |
| ::set ARGS_POST=%ARGS_POST% "-maxrate:a" "192k" | |
| ::set ARGS_POST=%ARGS_POST% "-bufsize:a" "256k" | |
| ::set ARGS_POST=%ARGS_POST% -ar 48000 | |
| ::set ARGS_POST=%ARGS_POST% -ac 2 | |
| ::set ARGS_POST=%ARGS_POST% -joint_stereo 1 | |
| ::set ARGS_POST=%ARGS_POST% -abr 0 | |
| ::---------------------------------------- 23.97602397602398 | |
| set ARGS_POST=%ARGS_POST% -r "24000/1001" | |
| set ARGS_POST=%ARGS_POST% -g 48 | |
| set ARGS_POST=%ARGS_POST% -keyint_min 24 | |
| set ARGS_POST=%ARGS_POST% -x264opts "no-cabac:no-deblock:no-weightb:weightp=0" | |
| set ARGS_POST=%ARGS_POST% -x264opts "b-adapt=2:rc-lookahead=90" | |
| set ARGS_POST=%ARGS_POST% -x264opts "aq-mode=3:aq-strength=1.50:fast-pskip=0:me=tesa:merange=92:psy-rd=2.00:qcomp=0.65:ref=4:subme=11:trellis=2" | |
| ::set ARGS_POST=%ARGS_POST% -x264opts "mixed-ref=1:psy-rdoq=4.00" | |
| set ARGS_POST=%ARGS_POST% -tune fastdecode | |
| set ARGS_POST=%ARGS_POST% -ignore_editlist 1 | |
| set ARGS_POST=%ARGS_POST% -use_editlist 0 | |
| set ARGS_POST=%ARGS_POST% -intra-refresh 1 | |
| set ARGS_POST=%ARGS_POST% -bluray-compat 1 | |
| set ARGS_POST=%ARGS_POST% -pix_fmt yuv420p | |
| set ARGS_POST=%ARGS_POST% -movflags "+faststart" | |
| set ARGS_POST=%ARGS_POST% "-profile:v" high | |
| set ARGS_POST=%ARGS_POST% -level "4.1" | |
| set ARGS_POST=%ARGS_POST% -refs 4 | |
| set ARGS_POST=%ARGS_POST% "-bf:v" 4 | |
| set ARGS_POST=%ARGS_POST% "-b:v" 1500k | |
| set ARGS_POST=%ARGS_POST% -maxrate 1500k | |
| set ARGS_POST=%ARGS_POST% -bufsize 6000k | |
| set ARGS_POST=%ARGS_POST% -avoid_negative_ts make_zero | |
| set ARGS_POST=%ARGS_POST% -map_metadata 0 | |
| set ARGS_POST=%ARGS_POST% -vsync cfr | |
| set ARGS_POST=%ARGS_POST% -fps_mode cfr | |
| set ARGS_POST=%ARGS_POST% -passlogfile "ffmpeg_%~n1_log" | |
| ::set ARGS_POST=%ARGS_POST% -to "00:00:01.000" | |
| del /f /q "ffmpeg_%~n1_log*.*" 1>nul 2>nul | |
| :: ffmpeg %ARGS% -pass 1 -f null nul | |
| :: ffmpeg %ARGS% -pass 2 "./output/%~n1.mkv" | |
| :: powershell -Command "wget.exe --no-config --config=wget_config.txt --input-file=wget_links.txt | Tee-Object -Append -FilePath '--_%TIMESTAMP%_wget_log.txt'" | |
| title 1 - %~sn1 | |
| start "%~sn1" /b /wait /min /low ffmpeg %ARGS_PRE% %ARGS_STEP1% %ARGS_POST% -pass 1 -f null nul | |
| title 2 - %~sn1 | |
| start "%~sn1" /b /wait /min /low ffmpeg %ARGS_PRE% %ARGS_STEP2% %ARGS_POST% -pass 2 "./output/%~n1.mkv" | |
| del /f /q "ffmpeg_%~n1_log*.*" 1>nul 2>nul | |
| timeout /t 5 | |
| popd | |
| goto :eof | |
| ::------------------------------------------------------------------ | |
| :END | |
| pause | |
| exit /b 0 | |
| ::---------------------------------------------------------------------------- | |
| :: note: | |
| :: - you can uncomment the audio encoding if your format is not AAC already. | |
| :: - optional - it selects just the audio that is tagged "English"/eng. you can choose to comment that if you want to copy all audio streams. | |
| :: - it pre-removes all PNG/JPG/JPEG/WEBM attachments using MKV tools. ffmpeg selects just the first video. this helps to avoid thumbnail. | |
| :: - it uses large RAM, two steps, a lot of look-ahead frames to improve compression with same quality, it uses 2 thread to reduce cpu, it uses start and low cpu instruction to reduce cpu load and noise. best to work in background. | |
| :: - it uses 3times playing cache as compatible format to allow smooth playing. | |
| :: - quality note: bad on fast scenes! that is due to limitation of bitrate. you can use -crf 18 and instead. but with this most 40 min. shows are about 300mb.. with very good quality on normal scenes. | |
| :: - muxer in step 1, only gets video, asap. | |
| ::---------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment