From 9f75da557a6aa6736e36edc1a75686c6b357401b Mon Sep 17 00:00:00 2001 From: Dan Schultz Date: Mon, 31 May 2021 13:02:26 -0400 Subject: [PATCH] Allow pts rollover The MPEG-TS pts field can roll over after a stream has been on for a sufficiently long time (e.g. a week or so). There was a failsafe built into the demuxer that would prevent PTS from ever decreasing -- this was because normally PTS is not supposed to decrease (outside of rollovers). This change now assumes that the data stream will be passed in order in order to maintain that PTS condition. Issue #18 --- packages/mpegts-demuxer/CHANGELOG.md | 2 ++ packages/mpegts-demuxer/src/utils/index.ts | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/mpegts-demuxer/CHANGELOG.md b/packages/mpegts-demuxer/CHANGELOG.md index da9b011..77ec0b9 100644 --- a/packages/mpegts-demuxer/CHANGELOG.md +++ b/packages/mpegts-demuxer/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- PTS is now allowed to decrease between packets, allowing support for timestamp rollovers. ## [0.1.0] - 2021-05-13 ### Added diff --git a/packages/mpegts-demuxer/src/utils/index.ts b/packages/mpegts-demuxer/src/utils/index.ts index 85d1896..37ad6c9 100644 --- a/packages/mpegts-demuxer/src/utils/index.ts +++ b/packages/mpegts-demuxer/src/utils/index.ts @@ -290,7 +290,7 @@ function decodePes( const pts = decodeTs(mem, ptr + 3) if (s.has_dts && pts !== s.dts) { s.frame_ticks = pts - s.dts } - if (pts > s.last_pts || !s.has_pts) { s.last_pts = pts } + s.last_pts = pts if (s.first_pts === 0 && s.frame_num === (s.content_type === MEDIA_TYPES.video ? 1 : 0)) { @@ -308,7 +308,7 @@ function decodePes( const dts = decodeTs(mem, ptr + 8) if (s.has_dts && dts > s.dts) { s.frame_ticks = dts - s.dts } - if (pts > s.last_pts || !s.has_pts) { s.last_pts = pts } + s.last_pts = pts if (s.first_pts === 0 && s.frame_num === (s.content_type === MEDIA_TYPES.video ? 1 : 0)) {