@torrent-tv/proxy 2.9.11 → 2.9.12

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/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 2.9.12
2
+
3
+ - **Fix**: Eliminate PTS-gap glitches (stutter/freeze on video while audio keeps playing) at start and after seeking, for both transcode modes:
4
+ - **Branch A — video re-encoded** (`video=libx264`): use a fixed GOP (`-g`/`-keyint_min` = segmentDuration × fps, `-sc_threshold 0`) instead of `-force_key_frames expr:gte(t,n_forced*SEG)`. The old expression broke after a seek because `t` is shifted by `-output_ts_offset`, forcing keyframes at the wrong places and producing segments that did not line up with the playlist grid. A frame-count GOP is offset-independent → every segment is exactly segmentDuration and starts on a keyframe.
5
+ - **Branch B — video copied** (`video=copy`, only audio transcoded): keep the source's real timestamps with `-copyts` (and accurate seek) instead of relabelling onto a 4 s grid that does not match the source's own keyframe positions. Relabelling was the source of the holes in this mode.
6
+ - **Chore**: Session-start log tags the active branch (`branch=A(reencode,fixed-gop)` / `branch=B(copy,copyts)`) so glitches can be attributed to the right mode.
7
+ - **Fix**: Log timestamps reverted to UTC (`HH:MM:SS.mmm`) so the proxy and browser logs share one timezone and line up exactly when correlated.
8
+
1
9
  ## 2.9.11
2
10
 
3
11
  - **New**: Seek-aware torrent piece prioritization. On every `/stream` range request the proxy now marks the torrent pieces at the read position **critical** (`TorrentPool.prioritizeByteRange` → `torrent.critical`, ~8 MB window). After a seek, ffmpeg opens the input at a new byte offset; previously those pieces waited behind the sequential download backlog, so seeking into an undownloaded region stalled ~15-18 s while the proxy fetched data. Now the seek position jumps the download queue.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torrent-tv/proxy",
3
- "version": "2.9.11",
3
+ "version": "2.9.12",
4
4
  "description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "publishConfig": {
@@ -616,6 +616,9 @@ export class HlsSessionManager {
616
616
  `transcode ${sessionId} start "${logName}" ` +
617
617
  `video=${transcodeVideo ? `${this.videoEncoder.name}${softwarePreset ? `/${softwarePreset}` : ""}` : "copy"} ` +
618
618
  `audio=${transcodeAudio ? "aac" : "copy"} ` +
619
+ // Branch tag for log correlation: A = video re-encode (fixed GOP, grid
620
+ // aligned, ts-offset); B = video copy (cut at source keyframes, copyts).
621
+ `branch=${transcodeVideo ? "A(reencode,fixed-gop)" : "B(copy,copyts)"} ` +
619
622
  `${sourceWidth && sourceHeight ? `src=${sourceWidth}x${sourceHeight} ` : ""}` +
620
623
  `duration=${hasDuration ? formatSeconds(durationSeconds) : "unknown"} segments=${segmentCount}`
621
624
  );
@@ -740,14 +743,27 @@ export class HlsSessionManager {
740
743
  args.push(...this.videoEncoder.inputArgs);
741
744
  }
742
745
  if (startSeconds > 0) {
743
- // Fast keyframe-level seek before -i (skips decoding earlier frames).
744
- args.push("-ss", String(startSeconds));
746
+ // Accurate seek before -i (decodes from the preceding keyframe and trims
747
+ // to the exact point), so the first output frame is exactly at startSeconds.
748
+ args.push("-accurate_seek", "-ss", String(startSeconds));
745
749
  }
746
750
  args.push("-i", session.inputUrl);
747
- if (startSeconds > 0) {
748
- // Keep output timestamps on the original timeline so video.currentTime
749
- // matches the requested position.
750
- args.push("-output_ts_offset", String(startSeconds));
751
+ if (session.transcodeVideo) {
752
+ // Branch A (re-encode): fixed GOP makes keyframes land exactly on the
753
+ // segment grid; relabel output onto the original timeline so segment N
754
+ // carries PTS = N × segmentDuration.
755
+ if (startSeconds > 0) {
756
+ args.push("-output_ts_offset", String(startSeconds));
757
+ }
758
+ } else {
759
+ // Branch B (video copied — only audio is transcoded): we cannot insert
760
+ // keyframes, so segments are cut at the source's own keyframes. Keep the
761
+ // source's real timestamps (`-copyts`) instead of relabelling, so the
762
+ // copied frames stay continuous across segment boundaries and seek-restarts
763
+ // (relabelling to a 4 s grid that does not match the real keyframe times is
764
+ // exactly what produced the PTS holes / glitches). Audio is transcoded on
765
+ // the same timeline.
766
+ args.push("-copyts");
751
767
  }
752
768
  args.push(
753
769
  "-map",
@@ -90,7 +90,17 @@ export function softwareDescriptor() {
90
90
  "-crf", SOFTWARE_CRF,
91
91
  "-threads", String(CPU_THREADS),
92
92
  "-pix_fmt", "yuv420p",
93
- ...keyFrameArgs(segmentDurationSec)
93
+ // Fixed GOP: a keyframe exactly every (segmentDurationSec × fps) frames,
94
+ // scene-cut keyframes disabled. This is frame-count based, so it is
95
+ // independent of the PTS offset used on seek-restart — every HLS segment
96
+ // is exactly segmentDurationSec long and starts on a keyframe, so segment
97
+ // boundaries line up with the synthetic playlist with no gaps. (The old
98
+ // `-force_key_frames expr:gte(t,n_forced*SEG)` broke after a seek because
99
+ // `t` is offset by `-output_ts_offset`, forcing keyframes at the wrong
100
+ // places.)
101
+ "-g", String(segmentDurationSec * TRANSCODE_FPS),
102
+ "-keyint_min", String(segmentDurationSec * TRANSCODE_FPS),
103
+ "-sc_threshold", "0"
94
104
  ];
95
105
  }
96
106
  };
package/utils/logger.js CHANGED
@@ -10,13 +10,14 @@ import chalk from "chalk";
10
10
  const PREFIX = "[proxy-client]";
11
11
 
12
12
  /**
13
- * Return the current time as a compact ISO-8601 string, e.g. `12:34:56.789`.
14
- * Uses only the time portion to keep log lines short.
13
+ * Return the current time as a compact ISO-8601 (UTC) string, e.g.
14
+ * `12:34:56.789`. UTC is used deliberately so proxy and browser logs share the
15
+ * same timezone and line up exactly when correlating them.
15
16
  *
16
17
  * @returns {string}
17
18
  */
18
19
  function ts() {
19
- return new Date().toISOString().slice(11, 23); // "HH:MM:SS.mmm"
20
+ return new Date().toISOString().slice(11, 23); // "HH:MM:SS.mmm" (UTC)
20
21
  }
21
22
 
22
23
  /**