<p>Looks like this might be a bug in HLS.js:
<a href="https://github.com/video-dev/hls.js/issues/2873" rel="nofollow noreferrer">https://github.com/video-dev/hls.js/issues/2873</a></p>
<p>Hopefully this is rectified in a subsequent version.</p>
<p><strong>UPDATE:</strong></p>
<p>This hls.js bug has been fixed in release 0.14.1:
<a href="https://github.com/video-dev/hls.js/releases/tag/v0.14.1" rel="nofollow noreferrer">https://github.com/video-dev/hls.js/releases/tag/v0.14.1</a></p>

CC BY-SA 4.0
2020-07-09T01:08:27.523Z
2020-07-14T03:02:05.740Z
2020-07-14T03:02:05.740Z
James Mc
<p>I have a need to play small pieces (1 or 2 seconds) of video in various orders via HLS. Think a highlights reel from a sporting match.</p>
<p>Several HLS players struggle with playing a stream with discontinuities between every TS segment, but HLS.js based players appear to cope OK. The one things that does happen is <em>sometimes</em>, but not always, a frame is dropped following a discontinuity. It seems to happen about 70% of the time that the player drop either frame 0 or frame 1 (i.e. the 1st or 2nd frame in the TS segment).</p>
<p>I have experimented with different TS segment lengths, different videos, different frame rates and bit rates. The problem seems pretty consistent.</p>
<p>To reproduce what I'm seeing (on windows 10), create a test video at 25 FPS with FFMPEG:</p>
<pre><code>ffmpeg -f lavfi -i testsrc=duration=60:size=1960x1080:rate=25 -vf &quot;drawtext=fontsize=30:fontcolor=White:fontfile='c\:\\Windows\\Fonts\\arial.ttf':text='Frame\: %{eif\:mod(n,25)\:d}':x=2:y=2:box=1: boxcolor=0x00000000@1&quot; -b:v 1m atestsrc.mpg
</code></pre>
<p>Then slice the video into 1 second long TS segments:</p>
<pre><code>ffmpeg -i atestsrc.mpg -force_key_frames &quot;expr:gte(t,n_forced*1)&quot; -strict -2 -c:a aac -c:v libx264 -f segment -segment_list_type m3u8 -segment_list_size 0 -segment_time 1.0 -segment_time_delta 0 -segment_list atest.m3u8 seg%02d.ts
</code></pre>
<p>The resulting output plays back just fine, until I add the #EXT-X-DISCONTINUITY tags...</p>
<p><strong>The Problem:</strong>
It looks like HLS.js based video players drop frames when playing back the m3u8 with #EXT-X-DISCONTINUITY tags - <a href="https://aai-helper-apps.s3-us-west-2.amazonaws.com/OneSecondChunks/atest_discont.m3u8" rel="nofollow noreferrer">example stream here</a>.</p>
<p>Firstly, you can see that it plays back a 60 second video in 58 seconds. The same symptom occurs in several different HLS.js based players, such as <a href="https://hls-js.netlify.app/demo/?src=https%3A%2F%2Faai-helper-apps.s3-us-west-2.amazonaws.com%2FOneSecondChunks%2Fatest_discont.m3u8&amp;demoConfig=eyJlbmFibGVTdHJlYW1pbmciOnRydWUsImF1dG9SZWNvdmVyRXJyb3IiOnRydWUsImR1bXBmTVA0IjpmYWxzZSwibGV2ZWxDYXBwaW5nIjotMSwibGltaXRNZXRyaWNzIjotMX0=" rel="nofollow noreferrer">this one</a>.</p>
<p>If you play it back at 0.1 times speed you can see that it is not rendering some frames, often frame 1:
<img src="https://aai-helper-apps.s3-us-west-2.amazonaws.com/images/hls-frame-drop.gif" alt="Text" /></p>
<p>This difference in playback speed is causing me all kinds of grief in seeking to specific places in the video. Any ideas on how to address this would be much appreciated!</p>

<ffmpeg><hls>
HLS.js player dropping frames at discontinuities in HLS stream
James Mc
# HLS.js player dropping frames at discontinuities in HLS stream

(Asked by: username_0 on 2020-07-07)

I have a need to play small pieces (1 or 2 seconds) of video in various orders via HLS. Think a highlights reel from a sporting match.
Several HLS players struggle with playing a stream with discontinuities between every TS segment, but HLS.js based players appear to cope OK. The one things that does happen is sometimes, but not always, a frame is dropped following a discontinuity. It seems to happen about 70% of the time that the player drop either frame 0 or frame 1 (i.e. the 1st or 2nd frame in the TS segment).
I have experimented with different TS segment lengths, different videos, different frame rates and bit rates. The problem seems pretty consistent.
To reproduce what I'm seeing (on windows 10), create a test video at 25 FPS with FFMPEG:
ffmpeg -f lavfi -i testsrc=duration=60:size=1960x1080:rate=25 -vf "drawtext=fontsize=30:fontcolor=White:fontfile='c\:\\Windows\\Fonts\\arial.ttf':text='Frame\: %{eif\:mod(n,25)\:d}':x=2:y=2:box=1: boxcolor=0x00000000@1" -b:v 1m atestsrc.mpg

Then slice the video into 1 second long TS segments:
ffmpeg -i atestsrc.mpg -force_key_frames "expr:gte(t,n_forced*1)" -strict -2 -c:a aac -c:v libx264 -f segment -segment_list_type m3u8 -segment_list_size 0 -segment_time 1.0 -segment_time_delta 0 -segment_list atest.m3u8 seg%02d.ts

The resulting output plays back just fine, until I add the #EXT-X-DISCONTINUITY tags...
The Problem:
It looks like HLS.js based video players drop frames when playing back the m3u8 with #EXT-X-DISCONTINUITY tags - example stream here.
Firstly, you can see that it plays back a 60 second video in 58 seconds. The same symptom occurs in several different HLS.js based players, such as this one.
If you play it back at 0.1 times speed you can see that it is not rendering some frames, often frame 1:

This difference in playback speed is causing me all kinds of grief in seeking to specific places in the video. Any ideas on how to address this would be much appreciated!

**Tags:** ffmpeg, hls


---

## 1 answers

### Answer by username_0 on 2020-07-09. Score: 1

Looks like this might be a bug in HLS.js:
<https://github.com/video-dev/hls.js/issues/2873>

Hopefully this is rectified in a subsequent version.

**UPDATE:**

This hls.js bug has been fixed in release 0.14.1:
<https://github.com/video-dev/hls.js/releases/tag/v0.14.1>


---

