rooltex
rooltex

Reputation: 132

How to handle timestamp in RTMP?

I'm parse RTMP stream from wireshark capture and write media data to .flv file. I know how to calculate timestamp but a how can i handle timestamp when it overflow?

Upvotes: 1

Views: 3432

Answers (2)

rooltex
rooltex

Reputation: 132

So i solved problem this way : 1) Parse RTMP header( read 4 bytes from the beginning of timestamp ) and get timestamp( u_int 32 ) ;

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

2) Calculate timestamp for .flv file ( timestamp in .flv file is always 32 bit for example 0x00000100 is simple timestamp and equal 1 and 0xffffff01 is extended timestamp and equal 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;
    }

Upvotes: 2

szatmary
szatmary

Reputation: 31081

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

realtimestamp += delta;
previoustimestamp = timestamp

Upvotes: 0

Related Questions