diff options
author | Felix S <felix.von.s@posteo.de> | 2021-08-15 15:33:06 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-15 21:03:06 +0530 |
commit | 7a6742b5f9e7b8d0c92fb6b1f56e7e486873c169 (patch) | |
tree | 65c610dfd9db5187e3d5778058e3668753251553 | |
parent | e040bb0a41d1023268875d03b7c558107d873ad3 (diff) | |
download | hypervideo-pre-7a6742b5f9e7b8d0c92fb6b1f56e7e486873c169.tar.lz hypervideo-pre-7a6742b5f9e7b8d0c92fb6b1f56e7e486873c169.tar.xz hypervideo-pre-7a6742b5f9e7b8d0c92fb6b1f56e7e486873c169.zip |
[webvtt] Fix timestamp overflow adjustment (#698)
In some streams, empty segments may appear with a bogus, non-monotone MPEG timestamp.
This should not be considered as an overflow
Authored by: fstirlitz
-rw-r--r-- | yt_dlp/downloader/hls.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/yt_dlp/downloader/hls.py b/yt_dlp/downloader/hls.py index 9cfc191cb..779658b70 100644 --- a/yt_dlp/downloader/hls.py +++ b/yt_dlp/downloader/hls.py @@ -254,8 +254,14 @@ class HlsFD(FragmentFD): def pack_fragment(frag_content, frag_index): output = io.StringIO() adjust = 0 + overflow = False + mpegts_last = None for block in webvtt.parse_fragment(frag_content): if isinstance(block, webvtt.CueBlock): + extra_state['webvtt_mpegts_last'] = mpegts_last + if overflow: + extra_state['webvtt_mpegts_adjust'] += 1 + overflow = False block.start += adjust block.end += adjust @@ -296,9 +302,9 @@ class HlsFD(FragmentFD): extra_state.setdefault('webvtt_mpegts_adjust', 0) block.mpegts += extra_state['webvtt_mpegts_adjust'] << 33 if block.mpegts < extra_state.get('webvtt_mpegts_last', 0): - extra_state['webvtt_mpegts_adjust'] += 1 + overflow = True block.mpegts += 1 << 33 - extra_state['webvtt_mpegts_last'] = block.mpegts + mpegts_last = block.mpegts if frag_index == 1: extra_state['webvtt_mpegts'] = block.mpegts or 0 |