Log in

View Full Version : Detecting VBR vs CBR in MPEG-2 from headers and trace files


K7AAY
19th March 2008, 23:41
I need to search through headers and trace files for thousands of video files to determine if an MPEG-2 file was encoded with Constant Bit Rate or Variable Bit Rate, through an automated process. I've already done that with H.264, where it was easy with
[SPS] cbr_flag = 0
but the standards document for MPEG-2 indicates the content of bit_rate_value won't tell me if a file's VBR or CBR, and there's no other flag I can see which might.

Mediainfo is not reliable; it identifies VBR files as CBR.

How may I look into an MPEG-2 file and determine if it's CBR or VBR?

Thank you kindly.

akupenguin
20th March 2008, 01:03
I trust that before asking such a question, you understand that the distinction between CBR and VBR is not a boolean? Any stream whatsoever is CBR if you allow a big enough VBV. Likewise, just because a stream is marked as cbr_flag=1 doesn't mean that it's restricted enough for your application.

Constant bitrate operation is simply a special case of variable bitrate operation. There is no way to tell that a bitstream is constant bitrate without examining all of the vbv_delay values and making complicated computations.

drmpeg
20th March 2008, 13:54
If vbv_delay is not 0xffff, then it's very likely that the bitstream is CBR (although not guaranteed as the specification suggests).

If vbv_delay is 0xffff, then all bets are off. It could be VBR, CBR or CBR without zero stuffing.

I do have some code for you. It's a bitrate calculator that uses a running average to determine bitrate in bps.

http://www.w6rz.net/bitrate.zip

Ron

Guest
20th March 2008, 14:34
DGIndex's info dialog displays the current, average, and max bitrates.

K7AAY
20th March 2008, 17:03
grep vbv_delay tracefile | awk '{print $5}' | sort | uniq | awk 'END{print NR-1}' will show me 0 if CBR, 1 or higher if the bit rate varies. So, perhaps that's my solution?

If that looks bogus, your feedback would be appreciated.

I use the GNUWIN32 versions of grep and awk, uniq from Jason Mathews and sort from Microsoft Windows, if you want to replicate my test.

Thank you, akupenguin, for taking the time to reply earlier, and special 73s to drmpeg. I had sussed out the vbv_delay idea last night after getting home from night school at PSU, and it's nice to get the confirmation my approach is valid.

Neuron2, I will make sure to look into your suggestion, as well as drmpeg's.

K7AAY
8th April 2008, 17:25
If vbv_delay is not 0xffff, then it's very likely that the bitstream is CBR (although not guaranteed as the specification suggests).

If vbv_delay is 0xffff, then all bets are off. It could be VBR, CBR or CBR without zero stuffing.

I do have some code for you. It's a bitrate calculator that uses a running average to determine bitrate in bps.

http://www.w6rz.net/bitrate.zip

Ron

bitrate | grep average | gsar -F -s, -r | awk '{print $10/$5}'
shows 1 if CBR, >1 if VBR.

other apps Open Source @ http://gnuwin32.sourceforge.net/packages.html

Thank you!

Got a version of BITRATE which works for H.264?