Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ECHO OFF
- SETLOCAL EnableExtensions EnableDelayedExpansion
- CHCP 65001
- ::v0.01 Initial Release
- ::v0.02 A few minutes after that, two missing quotes made it shit itself. You can now drag/drop multiple files at once.
- ::v0.03 2021-11-04 VP9! Hallelujah!
- ::v0.0? 2022-07-06 I forgor
- ::v0.04 2023-01-16 Rudimentary constrained bitrate mode
- :: Now won't overwrite input WEBMs, lol
- :: Resample obnoxiously using libsoxr to 48k if needed, convert to 128k opus using libopus for any non-MP3/AAC/OGG/OPUS sources
- :: Yes, that means you need ffmpeg compiled with --enable-libopus and --enable-libsoxr
- :: But you already compiled it with both, and --disable-encoder=opus/--disable-decoder=opus, amongst many other such substitutions...
- :: Right?
- ::For batch converting any FFMPEG compatible inputs to a VP9 WEBM that can be posted on 4chinz.
- ::Done - Implement bit-rate calculation using FFProbe to determine input length and required bitrate to meet 3MB limit.
- ::Done - Check for audio in input, demux to original format in appropriate container per FFProbe without re-encoding, without requiring user to determine appropriate container. Automatically transcode to opus for any formats other than m4a/mp3/ogg/opus
- ::Done: Fix non-ASCII UTF-8 filename parsing, using "CHCP 65001" to change codepage.
- ::To-Do: Prompt user if they want a soundpost.
- ::To-Do: Call catbox.moe API using pwsh.exe Invoke-WebRequest, upload sound
- ::Note: Probably requires userhash/registered account.
- ::To-Do: /wsg/ prompt -> adjust to 6 MB, allow direct audio copy if input is Vorbis, else re-encode and include.
- ECHO [97;46mnigger [93;46m:D [97;46mv0.04
- :AGAIN
- ECHO [97;45mCalculating Duration and Bitrate for Input:[96;45m "%~dpnx1" [0m
- ::Determines input duration using ffprobe, stores seconds value to duration variable.
- FOR /F %%I IN ('ffprobe.exe -v error -show_entries format^=duration -of default^=noprint_wrappers^=1:nokey^=1 "%~1"') do SET "DURATION=%%I"
- ::Determines required bitrate using [3 MiB * 1024 KiB/MiB * 8 kb/KiB] = 24576 kbit
- SET /A BITRATE = 24576 / DURATION
- SET /A MINBITS = BITRATE / 10
- SET /A MAXBITS = 11 * BITRATE / 10
- ECHO [97;45mDuration is:[96;45m %DURATION%[97;45m seconds -[96;45m %BITRATE%[97;45m kbps required to meet 3 MB limit. Min: [96;45m %MINBITS%[97;45m kbps - Max: [96;45m %MAXBITS%[97;45m kbps
- ECHO [97;44mConverting[95;44m %~1 [97;44mto[95;44m %BITRATE%[97;44m kbps 10-bit VP9, 1st Pass[0m
- ffmpeg.exe -i "%~1" -c:v libvpx-vp9 -pix_fmt yuv420p10le -colorspace bt709 -color_primaries bt709 -color_trc bt709 -quality good -auto-alt-ref 1 -arnr-maxframes 12 -lag-in-frames 24 -tile-rows 0 -tile-columns 1 -tune-content film -enable-tpl 1 -row-mt 1 -qcomp 0.80 -keyint_min 24 -g 240 -pass 1 -b:v %BITRATE%k -minrate %MINBITS%k -maxrate %MAXBITS%k -f rawvideo -passlogfile "%TMP%/%~n1_2pass" -an -sn -y -hide_banner NUL
- ECHO [97;42m1st Pass [93;42mSuccess[0m
- ECHO [97;44mConverting[95;44m %~1 [97;44mto 10-bit VP9, 2nd Pass[0m
- ffmpeg.exe -i "%~1" -c:v libvpx-vp9 -pix_fmt yuv420p10le -colorspace bt709 -color_primaries bt709 -color_trc bt709 -quality good -auto-alt-ref 1 -arnr-maxframes 12 -lag-in-frames 24 -tile-rows 0 -tile-columns 1 -tune-content film -enable-tpl 1 -row-mt 1 -qcomp 0.80 -keyint_min 24 -g 240 -pass 2 -b:v %BITRATE%k -minrate %MINBITS%k -maxrate %MAXBITS%k -passlogfile "%TMP%/%~n1_2pass" -an -sn -hide_banner "%~pn1.out.webm"
- ECHO [97;42m2nd Pass [93;42mSuccess[0m
- ECHO [91;44mDeleting[97;44m 2-Pass Log File[0m
- DEL "%TMP%\%~n1_2pass-0.log"
- ECHO [97;42mFinished Converting[93;42m %~1
- FOR /F "tokens=*" %%S IN ("%~pn1.out.webm") DO SET SIZE=%%~zS
- SET /A SIZEK=SIZE/1024
- ECHO [97;42m10-bit VP9 WEBM:[93;42m %~dpn1.out.webm [97;42mSize:[93;42m %SIZE%[97;42m bytes /[93;42m %SIZEK%[97;42m KiB[0m
- SET MAX=3145728
- IF %SIZE% LSS %MAX% (ECHO [97;46m%~n1.out.webm is[93;46m under 3 MiB[97;46m, libvpx obeyed.[93;46m Please shitpost responsibly.[0m) ELSE (ECHO [97;41m%~n1.out.webm is [93;41mover 3 MiB[97;41m, fuck libvpx-vp9, fuck hiroshimoot, give us AV1 you wanker.[0m)
- ECHO [97;45mProbing Default Audio Track...[0m
- FOR /F %%X IN ('ffprobe.exe -v error -select_streams a:0 -show_entries stream^=codec_name -of default^=noprint_wrappers^=1:nokey^=1 "%~1"') do SET "AF=%%X"
- SET AEXT=
- IF "%AF%" == "vorbis" SET "AEXT=.ogg"
- IF "%AF%" == "opus" SET "AEXT=.ogg"
- IF "%AF%" == "aac" SET "AEXT=.m4a"
- IF "%AF%" == "mp3" SET "AEXT=.mp3"
- IF [%AEXT%]==[] GOTO:TRANSCODEAUDIO
- ECHO [97;44mExtracting[93;44m %AF% [97;44maudio to[93;44m %~n1.audio%AEXT%[0m
- ffmpeg.exe -i "%~1" -map 0:a -c:a copy -hide_banner "%~pn1.audio%AEXT%"
- ECHO [93;42m%AF% [97;42maudio extracted to:[93;42m %~dpn1.audio%AEXT% [97;42mSize:[93;42m who cares?[0m
- SHIFT
- IF "%~1" == "" GOTO:FINISH
- GOTO:AGAIN
- :TRANSCODEAUDIO
- ECHO [97;43m ;_; [36;43m%AF% [97;43maudio detected. Transcoding using [36;43mlibopus[97;43m using obnoxious autismo settings.[0m
- ffmpeg.exe -i "%~1" -map 0:a -af aresample=resampler=soxr:dither_method=low_shibata:precision=33:cutoff=0.95:cheby=1 -ar 48000 -b:a 128k -c:a libopus -hide_banner "%~pn1-opus.ogg"
- ECHO [93;42m%AF% [97;42maudio converted to:[93;42m %~dpn1-opus.ogg [97;42mSize:[93;42m who cares?[0m
- SHIFT
- IF "%~1" == "" GOTO:FINISH
- GOTO:AGAIN
- :FINISH
- ECHO [93;46m :) [97;46mNo additional files selected for conversion, please check the console for errors, if any.[0m
- PAUSE
Add Comment
Please, Sign In to add comment