如何判断码流的编码格式为MPEG-4
可通过查看第一个数据包的payload
前几个字节:
如果是 0x00 0x00 0x01 0xB0
, 则当前码流可能是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.
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.
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-VOP
, P-VOP
等。
MPEG-4整体层次
References:http://blog.csdn.net/joesay/article/details/4988575
startcode
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
)之后, 后续的数据包开头无任何规律,这是为什么呢?
这是因为他们都属于同一帧的数据。
他们拥有相同的时间戳,所以属于同一帧的数据。
如何判断I-VOP和P-VOP
答案是: 由0x00 0x00 0x01 0xb6
之后的两位决定。
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