MPEG-4码流简析

如何判断码流的编码格式为MPEG-4

可通过查看第一个数据包的payload前几个字节:
如果是 0x00 0x00 0x01 0xB0, 则当前码流可能是MPEG-4码流。

MPEG-4码流简析_第1张图片
判断MPEG-4码流的简易方法

或者观察后续的是否存在多个以0x00 0x00 0x01 0xB6开头的数据包,也可以来进行判断。

基本概念

Visual object sequence

Visual object sequence is the highest syntactic structure of the coded visual bitstream.
A visual object sequence commences with a visual_object_sequence_start_code which is followed by one or more
visual objects coded concurrently
.
The visual object sequence is terminated by a visual_object_sequence_end_code.

MPEG-4码流简析_第2张图片
**VisualObjectSequence()**

Visual object

A visual object commences with a visual_object_start_code, is followed by profile and level identification, and a
visual object id, and is followed by a video object, a still texture object, a mesh object, or an FBA object.


MPEG-4码流简析_第3张图片
**Visual object的前半部分**
Video object

A video object commences with a video_object_start_code, and is followed by one or more video object layers.

VOP

VOP (Video Object Plane -- frame) starts with a code 000001B6(hex). It is the same for all MPEG4 frames (I,P,B)

VOP可理解为帧的概念,有I-VOPP-VOP等。

MPEG-4码流简析_第4张图片
VOP

MPEG-4整体层次

MPEG-4码流简析_第5张图片
MPEG-4整体层次

References: http://blog.csdn.net/joesay/article/details/4988575

startcode

MPEG-4码流简析_第6张图片
Start code values

As far as I know, MPEG4-ES stream fragments in RTP payload usually start with MPEG4 startcode, which can be one of these:
0x000001b0: visual_object_sequence_start_code (probably keyframe)
0x000001b6: vop_start_code (keyframe, if the next two bits are zero)
0x000001b3: group_of_vop_start_code, which contains three bytes and then hopefully a vop_start_code that may or may not belong to a keyframe (see above)
0x00000120: video_object_layer_start_code (probably keyframe)
0x00000100-0x0000011f: video_object_start_code (those look like keyframes as well)
something else (probably not a keyframe)

0x000001b0

visual_object_sequence_start_code, visual_object_sequence序列的startcode。
码流的第一个数据包也以此为开头。
码流中可能存在多个visual_object_sequence_start_code(因为可能存在多个sequence)。

0x000001b6

vop_start_code: This is the bit string ‘000001B6’ in hexadecimal. It marks the start of a video object plane.

即VOP(可理解为一帧)的startcode。

为什么会出现多个连续的开头无任何规律的数据包

比如在某数据包出现0x00 0x00 0x01 0xb0(或0x00 0x00 0x01 0xb6)之后, 后续的数据包开头无任何规律,这是为什么呢?
这是因为他们都属于同一帧的数据
他们拥有相同的时间戳,所以属于同一帧的数据。

MPEG-4码流简析_第7张图片
**payload以0x000001b0开头的数据包**
MPEG-4码流简析_第8张图片
**payload开头无规律的数据包**

如何判断I-VOP和P-VOP

答案是: 由0x00 0x00 0x01 0xb6之后的两位决定。

MPEG-4码流简析_第9张图片
**VideoObjectPlane() 的前半部分**

MPEG-4码流简析_第10张图片
vop_coding_type

vop_coding_type的值如果为00,则为I-VOP
vop_coding_type的值如果为01,则为P-VOP

References:

ISO/IEC 14496-2:2001(E)
http://blog.csdn.net/sunnylgz/article/details/7745038
http://stackoverflow.com/questions/1957427/detect-mpeg4-h264-i-frame-idr-in-rtp-stream
http://users.ece.utexas.edu/~bevans/courses/ee381k/lectures/12_Video_Coding/lecture12/sld008.htm
http://blog.csdn.net/axdc_qa_team/article/details/4042762
http://blog.csdn.net/joesay/article/details/4988575

你可能感兴趣的:(MPEG-4码流简析)