AVC Video: location of high-level parameters in bitstream

The AVC video compression standard (also referred as H.264 or MPEG-4 Part 10) emerged in 2003. Even after 21 years in 2024, it continues to stand as one of the most extensively used video compression standards. In the article we will show the location of some parameters of the original video (FPS, size, aspect ratio, profile and level, bitrate mode and scan type) in encoded AVC/H264 bitstream. To analyze AVC video we will use Virinext Bitstream Analyzer. You can download the evaluation version on the download page. For license acquiring please check the Buy license page.

Frame per second (FPS)

Information about FPS in AVC bitstream is optional. When frame rate information stored within the stream, the FPS value gets derived from the SPS::VUI::num_units_in_tick and SPS::VUI::time_scale fields through the following algorithm:

FrameRate_Divider=1
IF Picture timing SEI::pic_struct == 7
    FrameRate_Divider = 2
IF Picture timing SEI::pic_struct == 8
    FrameRate_Divider = 3

FPS = SPS::VUI::time_scale / SPS::VUI::num_units_in_tick / FrameRate_Divider
IF SPS::frame_mbs_only_flag && SPS::pic_order_cnt_type != 2
    FPS = FPS / 2
Screenshot from Virinext Bitstream Analyzer of H264 Sequence Parameter Set(SPS) element with timing info underlined

In the example file we have SPS::frame_mbs_only_flag = 1, SPS::VUI::time_scale = 240000 and SPS::VUI::num_units_in_tick = 5005, so FPS = 2 * 240000 / 5005 = 23.976.

Picture size

Size of the picture is stored in SPS::pic_width_in_mbs_minus1 and SPS::pic_height_in_luma_samples fields. Picture Size calculated by using the following algorithm:

WidthCrop = 0
HeightCrop = 0
IF SPS::frame_cropping_flag
    ChromaArrayType = 0
    IF SPS::separate_colour_plane_flag == 0
        ChromaArrayType = SPS::chroma_format_idc

    SubWidthC = { 1, 2, 2, 1 }
    SubHeightC = { 1, 2, 1, 1 }

    CropUnitX = SubWidthC[ChromaArrayType];
    CropUnitY = SubHeightC[ChromaArrayType] * (2 - SPS::frame_mbs_only_flag);

    WidthCrop = SPS::frame_crop_left_offset + SPS::frame_crop_right_offset
    WidthCrop = WidthCrop * CropUnitX
    HeightCrop = SPS::frame_crop_top_offset + SPS::frame_crop_bottom_offset
    HeightCrop = HeightCrop * CropUnitY
    
Width = (SPS::pic_width_in_mbs_minus1 + 1) * 16 - WidthCrop
Height = (SPS::pic_height_in_map_units_minus1 + 1) * 16  * (2 - SPS::frame_mbs_only_flag) - HeightCrop
Screenshot from Virinext Bitstream Analyzer with SPS element with underlined pic_width_in_mbs_minus1, pic_height_in_luma_samples and frame_cropping_flag

In the example file we have:

Width = (119 + 1) * 16 = 1920

Height = (67 + 1) * 16 – 4 * 2 = 1080

Aspect ratio

The aspect ratio can be encoded either as a predefined constant value or as a pair of horizontal and vertical values. It resides in the SPS::VUI::aspect_ratio_idc field. If SPS::VUI::aspect_ratio_idc equals EXTENDED_SAR, then sar_width and sar_height are utilized for aspect ratio calculation.

Screenshot from Virinext Bitstream Analyzer with SPS element with underlined aspect_ratio_idc value

In the example file we have SPS::VUI::aspect_ratio_idc = 1. That means pixels in stream are squares.

Profile and level

Profile defines the features that the encoder can use during encoding. Based on the profile value, the decoder can recognize the requirements for decoding specific bitstream. Level specifies another set of constraints that indicate a required decoder performance. These constraints include maximum frame size, bitrate and decoding speed.

Profile value is located in SPS::profile_idc field, level is signaled via SPS::level_idc field.

Screenshot from Virinext Bitstream Analyzer with SPS element with underlined profile_idc and level_idc values

In the example file we have SPS::profile_idc=100 and SPS::level_idc=40 that means High profile with level 4 is used.

Bitrate mode

AVC bitstream can optionally have a flag that indicates CBR (constant bit rate) mode is used. When exists, this value is signaled in SPS::vui_parameters::hrd_parameters::cbr_flag field.

Screenshot from Virinext Bitstream Analyzer with SPS element with underlined cbr_flag value

In the example file we have SPS::vui_parameters::hrd_parameters::cbr_flag=0 that means non-CBR mode is used.

Scan type

Value SPS::frame_mbs_only_flag indicates the information about using progressive and interlace scan types during encoding. The value SPS::frame_mbs_only_flag equals to 1 indicates that encoded bitstream contains only coded frames and doesn’t have codec fields. When SPS::frame_mbs_only_flag equals 0 both coded frames and coded fields can be used in bitstream.

Screenshot from Virinext Bitstream Analyzer with SPS element with underlined frame_mbs_only_flag value

In the example file we have SPS::frame_mbs_only_flag=1 that means only coded frames is used in bitstream.

Conclusion

In this article, we have explored the AVC video compression standard. We have examining details of standard by looking for the location of key video parameters within the encoded AVC/H.264 bitstream, including frame rate, picture size, aspect ratio, profile and level, bitrate mode, and scan type. By utilizing the powerful analysis tool Virinext Bitstream Analyzer, we have demonstrated how these parameters are encoded and can be extracted from the bitstream. If you interested in exploring further, we are offering you to try free evaluation version of Virinext Bitstream Analyzer. Virinext Bitstream Analyzer it is a GUI tool for both in-depth and high-level analysis for many encoding standards including H.264 video.