0

Looking at https://trac.ffmpeg.org/wiki/Encode/H.264:

I see this example as being the recommended method to target a bit rate for files meant for streaming

ffmpeg -i input -c:v libx264 -b:v 1M -maxrate 1M -bufsize 2M -pass 1 -f mp4 /dev/null
ffmpeg -i input -c:v libx264 -b:v 1M -maxrate 1M -bufsize 2M -pass 2 output.mp4

I encoded a file using a slightly variation here:

ffmpeg -i *mkv -c:v libx264 -b:v 2.5M -maxrate 2.5M -bufsize 5M -profile:v high -level 4.2 -pass 1 -an -f mp4 /dev/null -y \
ffmpeg -i *mkv -c:v libx264 -b:v 2.5M -maxrate 2.5M -bufsize 5M -profile:v high -level 4.2 -an -movflags +faststart -pass 2 output.mp4

I see that sometimes it's uses a bitrate of 1.800 kbits/s but where does it get that?

Is it using some kind of default CRF value or what?

Does setting a -preset slow would increase the quality further?

1

think of it this way, your driving a car, and you have a target speed of 25, and a max speed limit of 25. Then you stop at a red light for 30 seconds and your average speed drops to 20. It is now impossible to reach an average of 25 again without going over the max. you would need to drive at the max speed an infinite amount of time to get the average back to 25.

When encoding the video, the encoder reached a frame that took less bits to encode than average (low spacial or temporal information. For example two identical frames), so bitrate temporarily dipped, and now it can never reach max.

What you need is a way to say, if we drop below average, we are able to go over max for a small period of time to bring the average back up. This is called “vbv” and you should use that if you want to target a bitrate.

  • But how does it calculate a value for the bitrate? How can the encoder find that a frame needs less bit to encode than average, unless comparing it to a CRF value? – Freedo Sep 8 at 18:00
  • It doesn’t know. It guesses. The process called “rate control” is not part of the specification, and every implementation is free to develop its own algorithm. But the gist, is that given a “bit reservoir” it guess how much will be needed for the next frame/macroblock. It then encodeds it, then checks if it was rite or wrong, than adjusts it guess for the next frame/macroblock. – SlimSCSI Sep 8 at 18:06
  • I'm using ffmpeg libx264 btw. Does using a -preset slow achieves higher quality? And how is encoding like this better than a single pass cbr at say 2.5 Mbps? – Freedo Sep 8 at 18:13
  • If you have more questions. Please make a new post. – SlimSCSI Sep 10 at 0:29
  • ok I have another question related to this one. What if I don't set a average value? What if I don't care about the average values as long it's under X maximum? – Freedo Sep 10 at 5:46

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.