[FFmpeg-user] 2 pass CBR or VBR not really fixing the bitrate?

Manuel Tiglio tiglio at icloud.com
Mon Jul 31 22:14:47 EEST 2017


> On Jul 31, 2017, at 12:11 PM, Jonathan Baecker <jonbae77 at gmail.com> wrote:
> 
> Am 31.07.2017 um 20:52 schrieb Manuel Tiglio:
>> Hi Jonathan,
>> 
>> This helps
>> 
>>> Hi,
>>> how about this command?:
>>> 
>>> ffmpeg -i input.mp4 -c:v libx264 -x264-params "nal-hrd=cbr" -b:v 1M -minrate 1M -maxrate 1M -bufsize 2M
>>> 
>>> Source: https://trac.ffmpeg.org/wiki/Encode/H.264
>>> 
>> Will give it a try. I had seen in other forums discussing this same issued and that this should work, but ‘nal-hrd=cbr” only work for producing ts files. I was wondering if one could also control the bitrate prior to that, at the mp4 level.
>> 
>> Notice that in the documentation that you quote, just below this example, it says
>> 
>> Constained encoding (VBV / maximum bit rate) <https://trac.ffmpeg.org/wiki/Encode/H.264#ConstainedencodingVBVmaximumbitrate>
>> You can also use -crf or -b:v with a maximum bit rate by specifying both  -maxrate and -bufsize:
>> 
>> ffmpeg -i input -c:v libx264 -crf 23 -maxrate 1M -bufsize 2M output.mp4
>> This will effectively "target" -crf 23, but if the output were to exceed 1 MBit/s, the encoder would increase the CRF to prevent bitrate spikes. However, be aware that libx264does not strictly control the maximum bit rate as you specified (the maximum bit rate may be well over 1M for the above file). To reach a perfect maximum bit rate, use two-pass.
>> 
>> In another example, instead of using constant quality (CRF) as a target, the average bitrate is set. A two-pass approach is preferred here:
>> 
>> 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
>> 
>> And that, does not seem to work as advertised. That is, the two pass encoding still gives a max rate which is far from the specified target (1M in the above example).
>> 
>> Somebody must have gone through this before.
>> 
>> 
>>> Of course it needs a bit modification to fit your two pass encoding.
>> That would be fine. But ideally I would like to have the mp4 files with bitrate control before transmuxing, and keep those mp4 files in case they need to be reused for a number of reasons.
>> 
>>> You just worry about hls, or your really need to get this close persistence?
>>> Because we make life streaming with crf and maxrate/buffsize over hls and never had problems with it.
>> Interesting, as in above? Ie
>> 
>>> ffmpeg -i input.mp4 -c:v libx264 -x264-params "nal-hrd=cbr" -b:v 1M -minrate 1M -maxrate 1M -bufsize 2M
>> What does seem to work in ffmpeg is capped crf (in the sense that the obtained crf is close to the specified cap value), but then the lower bitrates are far from that cap and there is degradation in quality.
>> 
>> Ideally I would like to do 110% VBV, which changing the 2-pass example should be achieved by
>> 
>> 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 1.1M -bufsize 2M -pass 2 output.mp4
>> Or with a bufsize of 1M (one sec)
>> 
>> Thanks Jonathan, would you mind following up on my comments above? I really appreciate it.
>> 
>> Manuel
> Hi Manuel,
> I don't believe nal-hrd=cbr is only for ts, because it is a x264 parameter, not an ffmpeg paramter. And as I know x264 don't know ts, ts is just the container, or not?
> There is also a mode: nal-hrd=vbr, maybe this fills more your need, because you don't want 100% constant.

Thanks Jon, let me try that out and report back to you guys. You are right, I’d prefer 110% 

I had read that those parameters are for ts in fact in the example that you sent from that ffmpeg page it actually reads

ffmpeg -i input.mp4 -c:v libx264 -x264-params "nal-hrd=cbr" -b:v 1M -minrate 1M -maxrate 1M -bufsize 2M output.ts

But I will give it a shot. 


Manuel
> 
> Jonathan
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
> 
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".



More information about the ffmpeg-user mailing list