Skip to content

Instantly share code, notes, and snippets.

@elkhadiy
Created March 23, 2021 00:49
Show Gist options
  • Save elkhadiy/2f11cb8561cc3d7c76acd08f84b587b8 to your computer and use it in GitHub Desktop.
Save elkhadiy/2f11cb8561cc3d7c76acd08f84b587b8 to your computer and use it in GitHub Desktop.
needs ffmpeg and ffprobe on path or same folder (there are handy windows static builds on their website), then just drag'n'drop video file on it and let it crunch away
@ECHO off
CD /D %~p0
SET output=%~n1_8MB.mp4
FOR /F "usebackq" %%i in (`ffprobe -i %1 -show_entries format^=duration -v quiet -of csv^="p=0"`) do set seconds=%%i
SET /A "totalBitrate=64000/seconds"
SET overheadBitrate=100
SET audioBitrate=96
SET /A "videoBitrate=totalBitrate-audioBitrate-overheadBitrate"
ffmpeg -hide_banner -y -i %1 -c:v libx264 -b:v %videoBitrate%k -pass 1 -b:a %audioBitrate%k -f mp4 NUL && \
ffmpeg -hide_banner -i %1 -c:v libx264 -b:v %videoBitrate%k -pass 2 -b:a %audioBitrate%k "%output%"
DEL /q ffmpeg2pass-*.log ffmpeg2pass-*.mbtree
PAUSE
@elkhadiy
Copy link
Author

changed one line from this: https://www.etdofresh.com/ffmpeg-your-videos-to-8mb-in-windows-for-discord-use/
replaced the duration input by a call to ffprobe
(crazy how mindbogglingly hilariously awful the hack is to basically put a command output into a variable. wtf. like holyfucking shit. https://devblogs.microsoft.com/oldnewthing/20120731-00/?p=7003 <- life saver)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment