[Ffmpeg-devel] [BUG] Rate Control For MPEG CBR

Brian Brice bbrice
Sat Oct 28 11:01:36 CEST 2006


Hello.

I have been testing ffmpeg's CBR capabilities for the purpose of
producing HDV compatible MPEG 2 video.  The hardware I'm working
with requires a constant bitrate of either 18.3 Mbps or 25 Mbps
(2 different types of devices).  If there are sudden spikes in the
bitrate then of course recording to the media, eg. mini-DV tape, doesn't
work.

My test input into libavcodec is pretty much a series of frames with
random noise in them (I'm trying to test somewhat worst case scenarios).
Here's information about the streams (not listed is left to default):

Video
   codec:        mpeg2video
   bit_rate:     18300000
   width:        1280
   height:       720
   aspect_ratio: 16:9
   rate:         ntsc (30/1.001)
   gop_size:     6
   max_b_frames: 2
   profile:      4 (MP)
   level:        6 (HL 1440)
   rc_min_rate:  18300000
   rc_max_rate:  18300000
   rc_buffer_size: 3670016 (448 KiB * 1024 * 8)

Audio:
   codec:       mp2
   bit_rate:    384000
   sample_rate: 48000
   channels:    2

Given that the input frames to the encoder are pretty much random noise,
the outcoming frame sizes are absolute too huge for anything close to
18.3 Mbps CBR.  I kept track of the returned compressed frame sizes from
avcodec_encode_video() and here is their results:

dts     type  size
0.4004   I    860038
0.5005   P    291016
0.533867 B    396652
0.567233 B    331925
0.6006   I    294090
0.633967 B    331273
0.667333 B    331603
0.7007   P    247944
0.734067 B    331157
0.767433 B    331345
0.8008   I    293541
0.834167 B    331235
0.867533 B    330850
0.9009   P    246918
0.934267 B    330333
0.967633 B    330848
1.001    I    292795
...

If you average this first second worth, it comes out to about 47 Mbps.
For sample videos I've tested, the bitrate only goes up from there,
averaging about 66 Mbps.

Obviously 66 Mbps isn't going to work with a device that needs
18.3 Mbps.  I believe this to be a bug.  Unless I've forgotten to set
something else that should be requird for CBR (or close to), asking for
18.3 Mbps and getting back more than 3 times that is quite unexpected.

Please, comments, questions, suggestions!  Thank you guys.

-- 
Brian Brice




More information about the ffmpeg-devel mailing list