RTMP协议 05 时间戳

RTMP时间戳

基本介绍
RTMP协议 05 时间戳_第1张图片
timestamp
  • RTMP中时间戳的单位为毫秒(ms)
  • 时间戳为相对于某个时间点的相对值
  • 时间戳的长度为32bit,不考虑回滚的话,最大可表示49天17小时2分钟47.296秒
  • Timestamp delta单位也是毫秒,为相对于前一个时间戳的一个无符号整数; 可能为24bit或32bit

Message时间戳

RTMP协议 05 时间戳_第2张图片
Message时间戳

Timestamp:
Four-byte field that contains a timestamp of the message.
The 4 bytes are packed in the big-endian order.

  • RTMP Message的时间戳 4个字节
  • 大端存储
Chunk时间戳
Chunk Format
RTMP协议 05 时间戳_第3张图片
Chunk Format

用wireshark转包分析发现,rtmp流的chunk视频流(或音频流)除第一个视频时间戳为绝对时间戳外,后续的时间戳均为timestamp delta,即当前时间戳与上一个时间戳的差值
比如帧率为25帧/秒的视频流,timestamp delta基本上都为40ms。

通常情况下,Chunk的时间戳(包括绝对时间戳和Timestamp delta)是3个字节。
但时间戳值超过0xFFFFFF时,启用Extended Timestamp(4个字节)来表示时间戳

通常情况下 -- 3字节
RTMP协议 05 时间戳_第4张图片
3字节时间戳 示意

三字节的timestamp可能为绝对timestamp或timestamp delta。

timestamp delta (3 bytes):
For a type-1 or type-2 chunk, the difference between the previous chunk’s timestamp and the current chunk’s timestamp is sent here.
If the delta is greater than or equal to 16777215 (hexadecimal 0xFFFFFF), this field MUST be16777215, indicating the presence of the Extended Timestamp field to encode the full 32 bit delta. Otherwise, this field SHOULD be the actual delta.

timestamp delta的值超过16777215 (即16进制的0xFFFFFF)时,这时候这三个字节必须被置为: 0xFFFFFF,以此来标示Extended Timestamp(4字节)将会存在,由Extended Timestamp来表示时间戳。

时间戳超过0xFFFFFF时 -- 4字节
Extended Timestamp
RTMP协议 05 时间戳_第5张图片
Extended Timestamp
  • Extended Timestamp为4个字节。


    RTMP协议 05 时间戳_第6张图片
    Chunk Format
  • 当Chunk Format中Message Header中的三字节时间戳的值为0xFFFFFF,即时间戳或timestamp delta超过16777215 (0xFFFFFF)时,Extended Timestamp才存在。

References:

rtmp_specification_1.0.pdf

你可能感兴趣的:(RTMP协议 05 时间戳)