Quick tip. How do you start playing a video from a specific point in time with HLS? Use the EXT-X-START tag. It’s optional, but if it’s present in a playlist it specifies the preferred point in the video to start playback.
The following attributes are defined in the spec for the EXT-X-START tag:
- TIME-OFFSET – (required) The offset in seconds to start playing the video. If the value is negative, specifies the time from the end of the playlist. The offset must not be larger than the playlist duration.
- PRECISE – (optional) Valid string values: YES, NO. If YES, playback starts at the point specified by TIME-OFFSET but does not render frames in the segment prior to the offset. Default is NO.
Let’s look at an example. Assume that we want to start playback precisely 25 seconds from the beginning of the video. You would add the following tag to the playlist:
If we want to start 15 seconds from the end of the playlist and we aren’t concerned with precision, the tag will look like this:
To see how this works in practice, let’s look at some examples. (I recommend watching the videos with Safari on an iOS device. I had mixed results with Safari on the desktop.) The first example starts playing at the beginning of the video, the second one – same video, different playlist – starts playing 25 seconds in.
There’s one more thing to consider if you want to use the EXT-X-START tag: It first appeared in version 6 of the protocol so you need to set the EXT-X-VERSION tag in the playlist accordingly.
Here’s the complete playlist for the example with the EXT-X-START tag:
#EXTM3U #EXT-X-TARGETDURATION:10 #EXT-X-VERSION:6 #EXT-X-MEDIA-SEQUENCE:0 #EXT-X-START:TIME-OFFSET=25,PRECISE=YES #EXT-X-PLAYLIST-TYPE:VOD #EXTINF:10.00000, sintel0.ts #EXTINF:10.00000, sintel1.ts #EXTINF:10.00000, sintel2.ts #EXTINF:10.00000, sintel3.ts #EXTINF:10.00000, sintel4.ts #EXTINF:10.00000, sintel5.ts #EXTINF:10.00000, sintel6.ts #EXT-X-ENDLIST
If you want to play the videos in a browser other than Safari, you may want to check out an earlier post that describes how to do this. If it doesn’t work as expected, this may be because the client doesn’t support the appropriate version of HLS. Your mileage may vary.