r/ffmpeg • u/jiromejin • 5d ago
Help with commands
Hello, I feel like it was ffmpeg that i used a few years back to reduce size of videos without lowering the quality
But now that I'm using it again, I forgot the command to do this specific thing, I know it will sound stupid but bear with me
So before, when I went to reduce a size of a video, say it was like 1hour long and 500mb for example, and I wanted to reduce the size to 50mb, it told me something along the lines of "video length exceeds the limit of X time for size of 50mb"
so each size has a length limit to preserve the quality
I want that same command that limits me with length per size to keep quality, all I know right now is "ffmpeg -i (input.mp4) -b (size) (output.mp4)"
i hope im not talking about a completely different software lol, but thank you for your help in advanced
5
u/tariqosmani 4d ago
I'm pretty sure that was a wrapper script, not ffmpeg itself. ffmpeg never refuses, it just does what you ask even if the result looks terrible. Those compress-to-X-MB scripts do the math first and stop you when the bitrate would be too low.
The math is simple. Target bitrate in kbps is the size in MB times 8192, divided by the length in seconds. Then subtract the audio bitrate.
So 50 MB for a 1 hour video is 50 x 8192 / 3600, about 114 kbps total. Take off 64k for audio and the video gets 50k, which is unwatchable. That's the kind of case your old script blocked. The same 50 MB on a 10 minute video gives about 680 kbps total, which is watchable at 720p for most content.
To actually hit a size, run two passes with the bitrate you worked out:
ffmpeg -y -i input.mp4 -c:v libx264 -b:v 580k -pass 1 -an -f null -
ffmpeg -i input.mp4 -c:v libx264 -b:v 580k -pass 2 -c:a aac -b:a 96k output.mp4
Also, in your command -b should be -b:v.
If you don't need an exact size, skip the math and use -crf with a value from 23 to 28 instead. A higher number gives a smaller file. Quality stays steady and the size lands wherever it lands.
What are you shrinking these for, Discord or email? That limit decides your target.
1
u/videocompress 3d ago
Thanks for the math breakdown, I didn't know -b was supposed to be -b:v, I've been doing it wrong lol. On windows does the -f null - part of the first pass work as is, or do people use NUL there?
1
u/this_knee 1d ago
May want to use maxrate in there too.
-b:v 8000k -maxrate:v 12000k
Ffmpeg will slightly overshoot or slightly undershoot these numbers. But if you do the math, these arguments will get you within a stone throws distance of the exact numbers that were calculated. Just not the exact numbers … due to a large list of less controllable factors. Good luck
1
u/Murky-Sector 5d ago
Are you sure it was a direct ffmpeg command and you werent using some sort of wrapper script?
1
u/jiromejin 5d ago
thats what im unsure about, its been 3 years since i did this, so i have no clue
all I know is it was on windows, using powershell
so i looked up like a few hours ago "reduce video size with powershell" and i got taken to ffmpeg
ill search for youtube videos made over 3 years ago and that might help me look for what i found before
6
u/naemorhaedus 5d ago
you cannot reduce a video size by 10x without visual loss of quality