<p>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. </p>

<p>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. </p>

<p>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. </p>

CC BY-SA 4.0
2019-09-08T18:00:21.423Z
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
CC BY-SA 4.0
2019-09-08T18:06:11.427Z
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
CC BY-SA 4.0
2019-09-08T18:13:07.457Z
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
CC BY-SA 4.0
2019-09-10T00:29:45.767Z
If you have more questions. Please make a new post.
SlimSCSI
CC BY-SA 4.0
2019-09-10T05:46:35.580Z
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
CC BY-SA 4.0
2019-09-10T06:04:20.837Z
One question per post please.
SlimSCSI
CC BY-SA 4.0
2019-09-08T16:41:27.283Z
2019-09-08T16:41:27.283Z
SlimSCSI
<p>Looking at <a href="https://trac.ffmpeg.org/wiki/Encode/H.264" rel="nofollow noreferrer">https://trac.ffmpeg.org/wiki/Encode/H.264</a>: </p>

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

<pre><code>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
</code></pre>

<p>I encoded a file using a slightly variation here:</p>

<pre><code>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
</code></pre>

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

<p>Is it using some kind of default CRF value or what?</p>

<p>Does setting a -<code>preset slow</code> would increase the quality further? </p>

<ffmpeg>
What determines the chosen bitrate with ffmpeg constrained encoding example?
Freedo
# What determines the chosen bitrate with ffmpeg constrained encoding example?

(Asked by: username_0 on 2019-09-08)

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?

**Tags:** ffmpeg


---

## 1 answers

### Answer by username_1 on 2019-09-08. Score: 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.

> **Comments:**
> **username_0**: 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?  
> **username_1**: 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.  
> **username_0**: 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?  
> **username_1**: If you have more questions. Please make a new post.  
> **username_0**: 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?  
> **username_1**: One question per post please.  

---

