Search code examples
javascriptwebmmedia-source

Setting stream start offset from WebM header received to sourceBuffer


Is there an embed method in MediaSourceExtensions API to get the stream length from file header, without parsing the header manually?

The reason I'm asking this is that the HTML5 video-player doesn't understand where the content starts. The server records a stream updating the file duration and sends to browser on request the file header on initialize, and the latest incomming clusters. The timecode of the clusters may be much far from file's start and I need to set an offset of a stream in javascript. I know that there is appendWindowStart and timestampOffset members in SourceBuffer object, thus I need to extract the length of file on header's receive to set them.

So should I parse the header manually or there is some magic function?

PS: interesting, that the player shows the actual duration in control panel


Solution

  • Don't parse manually, let the browser figure it out. Depending on your container format, there may be relative timestamps, or there may not be. Just check the buffered range after loading your chunk, and seek the video to the buffered start.