简体   繁体   English

hls.js 将视频 PTS 从单位转换为秒

[英]Hls.js convert video PTS from units to seconds

Short短的

I would like to add a time shift to the streaming video player using PTS, but do not know how should correctly do a conversion from units to seconds.我想使用 PTS 向流媒体视频播放器添加时间转换,但不知道应该如何正确地进行从单位到秒的转换。

Long

I'm trying to make a simple streaming video player using hls.js and I would like to show in browsers player difference between real streaming start time and time a user connects to the stream.我正在尝试使用hls.js制作一个简单的流媒体视频播放器,我想在浏览器播放器中显示实际流媒体开始时间和用户连接到 stream 的时间之间的差异。 For example - a streaming video goes for 2 minutes 15 sec, if now a user opens my player it should show not "0 - 36" (36 - is time for several already uploaded fragments), but "2:15 - 2:51".例如 - 一个流媒体视频持续 2 分 15 秒,如果现在用户打开我的播放器,它应该显示的不是“0 - 36”(36 - 是几个已经上传的片段的时间),而是“2:15 - 2:51 ”。 Simply saying, I would like to add a time shift to the video player.简单地说,我想为视频播放器添加一个时移。 Since it is MPEG-ts it contains PTS in PES header that is connected to 90khz time clock.由于它是 MPEG-ts,它在连接到 90khz 时钟的 PES header 中包含 PTS。 In hls.js already done the job with getting PTS from packets.在 hls.js 中已经完成了从数据包中获取 PTS的工作。 So, it should be easy to set new var equal to PTS after checks and bitwise operations and convert new var from units to seconds.因此,在检查和按位运算后将新 var 设置为等于 PTS 并将新 var 从单位转换为秒应该很容易。 And there is my problem - I don't know how to do the conversion in the right way.还有我的问题 - 我不知道如何以正确的方式进行转换。 I tried to divide got PTS onto 90000, but the resulted value is bigger than video time on 1.46 sec and grows with video duration (I checked videos up to 2.5 hrs and at the end of the video it was about 6sec greater than real video time).我试图将得到的 PTS 划分为 90000,但结果值大于 1.46 秒的视频时间,并且随着视频持续时间的增加而增长(我检查了长达 2.5 小时的视频,在视频结束时它比实际视频时间长了大约 6 秒)。 In this case, I think that because of division I will always get a value that bigger than real on 1 sec - can set crutch by subtraction by 1 in the code.在这种情况下,我认为由于除法,我总是会在 1 秒内得到一个大于真实值的值 - 可以通过在代码中减 1 来设置拐杖。 But this does not solve the problem of growing time.但这并不能解决增长时间的问题。

From the beginning it gives me:从一开始它就给了我:

PTS = 132000

Next I'm trying to divide it by 90khz:接下来我尝试将其除以 90khz:

132000/90000 = 1,466666667 sec

Help me please, what am I doing wrong?请帮助我,我做错了什么?

Dividing by 90000 is correct, but the file does not start at PTS 0. You need subtract the first PTS of the video from the current PTS, then divide.除以 90000 是正确的,但文件不是从 PTS 0 开始。您需要从当前 PTS 中减去视频的第一个 PTS,然后再除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM