From 1b60d647a7ca6c1c502c821265b689b847f7255a Mon Sep 17 00:00:00 2001
From: Sebastian Zeller <SebiderSushi@t-online.de>
Date: Tue, 5 Jan 2021 07:09:34 +0100
Subject: [PATCH 3/3] avformat/webvttdec: Calculate hls_ts_offset relative to
first fragment
---
libavformat/webvttdec.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/libavformat/webvttdec.c b/libavformat/webvttdec.c
index c6acf8e5bb..cf56f0c232 100644
|
a
|
b
|
static int webvtt_read_header(AVFormatContext *s)
|
| 71 | 71 | AVStream *st = avformat_new_stream(s, NULL); |
| 72 | 72 | int has_hls_timestamp_map = 0; |
| 73 | 73 | int64_t hls_ts_offset; |
| | 74 | int64_t hls_ts_offset_global = -1; |
| 74 | 75 | |
| 75 | 76 | if (!st) |
| 76 | 77 | return AVERROR(ENOMEM); |
| … |
… |
static int webvtt_read_header(AVFormatContext *s)
|
| 121 | 122 | int64_t mpegts_ts = strtoll(mpegts_str + 7, NULL, 10); |
| 122 | 123 | |
| 123 | 124 | if (native_ts != AV_NOPTS_VALUE) { |
| 124 | | hls_ts_offset = mpegts_ts - native_ts * 90; |
| | 125 | /* |
| | 126 | * In livestreams the timestamp map can start at any mpegts time. |
| | 127 | * Consequently, everything should be treated relative to the first timestamp. |
| | 128 | */ |
| | 129 | if (hls_ts_offset_global == -1) { |
| | 130 | hls_ts_offset_global = mpegts_ts; |
| | 131 | } |
| | 132 | hls_ts_offset = mpegts_ts - native_ts * 90 - hls_ts_offset_global; |
| 125 | 133 | has_hls_timestamp_map = 1; |
| 126 | 134 | avpriv_set_pts_info(st, 33, 1, 90000); |
| 127 | 135 | } |