@torrent-tv/proxy 2.94.2 → 2.94.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torrent-tv/proxy",
3
- "version": "2.94.2",
3
+ "version": "2.94.3",
4
4
  "description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {
@@ -21,16 +21,7 @@ export function h264Configuration(avcc) {
21
21
 
22
22
  function readSps(nal, includeOrder = false) {
23
23
  if ((nal[0] & 31) !== 7 || nal[0] & 128) throw new Error("AVC configuration entry is not an SPS.");
24
- const bytes = [];
25
- for (let at = 1, zeroes = 0; at < nal.length; at++) {
26
- const byte = nal[at];
27
- if (zeroes >= 2 && byte === 3) {
28
- if (at + 1 >= nal.length || nal[at + 1] > 3) throw new Error("AVC emulation prevention byte is invalid.");
29
- zeroes = 0; continue;
30
- }
31
- bytes.push(byte); zeroes = byte === 0 ? zeroes + 1 : 0;
32
- }
33
- const bits = new Bits(Buffer.from(bytes));
24
+ const bits = new Bits(unescapeNal(nal));
34
25
  const profile = bits.uint(8), constraints = bits.uint(8), level = bits.uint(8);
35
26
  bits.ue();
36
27
  let chroma = 1, separate = 0, depth = 8;
@@ -131,14 +122,16 @@ export function avcOrderParameters(sps, pps) {
131
122
  return { ...facts.pictureOrder, bottomFieldOrderPresent: bits.uint(1) === 1 };
132
123
  }
133
124
 
125
+ /**
126
+ * Remove every emulation prevention byte: a 0x03 after two zero bytes, whatever follows it. H.264 §7.4.1
127
+ * forbids 0x000003 before a byte above 0x03, but encoders write it (LostFilm's LostCoder) and decoders drop
128
+ * it (ffmpeg's ff_h2645_extract_rbsp), so refusing it refuses files every player plays.
129
+ */
134
130
  export function unescapeNal(nal) {
135
131
  const bytes = [];
136
132
  for (let at = 1, zeroes = 0; at < nal.length; at++) {
137
133
  const byte = nal[at];
138
- if (zeroes >= 2 && byte === 3) {
139
- if (at + 1 >= nal.length || nal[at + 1] > 3) throw new Error("AVC escape byte is invalid.");
140
- zeroes = 0; continue;
141
- }
134
+ if (zeroes >= 2 && byte === 3) { zeroes = 0; continue; }
142
135
  bytes.push(byte);
143
136
  zeroes = byte === 0 ? zeroes + 1 : 0;
144
137
  }