I recently have a need to down-size of mp4 file in order to be able to upload it to a web page. The upload limit of the web page is 32M where the size of my mp4 file is about 200+M. I found out that I can use ffmpeg to re-compress the file with a smaller bit rate in order to down-size the file. The only problem is what bit rate to use. The command I used is as follows:
ffmpeg -i original.mp4 -b:v 126k -b:a 64k output.mp4
As you can see, I can control both the video bit rate and audio bit rate separately. After a few tests I eventually find our how to do the math. Given the length of my video is 22:49. The total bit rate is calculated as follows:
Total bit rate = (target file size / duration) * 8 = (32 * 1024 * 1024) / (22 * 60 + 49) * 8 = 196081 = 191k
In other words, my maximum bit rate should be 191k, this is the combined total bit rate for both video and audio. Thus, I can select different combination of video and audio bit rate as long as they sum is within 191k. In the above example, I use 126k for video and 64k of audio, the result file is 33,414,347 bytes (of 31.9M) long. Good enough for me.