MPEG-2码流结构分析
MPEG2视频编码定义在 ISO/IEC13818-2中,MPEG2 video sequence如下图所示
我们可以借助Elecard Stream Analyer工具来分析MPEG2视频码流
MPEG2编码码流的起始码的含义如下
1.Sequence Header
MPEG2视频裸流的每一个GOP以Sequence Header开头,Sequence Header的起始码为00 00 01 B3,它里面保存了如下信息
- horizontal_size_value:视频帧宽度
- vertical_size_value:视频帧高度
- aspect_ratio_information:宽高比,各取值的含义如下
- frame_rate_code:帧率,各取值含义如下
- bit_rate_value:码率
- marker_bit:This is one bit that shall be set to '1'. This bit prevents emulation of start codes
- vbv_buffer_size:定义了VBV (Video Buffering Verifie)的大小
2.Sequence Extention
它的起始码为 00 00 01 B5,保存了如下信息
- profile_and_level_indication:指明了profile和leve
- progressive_sequence:When set to '1' the coded video sequence contains only progressive frame pictures. Whenprogressive_sequence is set to '0' the coded video sequence may contain both frame pictures and field pictures, and framepicture may be progressive or interlaced frames.
- chroma_format:采样格式,各取值含义如下
3.Group of picture Header
起始码为00 00 01 B8,保存了如下信息
- time_code:时码,占25个字节,包含drop_frame_flag, time_code_hours, time_code_minutes,marker_bit, time_code_seconds 以及 time_code_pictures,各标志取值范围如下
drop_frame_flag 标志只有在帧率为 29.97 时才有可能被设置为1。如果被设置为0 每秒钟的帧数被近似到最近的整数,例如29.97的被近似为30. 如果被设置为1,除了 0, 10, 20, 30, 40, 50 分钟外每分钟开始的第0和第1帧将被忽略
- closed_gop:指明紧挨着在group of picture header后的I帧的连续的B帧的编码方式,如果被设置为1,表示该B帧只采用backward prediction 或 intra coding (Close GOP是指帧间的预测都是在GOP中进行的。而使用open GOP,后一个GOP会参考前一个GOP的信息。使用这种方式就大大降低了码率)
4.Picture Header
Picture Header保存了图像相关信息,从该头部信息中可以判断该帧时IP或B帧。它的起始码为00 00 01 00
- temporal_reference:指明该帧的参考属性,各取值含义如下
- vbv_delay:当该值为 0xFFFF 表示VBR编码
当出现0x0000100,是就表示已经到了图象层,再越过10位(Temporal_reference占10位),就到了Picture_coding_type(3位),如果Picture_coding_type为001(二进制)就是I帧,为010是P帧,011则就是B帧。
5. Picture coding extension
- f_code[s][t]:4bit的整数,用在解码时的运动向量中,s和t的取值含义如下图
- intra_dc_precision: indicates the number of bits for quantized DC,coefficients of intra-coded blocks,The more bits are used, the more precise quantization is achieved,取之含义如下
- picture_structure :图像扫面方式,各取值含义如下
- frame_pred_frame_dct:If this flag is set to '1', then only frame-DCT and frame prediction are used. In a field picture it shall be '0'. frame_pred_frame_dct shall be '1' if progressive_sequence is '1'. This flag affects the syntax of the bitstream.
- concealment_motion_vectors:This flag has the value '1' to indicate that motion vectors are coded in intra macroblocks. This flag has the value '0' to indicate that no motion vectors are coded in intra macroblocks
参考:ISOIEC13818-2-2013.pdf