Search code examples
voipoffsetrtptimestamp

How to calculate effective time offset in RTP


I have to calculate time offset between packets in RTP streams. With video stream encoded with Theora codec i have timestamp field like

 2856000
 2940000
 3024000
 ...

So I assume that transmission offset is 84000. With audio speex codec i have timestamp field like

 38080
 38400
 38720
 ...

So I assume that transmission offset is 320. Why values so different? Are they microseconds, milliseconds, or what? Can i generalize a formula to calculate delay between packets in microseconds that works with any codec? Thank you.


Solution

  • RTP timestamps are media dependant. They use the sampling rate of the codec in use. You have to convert them to milliseconds before comparing with your clock or with timestamps from other RTP streams.

    Added:

    To convert the timstamp to seconds, just divide the timestamp by the sample rate. For most audio codecs, the sample rate is 8 kHz.

    See here for a few examples.