@alessmicrosystems/mpegts.js 1.8.1 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,6 +14,69 @@ mpegts.js works by transmuxing MPEG2-TS stream into ISO BMFF (Fragmented MP4) se
14
14
  [Media Source Extensions]: https://w3c.github.io/media-source/
15
15
 
16
16
  ## News
17
+ - **v1.8.2** (alessmicrosystems fork)
18
+
19
+ **Audio PTS wrap-around detection and correction:**
20
+ - Detects 33-bit PTS counter wrap-around in live MPEG-TS audio streams
21
+ - Automatically normalizes forward-wrapped timestamps to maintain monotonic time
22
+ - Drops stale pre-wrap timestamps that arrive after the wrap point
23
+
24
+ **Audio timestamp discontinuity resilience (mp4-remuxer):**
25
+ - Detects massive audio timestamp discontinuities (>30s or >180 frame durations) caused by audio PID switching
26
+ - Resets the audio timeline reference instead of dropping all frames (backward) or generating thousands of silent frames (forward)
27
+ - Prevents audio dropout and long silence gaps when switching audio tracks on live streams
28
+
29
+ **Startup audio timestamp anchoring:**
30
+ - Snaps the first audio sample's PTS to the video anchor DTS when drift exceeds 5 seconds
31
+ - Filters out stashed audio payloads with timestamps more than 1.5s behind the video anchor before replay
32
+ - Prevents remuxer-level discontinuity events on audio PID switches during stream startup
33
+ - Applied to all six audio codecs (AAC, LOAS-AAC, AC-3, E-AC-3, Opus, MP3)
34
+
35
+ **`selectAudioPid` hardened against stale codec state:**
36
+ - Clears all legacy codec PID mappings and rebuilds only the requested track
37
+ - `selectAudioPid(0)` correctly restores the default audio route
38
+ - Resets audio init state on PID switch so the new codec config is cleanly dispatched
39
+
40
+ **Stashed audio codec-aware replay:**
41
+ - Audio payloads stashed before video init are tagged with their codec
42
+ - Replayed through the correct parser instead of always using AAC
43
+ - Fixes silent/garbled audio on tracks switched during stream startup
44
+
45
+ **`preferredAudioPid` extended to all stream types:**
46
+ - Previously only applied during AC-3/E-AC-3 auto-fallback
47
+ - Now also selects the preferred track on AAC, MP3, and other codec streams
48
+ - Respects the config option on first PMT parse regardless of primary codec
49
+
50
+ - **v1.8.1** (alessmicrosystems fork)
51
+
52
+ **Audio track selection for MPEG-TS live streams:**
53
+ - `TRACKS_UPDATED` player event reports all available audio tracks (PID, codec, language) and subtitle tracks from PMT parsing
54
+ - `switchAudioPid(pid)` API for in-place audio PID switching
55
+ - `preferredAudioPid` config option for pre-selecting an audio track before `load()`
56
+ - ISO 639 language descriptor extraction for all audio PIDs
57
+
58
+ **AC-3 / E-AC-3 auto-fallback:**
59
+ - Detects browser-incompatible AC-3/E-AC-3 primary audio
60
+ - Auto-switches to the first compatible AAC or MP3 alternative without user intervention
61
+ - Respects `preferredAudioPid` config when set
62
+
63
+ **Keyframe-gated media dispatch:**
64
+ - Media segments are held until the first H.264/H.265 IDR keyframe is seen after init segment dispatch
65
+ - Audio data before the first keyframe is stashed with its codec tag and replayed through the correct parser
66
+ - 6-second fallback timeout prevents indefinite stalling on streams with missing keyframes
67
+
68
+ **SEI support:**
69
+ - `SEI_ARRIVED` event for H.264/H.265 Supplemental Enhancement Information NAL units
70
+ - `SEIData` type with `type`, `size`, `uuid`, `user_data`, and optional `pts` fields
71
+
72
+ **Bug fixes:**
73
+ - Fixed stashed audio replay always using AAC parser regardless of actual codec (affected MP3 fallback streams)
74
+ - Fixed `selectAudioPid(0)` not restoring default audio route — now clears all stale codec PID mappings
75
+ - Fixed `audio_metadata_changed_` flag being set to `false` on video init instead of audio init (copy-paste bug)
76
+ - Fixed `parseMP3Payload` missing `audio_last_sample_pts_` tracking
77
+ - Fixed MP3 init segment missing `refSampleDuration`
78
+ - Fixed PMT multi-section parsing — `parsed_sections` map prevents duplicate audio entries
79
+
17
80
  - **v1.8.0**
18
81
 
19
82
  Support working on **iOS Safari** with iOS 17.1+ through Apple's [ManagedMediaSource API](https://github.com/w3c/media-source/issues/320)
@@ -59,6 +122,8 @@ mpegts.js works by transmuxing MPEG2-TS stream into ISO BMFF (Fragmented MP4) se
59
122
  - Low CPU overhead and low memory usage (JS heap takes about 10MiB for each instance)
60
123
  - Support extracting PES private data (stream_type=0x06) like ARIB B24 subtitles (with [aribb24.js][])
61
124
  - Support Timed ID3 Metadata (stream_type=0x15) callback (TIMED_ID3_METADATA_ARRIVED)
125
+ - Multi-audio track support with PID switching for MPEG-TS live streams
126
+ - Automatic AC-3 / E-AC-3 fallback to AAC or MP3 for browser compatibility
62
127
 
63
128
  [aribb24.js]: https://github.com/monyone/aribb24.js
64
129
 
@@ -32,6 +32,10 @@ declare class TSDemuxer extends BaseDemuxer {
32
32
  private stashed_audio_before_video_init_;
33
33
  private _last_dispatch_block_reason_;
34
34
  private video_init_dispatch_time_;
35
+ private audio_wrap_log_count_;
36
+ private audio_stale_drop_log_count_;
37
+ private audio_startup_align_log_count_;
38
+ private audio_startup_drop_log_count_;
35
39
  private active_audio_pid_;
36
40
  private loas_previous_frame;
37
41
  private video_track_;
@@ -99,6 +103,9 @@ declare class TSDemuxer extends BaseDemuxer {
99
103
  private dispatchVideoInitSegment;
100
104
  private dispatchVideoMediaSegment;
101
105
  private dispatchAudioMediaSegment;
106
+ private normalizeIncomingAudioPtsMilliseconds;
107
+ private getStartupAudioAnchorMilliseconds;
108
+ private normalizeStartupAudioPtsMilliseconds;
102
109
  private stashAudioBeforeVideoInit;
103
110
  private dispatchAudioVideoMediaSegment;
104
111
  private parseADTSAACPayload;