如何处理RTMP中的时间戳?

时间:2017-02-27 09:11:39

标签: c++ video timestamp rtmp flv

我正在解析来自wireshark捕获的RTMP流并将媒体数据写入.flv文件。我知道如何计算时间戳,但是如何在溢出时处理时间戳?

2 个答案:

答案 0 :(得分:1)

所以我用这种方式解决了问题: 1)解析RTMP头(从时间戳的开头读取4个字节)并获取时间戳(u_int 32);

if ( ( _timestamp >> 8 ) == 0xffffff ) /* check if extended timestamp is present */
    {
        _timestamp = (_timestamp & 0x000000ff) + 0xffffff;
    }
    else
    {
        _timestamp >>= 8 ;  
    }

2)计算.flv文件的时间戳(.flv文件中的时间戳总是32位,例如0x00000100是简单时间戳,等于1,0xffffff01是扩展时间戳,等于0xffffff + 0x01)

if ( ( timestamp_calc + _timestamp ) >= 0xffffff )
    {
        unsigned __int8 temp = _timestamp;
        unsigned __int8 * ptr;

        if ( (timestamp_calc + _timestamp) >= 0xffffffff ){ timestamp_calc = _timestamp; }
        else
        {
            timestamp_calc = 0xffffff;
            timestamp_calc <<= 8;
            ptr = (unsigned __int8 *)&timestamp_calc;
            ptr[ 0 ] = _timestamp;
        }
    }
    else
    {
        timestamp_calc += _timestamp;
    }

答案 1 :(得分:0)

delta = timestamp - previoustimestamp;
if delta > maxtimestamp / 2 {
delta = matimestamp - previoustimestamp + time stamp;}

realtimestamp += delta;
previoustimestamp = timestamp