Mic_chen

It is not the strongest of the species that survive, nor the most intelligent, but the one most responsive to change

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

这里主要关注的rtp包的时间戳,在rtsp中,播放器的1S钟的定义是和媒体的采样率有关的。

例如视频的采样率是90K,那么最小时间粒度(单位)是1/90000秒,再转换成ms就是 1/90毫秒,这个就是rtsp中的最小时间单位。

所以设备端采集的视频的时间要经过一个转换,标准的播放器才能播放

还是以90K的视频为例,设备采集到的单位是按时间tv_sec,tv_usec存储。

/* timestamp convert
    t(rtsp时间戳,单位ms) =  t(采集时间戳,单位秒)*90000
    */
    unsigned int tv_sec, tv_usec, pts;
    tv_sec = ts / 1000;
    tv_usec = (ts % 1000) * 1000;
    pts = tv_sec * 90000 + tv_usec *9 / 100;

 

对应的如果是8K采样率的音频,则转化公式是:

    /* timestamp convert
    t(rtsp时间戳,单位ms) =  t(采集时间戳,单位秒)*8000
    */
    tv_sec = ts / 1000;
    tv_usec = (ts % 1000) * 1000;
    pts = tv_sec * 8000 + tv_usec *8/1000;

 

posted on 2018-06-05 20:34  Mic_chen  阅读(5770)  评论(0编辑  收藏  举报