videojs / videojs-contrib-hls

HLS library for video.js
http://videojs.github.io/videojs-contrib-hls/
Other
2.84k stars 792 forks source link

Current time for live stream #380

Closed Koryakov closed 9 years ago

Koryakov commented 9 years ago

Hi All! I want implement realtime voting for HLS stream from cdn. My stream runs on Wowza Streaming Engine and I investigated that segment contains pts time counted from publishing time. My idea is storing minPts of first downloaded segment:

videojs.Hls.prototype.drainBuffer = function(event) {
//...
//some code
segmentOffset = this.playlists.expiredPostDiscontinuity_ + this.playlists.expiredPreDiscontinuity_;
segmentOffset += videojs.Hls.Playlist.duration(playlist,
                                                     playlist.mediaSequence,
                                                     playlist.mediaSequence + mediaIndex);
segmentOffset = offset - (segmentOffset * 1000);
ptsTime = segmentOffset + tags[0].pts;
//It`s my code - store into my variable firstRunPtsTime only first time :
 if (this.firstRunPtsTime < 0) {
        this.firstRunPtsTime = ptsTime;
}
//some code
//...
}
//using on page:
$('#btnVote').click(function () {
   var msec = player.hls.firstRunPtsTime / 1000 + player.currentTime();
}

But for this scenario I need to change videojs.Hls code for adding firstRunPtsTime , because ptsTime is private function variable. I will be grateful for solution or ideas!

dstieglitz commented 9 years ago

+1 I'm also interested in obtaining pts values

dmlap commented 9 years ago

PTS values for MPEG2-TS streams do not start from zero on many encoders so this wouldn't be a general-purpose mechanism for determining the start time of a live stream. Most people I've heard about who do this find an out-of-band way of signaling the live stream start time to their app, e.g. an API endpoint somewhere that returns a datetime. Closing this based on the original problem statement but if there's another use-case for PTS values, please feel free to keep commenting here.