Does constant bitrate exist in libx264

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Does constant bitrate exist in libx264

FFmichael
I have finally got my stream grapher working with FFprobe/gnuplot and what it has shown me so far is what I have been suspecting.....

I cannot achieve a constant bitrate using libx264 with any rate control method.

I have tried -b (including -bt, -maxrate, -minrate), -crf and -cqp all of which produce VBR output.

Check out my -b (1-pass and 2-pass) examples here: http://forums.creativecow.net/readpost/291/81
Here are the -crf and -cqp examples: http://forums.creativecow.net/readpost/291/85

It kind of makes sense but am just wondering if there is something I am missing with the whole 'definition' of CBR in relation to AVC.

Michael
Reply | Threaded
Open this post in threaded view
|

Re: Does constant bitrate exist in libx264

Frederik Dam Sunne
> I have finally got my stream grapher working with FFprobe/gnuplot and what it
> has shown me so far is what I have been suspecting.....
>
> I cannot achieve a constant bitrate using libx264 with any rate control
> method.

Have you tried with both -b and -bt ?

I do this for constant bitrate in windows:

ffmpeg.exe -i "input.mov" -s 620x348 -an -pass 1 -vcodec libx264
-aspect 16:9 -vpre "C:\ffmpeg\libx264-medium_firstpass.ffpreset" -b 1M
-bt 1M -threads 2 -y NUL

ffmpeg.exe -i "input.mov" -s 620x348 -an -pass 2 -vcodec libx264
-aspect 16:9 -vpre "C:\ffmpeg\ffpresets\libx264-medium.ffpreset" -b 1M
-bt 1M -threads 2 -y temp.m4v

Or at least, I thought it was constant - can you test the above lines?

Regards,

Frederik
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Does constant bitrate exist in libx264

FFmichael
Frederik Dam Sunne wrote
> I have finally got my stream grapher working with FFprobe/gnuplot and what it
> has shown me so far is what I have been suspecting.....
>
> I cannot achieve a constant bitrate using libx264 with any rate control
> method.

Have you tried with both -b and -bt ?

I do this for constant bitrate in windows:

ffmpeg.exe -i "input.mov" -s 620x348 -an -pass 1 -vcodec libx264
-aspect 16:9 -vpre "C:\ffmpeg\libx264-medium_firstpass.ffpreset" -b 1M
-bt 1M -threads 2 -y NUL

ffmpeg.exe -i "input.mov" -s 620x348 -an -pass 2 -vcodec libx264
-aspect 16:9 -vpre "C:\ffmpeg\ffpresets\libx264-medium.ffpreset" -b 1M
-bt 1M -threads 2 -y temp.m4v

Or at least, I thought it was constant - can you test the above lines?
I made this command line which is identical to yours:

ffmpeg -i funny_bubbles.mov -s 620x348 -an -pass 1 -vcodec libx264 -aspect 16:9 -vpre medium_firstpass -b 1M -bt 1M -threads 2 -y tmpfile.m4v && ffmpeg -i funny_bubbles.mov -s 620x348 -an -pass 2 -vcodec libx264 -aspect 16:9 -vpre medium -b 1M -bt 1M -threads 2 -y temp.m4v

The result is not constant bitrate.


kb/s:996.69
frame I:4     Avg QP:16.28  size: 12850
frame P:345   Avg QP:22.61  size:  7690
frame B:551   Avg QP:25.48  size:  3232
(as reported by FFmpeg)

CBR may not mean constant bitrate me thinks.
This encode also shows some strange B-frame behavior at the start and towards the end.
The footage is the same as posted on the previous links.

I like the cryptic descriptions on the FFmpeg FAQ in regards to this:
3.19 I want CBR, but no matter what I do frame sizes differ.
You do not understand what CBR is, please read the MPEG spec. Read about video buffer verifier and constant bitrate. The one sentence summary is that there is a buffer and the input rate is constant, the output can vary as needed.
3.20 How do I check if a stream is CBR?
To quote the MPEG-2 spec: "There is no way to tell that a bitstream is constant bitrate without examining all of the vbv_delay values and making complicated computations."

So what is CBR?

Michael


Reply | Threaded
Open this post in threaded view
|

Re: Does constant bitrate exist in libx264

Henk D. Schoneveld
FFmichael wrote:

>
> Frederik Dam Sunne wrote:
>>> I have finally got my stream grapher working with FFprobe/gnuplot and
>>> what it
>>> has shown me so far is what I have been suspecting.....
>>>
>>> I cannot achieve a constant bitrate using libx264 with any rate control
>>> method.
>> Have you tried with both -b and -bt ?
>>
>> I do this for constant bitrate in windows:
>>
>> ffmpeg.exe -i "input.mov" -s 620x348 -an -pass 1 -vcodec libx264
>> -aspect 16:9 -vpre "C:\ffmpeg\libx264-medium_firstpass.ffpreset" -b 1M
>> -bt 1M -threads 2 -y NUL
>>
>> ffmpeg.exe -i "input.mov" -s 620x348 -an -pass 2 -vcodec libx264
>> -aspect 16:9 -vpre "C:\ffmpeg\ffpresets\libx264-medium.ffpreset" -b 1M
>> -bt 1M -threads 2 -y temp.m4v
>>
>> Or at least, I thought it was constant - can you test the above lines?
>>
>>
>
> I made this command line which is identical to yours:
>
> ffmpeg -i funny_bubbles.mov -s 620x348 -an -pass 1 -vcodec libx264 -aspect
> 16:9 -vpre medium_firstpass -b 1M -bt 1M -threads 2 -y tmpfile.m4v && ffmpeg
> -i funny_bubbles.mov -s 620x348 -an -pass 2 -vcodec libx264 -aspect 16:9
> -vpre medium -b 1M -bt 1M -threads 2 -y temp.m4v
>
> The result is not constant bitrate.
>
> http://ffmpeg-users.933282.n4.nabble.com/file/n2255686/2passtest2.jpg 
> kb/s:996.69
> frame I:4     Avg QP:16.28  size: 12850
> frame P:345   Avg QP:22.61  size:  7690
> frame B:551   Avg QP:25.48  size:  3232
> (as reported by FFmpeg)
Bitrate is specified as amount of bits per second.
In 1 second you'll have an amount of I P and B-frames, depending on the
chosen GOP-size. So you'll have to sum xI + yP + zB and devide by the
total of frames. You'll the average, if this is the same for 'every'
second, you've got CBR.
At least that is what I'm thinking it is.

>
> CBR may not mean constant bitrate me thinks.
> This encode also shows some strange B-frame behavior at the start and
> towards the end.
> The footage is the same as posted on the previous links.
>
> I like the cryptic descriptions on the FFmpeg FAQ in regards to this:
> 3.19 I want CBR, but no matter what I do frame sizes differ.
> You do not understand what CBR is, please read the MPEG spec. Read about
> video buffer verifier and constant bitrate. The one sentence summary is that
> there is a buffer and the input rate is constant, the output can vary as
> needed.
> 3.20 How do I check if a stream is CBR?
> To quote the MPEG-2 spec: "There is no way to tell that a bitstream is
> constant bitrate without examining all of the vbv_delay values and making
> complicated computations."
>
> So what is CBR?
>
> Michael
>
>
>

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Does constant bitrate exist in libx264

FFmichael
belcampo wrote
FFmichael wrote:
>
> Frederik Dam Sunne wrote:
>>> I have finally got my stream grapher working with FFprobe/gnuplot and
>>> what it
>>> has shown me so far is what I have been suspecting.....
>>>
>>> I cannot achieve a constant bitrate using libx264 with any rate control
>>> method.
>> Have you tried with both -b and -bt ?
>>
>> I do this for constant bitrate in windows:
>>
>> ffmpeg.exe -i "input.mov" -s 620x348 -an -pass 1 -vcodec libx264
>> -aspect 16:9 -vpre "C:\ffmpeg\libx264-medium_firstpass.ffpreset" -b 1M
>> -bt 1M -threads 2 -y NUL
>>
>> ffmpeg.exe -i "input.mov" -s 620x348 -an -pass 2 -vcodec libx264
>> -aspect 16:9 -vpre "C:\ffmpeg\ffpresets\libx264-medium.ffpreset" -b 1M
>> -bt 1M -threads 2 -y temp.m4v
>>
>> Or at least, I thought it was constant - can you test the above lines?
>>
>>
>
> I made this command line which is identical to yours:
>
> ffmpeg -i funny_bubbles.mov -s 620x348 -an -pass 1 -vcodec libx264 -aspect
> 16:9 -vpre medium_firstpass -b 1M -bt 1M -threads 2 -y tmpfile.m4v && ffmpeg
> -i funny_bubbles.mov -s 620x348 -an -pass 2 -vcodec libx264 -aspect 16:9
> -vpre medium -b 1M -bt 1M -threads 2 -y temp.m4v
>
> The result is not constant bitrate.
>
> http://ffmpeg-users.933282.n4.nabble.com/file/n2255686/2passtest2.jpg 
> kb/s:996.69
> frame I:4     Avg QP:16.28  size: 12850
> frame P:345   Avg QP:22.61  size:  7690
> frame B:551   Avg QP:25.48  size:  3232
> (as reported by FFmpeg)
Bitrate is specified as amount of bits per second.
In 1 second you'll have an amount of I P and B-frames, depending on the
chosen GOP-size. So you'll have to sum xI + yP + zB and devide by the
total of frames. You'll the average, if this is the same for 'every'
second, you've got CBR.
At least that is what I'm thinking it is.
This is clearly not the case with the examples I have posted.

I looked into it a bit more and:

"The decoder's buffer is filled over time at a constant data rate in the case of CBR, and at a non-constant rate in the case of VBR. In both cases, data is removed from the buffer in varying chunks, depending on the actual size of the coded frames.
In the H.264 and VC-1 standards, the VBV is replaced with generalized version called Hypothetical Reference Decoder (HRD)."
http://en.wikipedia.org/wiki/Video_buffering_verifier

Can anyone explain the term "Hypothetical Reference Decoder (HRD)" as it relates to CBR and VBR?

Michael
Reply | Threaded
Open this post in threaded view
|

Re: Does constant bitrate exist in libx264

William FREE
In reply to this post by FFmichael
FFmichael wrote:

>
> belcampo wrote:
> >
> > FFmichael wrote:
> >>
> >> Frederik Dam Sunne wrote:
> >>>> I have finally got my stream grapher working with FFprobe/gnuplot
> and
> >>>> what it
> >>>> has shown me so far is what I have been suspecting.....
> >>>>
> >>>> I cannot achieve a constant bitrate using libx264 with any rate
> control
> >>>> method.
> >>> Have you tried with both -b and -bt ?
> >>>
> >>> I do this for constant bitrate in windows:
> >>>
> >>> ffmpeg.exe -i "input.mov" -s 620x348 -an -pass 1 -vcodec libx264
> >>> -aspect 16:9 -vpre "C:\ffmpeg\libx264-medium_firstpass.ffpreset" -b
> 1M
> >>> -bt 1M -threads 2 -y NUL
> >>>
> >>> ffmpeg.exe -i "input.mov" -s 620x348 -an -pass 2 -vcodec libx264
> >>> -aspect 16:9 -vpre "C:\ffmpeg\ffpresets\libx264-medium.ffpreset" -b
> 1M
> >>> -bt 1M -threads 2 -y temp.m4v
> >>>
> >>> Or at least, I thought it was constant - can you test the above
> lines?
> >>>
> >>>
> >>
> >> I made this command line which is identical to yours:
> >>
> >> ffmpeg -i funny_bubbles.mov -s 620x348 -an -pass 1 -vcodec libx264
> >> -aspect
> >> 16:9 -vpre medium_firstpass -b 1M -bt 1M -threads 2 -y tmpfile.m4v
> &&
> >> ffmpeg
> >> -i funny_bubbles.mov -s 620x348 -an -pass 2 -vcodec libx264 -aspect
> 16:9
> >> -vpre medium -b 1M -bt 1M -threads 2 -y temp.m4v
> >>
> >> The result is not constant bitrate.
> >>
> >> http://ffmpeg-
> users.933282.n4.nabble.com/file/n2255686/2passtest2.jpg
> >> kb/s:996.69
> >> frame I:4     Avg QP:16.28  size: 12850
> >> frame P:345   Avg QP:22.61  size:  7690
> >> frame B:551   Avg QP:25.48  size:  3232
> >> (as reported by FFmpeg)
> > Bitrate is specified as amount of bits per second.
> > In 1 second you'll have an amount of I P and B-frames, depending on
> the
> > chosen GOP-size. So you'll have to sum xI + yP + zB and devide by the
> > total of frames. You'll the average, if this is the same for 'every'
> > second, you've got CBR.
> > At least that is what I'm thinking it is.
> >
>
> This is clearly not the case with the examples I have posted.
>
> I looked into it a bit more and:
>
> "The decoder's buffer is filled over time at a constant data rate in
> the
> case of CBR, and at a non-constant rate in the case of VBR. In both
> cases,
> data is removed from the buffer in varying chunks, depending on the
> actual
> size of the coded frames.
> In the H.264 and VC-1 standards, the VBV is replaced with generalized
> version called Hypothetical Reference Decoder (HRD)."
> http://en.wikipedia.org/wiki/Video_buffering_verifier
> http://en.wikipedia.org/wiki/Video_buffering_verifier
>
> Can anyone explain the term "Hypothetical Reference Decoder (HRD)" as
> it
> relates to CBR and VBR?
>
> Michael
> --

I'm still studying the details myself, but an in-depth explanation can be found at http://research.microsoft.com/apps/pubs/default.aspx?id=77633.

Cliff

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Does constant bitrate exist in libx264

Jason Garrett-Glaser
In reply to this post by FFmichael
On Tue, Jun 15, 2010 at 3:40 AM, FFmichael <[hidden email]> wrote:

>
>
> Frederik Dam Sunne wrote:
>>
>>> I have finally got my stream grapher working with FFprobe/gnuplot and
>>> what it
>>> has shown me so far is what I have been suspecting.....
>>>
>>> I cannot achieve a constant bitrate using libx264 with any rate control
>>> method.
>>
>> Have you tried with both -b and -bt ?
>>
>> I do this for constant bitrate in windows:
>>
>> ffmpeg.exe -i "input.mov" -s 620x348 -an -pass 1 -vcodec libx264
>> -aspect 16:9 -vpre "C:\ffmpeg\libx264-medium_firstpass.ffpreset" -b 1M
>> -bt 1M -threads 2 -y NUL
>>
>> ffmpeg.exe -i "input.mov" -s 620x348 -an -pass 2 -vcodec libx264
>> -aspect 16:9 -vpre "C:\ffmpeg\ffpresets\libx264-medium.ffpreset" -b 1M
>> -bt 1M -threads 2 -y temp.m4v
>>
>> Or at least, I thought it was constant - can you test the above lines?
>>
>>
>
> I made this command line which is identical to yours:
>
> ffmpeg -i funny_bubbles.mov -s 620x348 -an -pass 1 -vcodec libx264 -aspect
> 16:9 -vpre medium_firstpass -b 1M -bt 1M -threads 2 -y tmpfile.m4v && ffmpeg
> -i funny_bubbles.mov -s 620x348 -an -pass 2 -vcodec libx264 -aspect 16:9
> -vpre medium -b 1M -bt 1M -threads 2 -y temp.m4v
>
> The result is not constant bitrate.
>
> http://ffmpeg-users.933282.n4.nabble.com/file/n2255686/2passtest2.jpg
> kb/s:996.69
> frame I:4     Avg QP:16.28  size: 12850
> frame P:345   Avg QP:22.61  size:  7690
> frame B:551   Avg QP:25.48  size:  3232
> (as reported by FFmpeg)
>
> CBR may not mean constant bitrate me thinks.
> This encode also shows some strange B-frame behavior at the start and
> towards the end.
> The footage is the same as posted on the previous links.
>
> I like the cryptic descriptions on the FFmpeg FAQ in regards to this:
> 3.19 I want CBR, but no matter what I do frame sizes differ.
> You do not understand what CBR is, please read the MPEG spec. Read about
> video buffer verifier and constant bitrate. The one sentence summary is that
> there is a buffer and the input rate is constant, the output can vary as
> needed.
> 3.20 How do I check if a stream is CBR?
> To quote the MPEG-2 spec: "There is no way to tell that a bitstream is
> constant bitrate without examining all of the vbv_delay values and making
> complicated computations."
>
> So what is CBR?
>
> Michael

CBR is when maxrate == bitrate and bufsize is set.

Dark Shikari
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user