@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 nigger :D v0.04 :AGAIN ECHO Calculating Duration and Bitrate for Input: "%~dpnx1"  ::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 Duration is: %DURATION% seconds - %BITRATE% kbps required to meet 3 MB limit. Min:  %MINBITS% kbps - Max:  %MAXBITS% kbps ECHO Converting %~1 to %BITRATE% kbps 10-bit VP9, 1st Pass 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 1st Pass Success ECHO Converting %~1 to 10-bit VP9, 2nd Pass 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 2nd Pass Success ECHO Deleting 2-Pass Log File DEL "%TMP%\%~n1_2pass-0.log" ECHO Finished Converting %~1 FOR /F "tokens=*" %%S IN ("%~pn1.out.webm") DO SET SIZE=%%~zS SET /A SIZEK=SIZE/1024 ECHO 10-bit VP9 WEBM: %~dpn1.out.webm Size: %SIZE% bytes / %SIZEK% KiB SET MAX=3145728 IF %SIZE% LSS %MAX% (ECHO %~n1.out.webm is under 3 MiB, libvpx obeyed. Please shitpost responsibly.) ELSE (ECHO %~n1.out.webm is over 3 MiB, fuck libvpx-vp9, fuck hiroshimoot, give us AV1 you wanker.) ECHO Probing Default Audio Track... 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 Extracting %AF% audio to %~n1.audio%AEXT% ffmpeg.exe -i "%~1" -map 0:a -c:a copy -hide_banner "%~pn1.audio%AEXT%" ECHO %AF% audio extracted to: %~dpn1.audio%AEXT% Size: who cares? SHIFT IF "%~1" == "" GOTO:FINISH GOTO:AGAIN :TRANSCODEAUDIO ECHO  ;_; %AF% audio detected. Transcoding using libopus using obnoxious autismo settings. 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 %AF% audio converted to: %~dpn1-opus.ogg Size: who cares? SHIFT IF "%~1" == "" GOTO:FINISH GOTO:AGAIN :FINISH ECHO  :) No additional files selected for conversion, please check the console for errors, if any. PAUSE