10

I am using ffmpeg to encode my videos to upload them on the web. I saw this post about using ffmpeg, but didn't quite get as to how to consider the values.

Suppose I have a video of size 70 MB with a duration of 4 minutes. How would I consider the value for these flags : -b:v, -maxrate and -bufsize for this command?

ffmpeg -i input -codec:v libx264 -profile:v main -preset slow -b:v ? -maxrate ? -bufsize ? -vf "scale=720:trunc(ow/a/2)*2" -threads 0 -codec:a libfdk_aac -movflags +faststart output

Or is there any normal value, like for the crf values are 19-24? I would really appreciate your help and guidance.

  • Video encoding is an art, and there are hundreds of parameters to master. Notice that two-pass encoding will offer (much) better quality and compression in most scenarios than playing with bitrates. Ussually the final size and video bitrate depends mainly on the video output size. ffmpeg is ussually smart enough to choose maxrate and bitrate if you tell it to keep the same video quality. Notice also that creating a 480px width video is good enough in most scenarios, and that will save much more bandwidth that playing with bitrates. – earizon Jul 28 '15 at 15:14
  • 1
    @earizon I agree, video encoding is an art and 480 is usually good enough. However, I also like having higher resolutions available because I don't use a CRT at 640x480 anymore. It is definitely a better way to reduce sizes than fiddling with bitrates, but again, I like options. – Wyatt8740 Aug 9 '15 at 3:45
16
+25

It really depends on your upload speed.

bufsize will determine how religious ffmpeg is about keeping your bitrate constant. If you set a bufsize of 64k, as per FFmpeg Wiki: Limiting the output bitrate, it will calculate its current bitrate every 64 kilobytes and adjust accordingly. Smaller sizes for bufsize can be harmful to quality in that they don't allow enough space between checks for x264 to do sudden changes - you will get blockiness.

If your maxrate is 640kbps, and your bufsize is 64k, then every tenth of a second x264 would check. This is sub-optimal - FFmpeg Wiki: Encoding for streaming sites recommends to run it every 1 to 2 seconds. If this didn't make sense, think of it as maxrate/bufsize = frequency of checks. Keep this frequency between 1 and 2 seconds as a rule of thumb.

If you set both maxrate and bufsize, you should:

  • set maxrate to whatever your lowest upload speed will likely be (in the ffmpeg wiki example, this is 80% of total upload speed, but your mileage may vary).
  • set bufsize to somewhere between the same as your maxrate (one second) and twice of your maxrate (2 seconds). If this is still not low enough, lower your maxrate and then re-set bufsize accordingly.

Then, you'll have to play around a bit, but since you have to start somewhere I'd just start at a maxrate around 600k, which was usually satisfying enough for me back before I used crf for everything.

If you'd like, you can try lower values for bufsize, like for every three or four seconds, just to see how the value changes how your output looks. Then you can determine how much you should worry about it for your video.

There is no normal value, really - what crf does is to optimize output based on what it thinks is the best buffer size for maintaining whatever it's rate is set at. It tries to keep as low a file size while maintaining some quality, at the cost of occasional spikes.

  • 1
    Shouldn't "set bufsize to somewhere between the same as your maxrate (one second) and half of your maxrate (2 seconds)" be "set bufsize to somewhere between the same as your maxrate (one second) and twice your maxrate (2 seconds)" ? – Ely Jul 28 '15 at 19:24
  • @Ely I think you are right. Mine would do it every half second. I'll fix that! – Wyatt8740 Jul 30 '15 at 3:33
  • @Wyatt8740 Sorry, I was very busy. Just one question though. If I use crf, then I don't need to specify bitrate, buffsize and maxrate? And if so, which is more efficient (use crf or bitrate, buffsize and maxrate)? – Robin Aug 2 '15 at 15:31
  • @Robin You can use bufsize and maxrate with crf. Remember, crf will adjust bitrate on the fly to match a certain quality, and if parts of the video are very complex, the bitrate will shoot sky-high and you probably don't want that, so better "put a lock" with bufsize and maxrate (but not too strict, or you video will look like crap ! :) ) – Ely Aug 5 '15 at 1:03
  • @Robin correct, you shouldn't need to use crf with the others. However, you can if you want to constrain it. crf tries to maintain constant quality - you can force it to do so within limits with bufsize and maxrate. You do not need bitrate, though. As Ely said, it will make it better for streaming. – Wyatt8740 Aug 5 '15 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.