jmuxer 2.0.2 → 2.0.5

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.
@@ -98,8 +98,30 @@ export class H264Parser {
98
98
  picWidthInMbsMinus1,
99
99
  picHeightInMapUnitsMinus1,
100
100
  frameMbsOnlyFlag,
101
- scalingListCount;
102
- decoder.readUByte();
101
+ scalingListCount,
102
+ fps = 0;
103
+ decoder.readUByte(); // skip NAL header
104
+
105
+ // rewrite NAL
106
+ let rbsp = [],
107
+ hdr_bytes = 1,
108
+ nal_bytes = data.byteLength;
109
+ for (let i = hdr_bytes; i < nal_bytes; i ++) {
110
+ if ((i + 2) < nal_bytes && decoder.readBits(24, false) === 0x000003) {
111
+ rbsp.push(decoder.readBits(8));
112
+ rbsp.push(decoder.readBits(8));
113
+ i += 2;
114
+
115
+ // emulation_prevention_three_byte
116
+ decoder.readBits(8);
117
+ }
118
+ else {
119
+ rbsp.push(decoder.readBits(8));
120
+ }
121
+ }
122
+ decoder.setData(new Uint8Array(rbsp));
123
+ // end of rewrite data
124
+
103
125
  profileIdc = decoder.readUByte(); // profile_idc
104
126
  profileCompat = decoder.readBits(5); // constraint_set[0-4]_flag, u(5)
105
127
  decoder.skipBits(3); // reserved_zero_3bits u(3),
@@ -191,7 +213,7 @@ export class H264Parser {
191
213
  break;
192
214
  }
193
215
  }
194
- if (sarRatio) {
216
+ if (sarRatio && sarRatio[0] > 0 && sarRatio[1] > 0) {
195
217
  sarScale = sarRatio[0] / sarRatio[1];
196
218
  }
197
219
  }
@@ -212,9 +234,14 @@ export class H264Parser {
212
234
  let timeScale = decoder.readUInt();
213
235
  let fixedFrameRate = decoder.readBoolean();
214
236
  let frameDuration = timeScale / (2 * unitsInTick);
237
+
238
+ if (fixedFrameRate) {
239
+ fps = frameDuration;
240
+ }
215
241
  }
216
242
  }
217
243
  return {
244
+ fps: fps > 0 ? fps : undefined,
218
245
  width: Math.ceil((((picWidthInMbsMinus1 + 1) * 16) - frameCropLeftOffset * 2 - frameCropRightOffset * 2) * sarScale),
219
246
  height: ((2 - frameMbsOnlyFlag) * (picHeightInMapUnitsMinus1 + 1) * 16) - ((frameMbsOnlyFlag ? 2 : 4) * (frameCropTopOffset + frameCropBottomOffset)),
220
247
  };
@@ -234,6 +261,7 @@ export class H264Parser {
234
261
  parseSPS(sps) {
235
262
  var config = H264Parser.readSPS(new Uint8Array(sps));
236
263
 
264
+ this.track.fps = config.fps;
237
265
  this.track.width = config.width;
238
266
  this.track.height = config.height;
239
267
  this.track.sps = [new Uint8Array(sps)];
@@ -102,4 +102,8 @@ export class AACRemuxer extends BaseRemuxer {
102
102
 
103
103
  return new Uint8Array(payload.buffer, 0, this.mp4track.len);
104
104
  }
105
+
106
+ getAacParser() {
107
+ return this.aac;
108
+ }
105
109
  }
@@ -16,6 +16,7 @@ export class H264Remuxer extends BaseRemuxer {
16
16
  fragmented: true,
17
17
  sps: '',
18
18
  pps: '',
19
+ fps: 30,
19
20
  width: 0,
20
21
  height: 0,
21
22
  timescale: timescale,
@@ -51,6 +52,7 @@ export class H264Remuxer extends BaseRemuxer {
51
52
  size: size,
52
53
  keyFrame: frame.keyFrame,
53
54
  duration: frame.duration,
55
+ compositionTimeOffset: frame.compositionTimeOffset
54
56
  });
55
57
  }
56
58
  }
@@ -81,7 +83,7 @@ export class H264Remuxer extends BaseRemuxer {
81
83
  mp4Sample = {
82
84
  size: sample.size,
83
85
  duration: duration,
84
- cts: 0,
86
+ cts: sample.compositionTimeOffset || 0,
85
87
  flags: {
86
88
  isLeading: 0,
87
89
  isDependedOn: 0,
@@ -100,7 +102,7 @@ export class H264Remuxer extends BaseRemuxer {
100
102
  }
101
103
 
102
104
  if (!samples.length) return null;
103
-
105
+
104
106
  return new Uint8Array(payload.buffer, 0, this.mp4track.len);
105
107
  }
106
108
  }
@@ -10,6 +10,12 @@ export class ExpGolomb {
10
10
  this.bitLength = data.byteLength * 8;
11
11
  }
12
12
 
13
+ setData(data) {
14
+ this.data = data;
15
+ this.index = 0;
16
+ this.bitLength = data.byteLength * 8;
17
+ }
18
+
13
19
  get bitsAvailable() {
14
20
  return this.bitLength - this.index;
15
21
  }
package/test/parser.js CHANGED
@@ -1,5 +1,6 @@
1
1
  //import { assert } from 'chai';
2
2
 
3
+ import { BaseRemuxer } from '../src/remuxer/base.js';
3
4
  import { H264Parser } from '../src/parsers/h264.js';
4
5
  import { AACParser } from '../src/parsers/aac.js';
5
6
 
@@ -25,9 +26,10 @@ describe('Parser tests --', function() {
25
26
  it('AAC frame length should be 284', function() {
26
27
  assert.equal(AACParser.getFrameLength(aac), 284);
27
28
  });
28
-
29
+
29
30
  it('Number of extracted AAC frames should be 1', function() {
30
- var result = AACParser.extractAAC(aac);
31
+ const parser = new AACParser(new BaseRemuxer());
32
+ var result = parser.extractAAC(aac);
31
33
  assert.equal(result.length, 1);
32
34
  });
33
35
  });