I have a 2 seconds length 1920x1080 dimensions video and I want to size of the file to be 3Mb
I tried the method below:
const fileSize = 3000; // Kilobytes
const duration = 2; // Second
const videoBitRate = Math.round((fileSize * 8) / duration));
So videoBitRate is 12000 right now
Then I use Two-Pass encoding
ffmpeg -y -i input -c:v libx264 -preset medium -b:v 12000k -pass 1 -c:a aac -b:a 128k -f mp4 /dev/null && \
ffmpeg -i input -c:v libx264 -preset medium -b:v 12000k -pass 2 -c:a aac -b:a 128k output.mp4
Expecting file size: 3Mb
Actual file size: 2.6Mb
If I'd use a 35 seconds video,
videoBitRate = 685k
ffmpeg -y -i input -c:v libx264 -preset medium -b:v 685k -pass 1 -c:a aac -b:a 128k -f mp4 /dev/null && \
ffmpeg -i input -c:v libx264 -preset medium -b:v 685k -pass 2 -c:a aac -b:a 128k output.mp4
Expecting file size: 3Mb
Actual file size: 3.6Mb
What is the point I'm doing wrong?
Isn't there a more accurate way to calculate? Why are the results always different?