xgplayer-transmuxer 3.0.0-alpha.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/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/es/codec/aac.d.ts +34 -0
- package/es/codec/aac.js +242 -0
- package/es/codec/avc.d.ts +35 -0
- package/es/codec/avc.js +250 -0
- package/es/codec/hevc.d.ts +38 -0
- package/es/codec/hevc.js +202 -0
- package/es/codec/index.d.ts +4 -0
- package/es/codec/nalu.d.ts +11 -0
- package/es/codec/nalu.js +194 -0
- package/es/flv/amf.d.ts +16 -0
- package/es/flv/amf.js +247 -0
- package/es/flv/fixer.d.ts +31 -0
- package/es/flv/fixer.js +437 -0
- package/es/flv/index.d.ts +65 -0
- package/es/flv/index.js +441 -0
- package/es/index.d.ts +5 -0
- package/es/index.js +13 -0
- package/es/model/audio-sample.d.ts +18 -0
- package/es/model/audio-sample.js +26 -0
- package/es/model/audio-track.d.ts +38 -0
- package/es/model/audio-track.js +94 -0
- package/es/model/index.d.ts +6 -0
- package/es/model/metadata-track.d.ts +36 -0
- package/es/model/metadata-track.js +100 -0
- package/es/model/types.d.ts +26 -0
- package/es/model/types.js +31 -0
- package/es/model/video-sample.d.ts +44 -0
- package/es/model/video-sample.js +66 -0
- package/es/model/video-track.d.ts +45 -0
- package/es/model/video-track.js +99 -0
- package/es/mp4/fmp4-remuxer.d.ts +32 -0
- package/es/mp4/fmp4-remuxer.js +172 -0
- package/es/mp4/index.d.ts +4 -0
- package/es/mp4/logger.d.ts +13 -0
- package/es/mp4/logger.js +97 -0
- package/es/mp4/mp4-demuxer.d.ts +24 -0
- package/es/mp4/mp4-demuxer.js +268 -0
- package/es/mp4/mp4-parser.d.ts +161 -0
- package/es/mp4/mp4-parser.js +776 -0
- package/es/mp4/mp4-remuxer.d.ts +23 -0
- package/es/mp4/mp4-remuxer.js +273 -0
- package/es/mp4/mp4.d.ts +56 -0
- package/es/mp4/mp4.js +574 -0
- package/es/mpeg-ts/fixer.d.ts +23 -0
- package/es/mpeg-ts/fixer.js +383 -0
- package/es/mpeg-ts/index.d.ts +60 -0
- package/es/mpeg-ts/index.js +480 -0
- package/es/utils/env.d.ts +4 -0
- package/es/utils/env.js +10 -0
- package/es/utils/exp-golomb.d.ts +17 -0
- package/es/utils/exp-golomb.js +172 -0
- package/es/utils/index.d.ts +11 -0
- package/es/utils/index.js +77 -0
- package/es/utils/logger.d.ts +9 -0
- package/es/utils/logger.js +45 -0
- package/es/utils/utf8.d.ts +9 -0
- package/es/utils/utf8.js +91 -0
- package/package.json +25 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import 'core-js/modules/es.reflect.construct.js';
|
|
2
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
3
|
+
import _inherits from '@babel/runtime/helpers/inherits';
|
|
4
|
+
import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
|
|
5
|
+
import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
|
|
6
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
7
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
8
|
+
import { TrackType } from './types.js';
|
|
9
|
+
|
|
10
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
11
|
+
|
|
12
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
13
|
+
|
|
14
|
+
var Sample = // second
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {Object} data
|
|
18
|
+
* @param {number} pts
|
|
19
|
+
*/
|
|
20
|
+
function Sample(data, pts) {
|
|
21
|
+
_classCallCheck(this, Sample);
|
|
22
|
+
|
|
23
|
+
_defineProperty(this, "time", 0);
|
|
24
|
+
|
|
25
|
+
this.data = data;
|
|
26
|
+
this.originPts = this.pts = pts;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
var FlvScriptSample = /*#__PURE__*/function (_Sample) {
|
|
30
|
+
_inherits(FlvScriptSample, _Sample);
|
|
31
|
+
|
|
32
|
+
var _super = _createSuper(FlvScriptSample);
|
|
33
|
+
|
|
34
|
+
function FlvScriptSample() {
|
|
35
|
+
_classCallCheck(this, FlvScriptSample);
|
|
36
|
+
|
|
37
|
+
return _super.apply(this, arguments);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return FlvScriptSample;
|
|
41
|
+
}(Sample);
|
|
42
|
+
var SeiSample = /*#__PURE__*/function (_Sample2) {
|
|
43
|
+
_inherits(SeiSample, _Sample2);
|
|
44
|
+
|
|
45
|
+
var _super2 = _createSuper(SeiSample);
|
|
46
|
+
|
|
47
|
+
function SeiSample() {
|
|
48
|
+
_classCallCheck(this, SeiSample);
|
|
49
|
+
|
|
50
|
+
return _super2.apply(this, arguments);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return SeiSample;
|
|
54
|
+
}(Sample);
|
|
55
|
+
var MetadataTrack = /*#__PURE__*/function () {
|
|
56
|
+
function MetadataTrack() {
|
|
57
|
+
_classCallCheck(this, MetadataTrack);
|
|
58
|
+
|
|
59
|
+
_defineProperty(this, "id", 3);
|
|
60
|
+
|
|
61
|
+
_defineProperty(this, "type", TrackType.METADATA);
|
|
62
|
+
|
|
63
|
+
_defineProperty(this, "timescale", 0);
|
|
64
|
+
|
|
65
|
+
_defineProperty(this, "flvScriptSamples", []);
|
|
66
|
+
|
|
67
|
+
_defineProperty(this, "seiSamples", []);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
_createClass(MetadataTrack, [{
|
|
71
|
+
key: "exist",
|
|
72
|
+
value:
|
|
73
|
+
/**
|
|
74
|
+
* @returns {boolean}
|
|
75
|
+
*/
|
|
76
|
+
function exist() {
|
|
77
|
+
return !!((this.flvScriptSamples.length || this.seiSamples.length) && this.timescale);
|
|
78
|
+
}
|
|
79
|
+
}, {
|
|
80
|
+
key: "reset",
|
|
81
|
+
value: function reset() {
|
|
82
|
+
this.timescale = 0;
|
|
83
|
+
this.flvScriptSamples = [];
|
|
84
|
+
this.seiSamples = [];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @returns {boolean}
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
}, {
|
|
91
|
+
key: "hasSample",
|
|
92
|
+
value: function hasSample() {
|
|
93
|
+
return !!(this.flvScriptSamples.length || this.seiSamples.length);
|
|
94
|
+
}
|
|
95
|
+
}]);
|
|
96
|
+
|
|
97
|
+
return MetadataTrack;
|
|
98
|
+
}();
|
|
99
|
+
|
|
100
|
+
export { FlvScriptSample, MetadataTrack, SeiSample };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type TrackType = string;
|
|
2
|
+
export namespace TrackType {
|
|
3
|
+
const VIDEO: string;
|
|
4
|
+
const AUDIO: string;
|
|
5
|
+
const METADATA: string;
|
|
6
|
+
}
|
|
7
|
+
export type VideoCodecType = string;
|
|
8
|
+
export namespace VideoCodecType {
|
|
9
|
+
const AVC: string;
|
|
10
|
+
const HEVC: string;
|
|
11
|
+
}
|
|
12
|
+
export type AudioCodecType = string;
|
|
13
|
+
export namespace AudioCodecType {
|
|
14
|
+
const AAC: string;
|
|
15
|
+
const G711PCMA: string;
|
|
16
|
+
const G711PCMU: string;
|
|
17
|
+
}
|
|
18
|
+
export type WarningType = string;
|
|
19
|
+
export namespace WarningType {
|
|
20
|
+
const LARGE_AV_SHIFT: string;
|
|
21
|
+
const LARGE_VIDEO_GAP: string;
|
|
22
|
+
const LARGE_VIDEO_GAP_BETWEEN_CHUNK: string;
|
|
23
|
+
const LARGE_AUDIO_GAP: string;
|
|
24
|
+
const AUDIO_FILLED: string;
|
|
25
|
+
const AUDIO_DROPPED: string;
|
|
26
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** @enum {string} */
|
|
2
|
+
var TrackType = {
|
|
3
|
+
VIDEO: 'video',
|
|
4
|
+
AUDIO: 'audio',
|
|
5
|
+
METADATA: 'metadata'
|
|
6
|
+
};
|
|
7
|
+
/** @enum {string} */
|
|
8
|
+
|
|
9
|
+
var VideoCodecType = {
|
|
10
|
+
AVC: 'avc',
|
|
11
|
+
HEVC: 'hevc'
|
|
12
|
+
};
|
|
13
|
+
/** @enum {string} */
|
|
14
|
+
|
|
15
|
+
var AudioCodecType = {
|
|
16
|
+
AAC: 'aac',
|
|
17
|
+
G711PCMA: 'g7110a',
|
|
18
|
+
G711PCMU: 'g7110m'
|
|
19
|
+
};
|
|
20
|
+
/** @enum {string} */
|
|
21
|
+
|
|
22
|
+
var WarningType = {
|
|
23
|
+
LARGE_AV_SHIFT: 'LARGE_AV_SHIFT',
|
|
24
|
+
LARGE_VIDEO_GAP: 'LARGE_VIDEO_GAP',
|
|
25
|
+
LARGE_VIDEO_GAP_BETWEEN_CHUNK: 'LARGE_VIDEO_GAP_BETWEEN_CHUNK',
|
|
26
|
+
LARGE_AUDIO_GAP: 'LARGE_AUDIO_GAP',
|
|
27
|
+
AUDIO_FILLED: 'AUDIO_FILLED',
|
|
28
|
+
AUDIO_DROPPED: 'AUDIO_DROPPED'
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { AudioCodecType, TrackType, VideoCodecType, WarningType };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} VideoFlag
|
|
3
|
+
* @property {number} [isLeading=0]
|
|
4
|
+
* @property {number} [dependsOn=1]
|
|
5
|
+
* @property {number} [isDependedOn=0]
|
|
6
|
+
* @property {number} [hasRedundancy=0]
|
|
7
|
+
* @property {number} [paddingValue=0]
|
|
8
|
+
* @property {number} [degradationPriority=0]
|
|
9
|
+
* @property {number} [isNonSyncSample=1]
|
|
10
|
+
*/
|
|
11
|
+
export class VideoSample {
|
|
12
|
+
/**
|
|
13
|
+
* @param {number} pts
|
|
14
|
+
* @param {number} dts
|
|
15
|
+
* @param {Uint8Array[]} [units]
|
|
16
|
+
*/
|
|
17
|
+
constructor(pts: number, dts: number, units?: Uint8Array[]);
|
|
18
|
+
/** @type {VideoFlag} */
|
|
19
|
+
flag: VideoFlag;
|
|
20
|
+
keyframe: boolean;
|
|
21
|
+
gopId: number;
|
|
22
|
+
duration: number;
|
|
23
|
+
size: number;
|
|
24
|
+
units: any[];
|
|
25
|
+
chromaFormat: number;
|
|
26
|
+
originPts: number;
|
|
27
|
+
pts: number;
|
|
28
|
+
originDts: number;
|
|
29
|
+
dts: number;
|
|
30
|
+
/**
|
|
31
|
+
* @returns {number}
|
|
32
|
+
*/
|
|
33
|
+
get cts(): number;
|
|
34
|
+
setToKeyframe(): void;
|
|
35
|
+
}
|
|
36
|
+
export type VideoFlag = {
|
|
37
|
+
isLeading?: number;
|
|
38
|
+
dependsOn?: number;
|
|
39
|
+
isDependedOn?: number;
|
|
40
|
+
hasRedundancy?: number;
|
|
41
|
+
paddingValue?: number;
|
|
42
|
+
degradationPriority?: number;
|
|
43
|
+
isNonSyncSample?: number;
|
|
44
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
2
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {Object} VideoFlag
|
|
7
|
+
* @property {number} [isLeading=0]
|
|
8
|
+
* @property {number} [dependsOn=1]
|
|
9
|
+
* @property {number} [isDependedOn=0]
|
|
10
|
+
* @property {number} [hasRedundancy=0]
|
|
11
|
+
* @property {number} [paddingValue=0]
|
|
12
|
+
* @property {number} [degradationPriority=0]
|
|
13
|
+
* @property {number} [isNonSyncSample=1]
|
|
14
|
+
*/
|
|
15
|
+
var VideoSample = /*#__PURE__*/function () {
|
|
16
|
+
/** @type {VideoFlag} */
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {number} pts
|
|
20
|
+
* @param {number} dts
|
|
21
|
+
* @param {Uint8Array[]} [units]
|
|
22
|
+
*/
|
|
23
|
+
function VideoSample(pts, dts, units) {
|
|
24
|
+
_classCallCheck(this, VideoSample);
|
|
25
|
+
|
|
26
|
+
_defineProperty(this, "flag", {});
|
|
27
|
+
|
|
28
|
+
_defineProperty(this, "keyframe", false);
|
|
29
|
+
|
|
30
|
+
_defineProperty(this, "gopId", 0);
|
|
31
|
+
|
|
32
|
+
_defineProperty(this, "duration", 0);
|
|
33
|
+
|
|
34
|
+
_defineProperty(this, "size", 0);
|
|
35
|
+
|
|
36
|
+
_defineProperty(this, "units", []);
|
|
37
|
+
|
|
38
|
+
_defineProperty(this, "chromaFormat", 420);
|
|
39
|
+
|
|
40
|
+
this.originPts = this.pts = pts;
|
|
41
|
+
this.originDts = this.dts = dts;
|
|
42
|
+
if (units) this.units = units;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @returns {number}
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
_createClass(VideoSample, [{
|
|
50
|
+
key: "cts",
|
|
51
|
+
get: function get() {
|
|
52
|
+
return this.pts - this.dts;
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "setToKeyframe",
|
|
56
|
+
value: function setToKeyframe() {
|
|
57
|
+
this.keyframe = true;
|
|
58
|
+
this.flag.dependsOn = 2;
|
|
59
|
+
this.flag.isNonSyncSample = 0;
|
|
60
|
+
}
|
|
61
|
+
}]);
|
|
62
|
+
|
|
63
|
+
return VideoSample;
|
|
64
|
+
}();
|
|
65
|
+
|
|
66
|
+
export { VideoSample };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export class VideoTrack {
|
|
2
|
+
/** @readonly */
|
|
3
|
+
readonly id: 1;
|
|
4
|
+
/** @readonly */
|
|
5
|
+
readonly type: string;
|
|
6
|
+
codecType: string;
|
|
7
|
+
pid: number;
|
|
8
|
+
/** @type {Uint8Array} */
|
|
9
|
+
hvcC: Uint8Array;
|
|
10
|
+
codec: string;
|
|
11
|
+
timescale: number;
|
|
12
|
+
formatTimescale: number;
|
|
13
|
+
sequenceNumber: number;
|
|
14
|
+
baseMediaDecodeTime: number;
|
|
15
|
+
baseDts: number;
|
|
16
|
+
duration: number;
|
|
17
|
+
warnings: any[];
|
|
18
|
+
/** @type {import('./video-sample').VideoSample[]} */
|
|
19
|
+
samples: import('./video-sample').VideoSample[];
|
|
20
|
+
/** @type {Uint8Array[]} */
|
|
21
|
+
pps: Uint8Array[];
|
|
22
|
+
/** @type {Uint8Array[]} */
|
|
23
|
+
sps: Uint8Array[];
|
|
24
|
+
/** @type {Uint8Array[]} */
|
|
25
|
+
vps: Uint8Array[];
|
|
26
|
+
fpsNum: number;
|
|
27
|
+
fpsDen: number;
|
|
28
|
+
/** @type {[number, number]} */
|
|
29
|
+
sarRatio: [number, number];
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
nalUnitSize: number;
|
|
33
|
+
present: boolean;
|
|
34
|
+
/** @type {any} */
|
|
35
|
+
ext: any;
|
|
36
|
+
reset(): void;
|
|
37
|
+
/**
|
|
38
|
+
* @returns {boolean}
|
|
39
|
+
*/
|
|
40
|
+
exist(): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* @returns {boolean}
|
|
43
|
+
*/
|
|
44
|
+
hasSample(): boolean;
|
|
45
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
2
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
import { TrackType, VideoCodecType } from './types.js';
|
|
5
|
+
|
|
6
|
+
var VideoTrack = /*#__PURE__*/function () {
|
|
7
|
+
function VideoTrack() {
|
|
8
|
+
_classCallCheck(this, VideoTrack);
|
|
9
|
+
|
|
10
|
+
_defineProperty(this, "id", 1);
|
|
11
|
+
|
|
12
|
+
_defineProperty(this, "type", TrackType.VIDEO);
|
|
13
|
+
|
|
14
|
+
_defineProperty(this, "codecType", VideoCodecType.AVC);
|
|
15
|
+
|
|
16
|
+
_defineProperty(this, "pid", -1);
|
|
17
|
+
|
|
18
|
+
_defineProperty(this, "hvcC", null);
|
|
19
|
+
|
|
20
|
+
_defineProperty(this, "codec", '');
|
|
21
|
+
|
|
22
|
+
_defineProperty(this, "timescale", 0);
|
|
23
|
+
|
|
24
|
+
_defineProperty(this, "formatTimescale", 0);
|
|
25
|
+
|
|
26
|
+
_defineProperty(this, "sequenceNumber", 0);
|
|
27
|
+
|
|
28
|
+
_defineProperty(this, "baseMediaDecodeTime", 0);
|
|
29
|
+
|
|
30
|
+
_defineProperty(this, "baseDts", 0);
|
|
31
|
+
|
|
32
|
+
_defineProperty(this, "duration", 0);
|
|
33
|
+
|
|
34
|
+
_defineProperty(this, "warnings", []);
|
|
35
|
+
|
|
36
|
+
_defineProperty(this, "samples", []);
|
|
37
|
+
|
|
38
|
+
_defineProperty(this, "pps", []);
|
|
39
|
+
|
|
40
|
+
_defineProperty(this, "sps", []);
|
|
41
|
+
|
|
42
|
+
_defineProperty(this, "vps", []);
|
|
43
|
+
|
|
44
|
+
_defineProperty(this, "fpsNum", 0);
|
|
45
|
+
|
|
46
|
+
_defineProperty(this, "fpsDen", 0);
|
|
47
|
+
|
|
48
|
+
_defineProperty(this, "sarRatio", []);
|
|
49
|
+
|
|
50
|
+
_defineProperty(this, "width", 0);
|
|
51
|
+
|
|
52
|
+
_defineProperty(this, "height", 0);
|
|
53
|
+
|
|
54
|
+
_defineProperty(this, "nalUnitSize", 4);
|
|
55
|
+
|
|
56
|
+
_defineProperty(this, "present", false);
|
|
57
|
+
|
|
58
|
+
_defineProperty(this, "ext", void 0);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
_createClass(VideoTrack, [{
|
|
62
|
+
key: "reset",
|
|
63
|
+
value: function reset() {
|
|
64
|
+
this.sequenceNumber = this.width = this.height = this.fpsDen = this.fpsNum = this.duration = this.baseMediaDecodeTime = this.timescale = 0;
|
|
65
|
+
this.codec = '';
|
|
66
|
+
this.present = false;
|
|
67
|
+
this.pid = -1;
|
|
68
|
+
this.pps = [];
|
|
69
|
+
this.sps = [];
|
|
70
|
+
this.vps = [];
|
|
71
|
+
this.sarRatio = [];
|
|
72
|
+
this.samples = [];
|
|
73
|
+
this.warnings = [];
|
|
74
|
+
this.hvcC = null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @returns {boolean}
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
}, {
|
|
81
|
+
key: "exist",
|
|
82
|
+
value: function exist() {
|
|
83
|
+
return !!(this.pps.length && this.sps.length && this.codec);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @returns {boolean}
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
}, {
|
|
90
|
+
key: "hasSample",
|
|
91
|
+
value: function hasSample() {
|
|
92
|
+
return !!this.samples.length;
|
|
93
|
+
}
|
|
94
|
+
}]);
|
|
95
|
+
|
|
96
|
+
return VideoTrack;
|
|
97
|
+
}();
|
|
98
|
+
|
|
99
|
+
export { VideoTrack };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} RemuxResult
|
|
3
|
+
* @property {Uint8Array} [videoInitSegment]
|
|
4
|
+
* @property {Uint8Array} [audioInitSegment]
|
|
5
|
+
* @property {Uint8Array} [videoSegment]
|
|
6
|
+
* @property {Uint8Array} [audioSegment]
|
|
7
|
+
*/
|
|
8
|
+
export class FMP4Remuxer {
|
|
9
|
+
/**
|
|
10
|
+
* @param {import('../model').VideoTrack} videoTrack
|
|
11
|
+
* @param {import('../model').AudioTrack} audioTrack
|
|
12
|
+
*/
|
|
13
|
+
constructor(videoTrack: import('../model').VideoTrack, audioTrack: import('../model').AudioTrack, options: any);
|
|
14
|
+
videoTrack: import("../model").VideoTrack;
|
|
15
|
+
audioTrack: import("../model").AudioTrack;
|
|
16
|
+
log: Logger;
|
|
17
|
+
/**
|
|
18
|
+
* @param {boolean} [createInit=false]
|
|
19
|
+
* @returns {RemuxResult}
|
|
20
|
+
*/
|
|
21
|
+
remux(createInit?: boolean): RemuxResult;
|
|
22
|
+
_remuxVideo(): Uint8Array;
|
|
23
|
+
_remuxAudio(): Uint8Array;
|
|
24
|
+
reset(): void;
|
|
25
|
+
}
|
|
26
|
+
export type RemuxResult = {
|
|
27
|
+
videoInitSegment?: Uint8Array;
|
|
28
|
+
audioInitSegment?: Uint8Array;
|
|
29
|
+
videoSegment?: Uint8Array;
|
|
30
|
+
audioSegment?: Uint8Array;
|
|
31
|
+
};
|
|
32
|
+
import { Logger } from "./logger";
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
2
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
3
|
+
import 'core-js/modules/web.dom-collections.for-each.js';
|
|
4
|
+
import 'core-js/modules/es.array.iterator.js';
|
|
5
|
+
import 'core-js/modules/es.object.to-string.js';
|
|
6
|
+
import 'core-js/modules/es.typed-array.uint8-array.js';
|
|
7
|
+
import 'core-js/modules/es.typed-array.copy-within.js';
|
|
8
|
+
import 'core-js/modules/es.typed-array.every.js';
|
|
9
|
+
import 'core-js/modules/es.typed-array.fill.js';
|
|
10
|
+
import 'core-js/modules/es.typed-array.filter.js';
|
|
11
|
+
import 'core-js/modules/es.typed-array.find.js';
|
|
12
|
+
import 'core-js/modules/es.typed-array.find-index.js';
|
|
13
|
+
import 'core-js/modules/es.typed-array.for-each.js';
|
|
14
|
+
import 'core-js/modules/es.typed-array.includes.js';
|
|
15
|
+
import 'core-js/modules/es.typed-array.index-of.js';
|
|
16
|
+
import 'core-js/modules/es.typed-array.iterator.js';
|
|
17
|
+
import 'core-js/modules/es.typed-array.join.js';
|
|
18
|
+
import 'core-js/modules/es.typed-array.last-index-of.js';
|
|
19
|
+
import 'core-js/modules/es.typed-array.map.js';
|
|
20
|
+
import 'core-js/modules/es.typed-array.reduce.js';
|
|
21
|
+
import 'core-js/modules/es.typed-array.reduce-right.js';
|
|
22
|
+
import 'core-js/modules/es.typed-array.reverse.js';
|
|
23
|
+
import 'core-js/modules/es.typed-array.set.js';
|
|
24
|
+
import 'core-js/modules/es.typed-array.slice.js';
|
|
25
|
+
import 'core-js/modules/es.typed-array.some.js';
|
|
26
|
+
import 'core-js/modules/es.typed-array.sort.js';
|
|
27
|
+
import 'core-js/modules/es.typed-array.subarray.js';
|
|
28
|
+
import 'core-js/modules/es.typed-array.to-locale-string.js';
|
|
29
|
+
import 'core-js/modules/es.typed-array.to-string.js';
|
|
30
|
+
import { MP4 } from './mp4.js';
|
|
31
|
+
import { concatUint8Array } from '../utils/index.js';
|
|
32
|
+
import { Logger } from './logger.js';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {Object} RemuxResult
|
|
36
|
+
* @property {Uint8Array} [videoInitSegment]
|
|
37
|
+
* @property {Uint8Array} [audioInitSegment]
|
|
38
|
+
* @property {Uint8Array} [videoSegment]
|
|
39
|
+
* @property {Uint8Array} [audioSegment]
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
var FMP4Remuxer = /*#__PURE__*/function () {
|
|
43
|
+
/**
|
|
44
|
+
* @param {import('../model').VideoTrack} videoTrack
|
|
45
|
+
* @param {import('../model').AudioTrack} audioTrack
|
|
46
|
+
*/
|
|
47
|
+
function FMP4Remuxer(videoTrack, audioTrack, options) {
|
|
48
|
+
_classCallCheck(this, FMP4Remuxer);
|
|
49
|
+
|
|
50
|
+
this.videoTrack = videoTrack;
|
|
51
|
+
this.audioTrack = audioTrack;
|
|
52
|
+
this.log = new Logger('FMP4Remuxer', options && options.openLog ? !options.openLog : true);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @param {boolean} [createInit=false]
|
|
56
|
+
* @returns {RemuxResult}
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
_createClass(FMP4Remuxer, [{
|
|
61
|
+
key: "remux",
|
|
62
|
+
value: function remux() {
|
|
63
|
+
var createInit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
64
|
+
var videoTrack = this.videoTrack;
|
|
65
|
+
var audioTrack = this.audioTrack;
|
|
66
|
+
var hasVideo = videoTrack.exist();
|
|
67
|
+
var hasAudio = audioTrack.exist();
|
|
68
|
+
videoTrack.duration = videoTrack.duration || 0xffffffff;
|
|
69
|
+
audioTrack.duration = audioTrack.duration || 0xffffffff;
|
|
70
|
+
var videoInitSegment;
|
|
71
|
+
var audioInitSegment;
|
|
72
|
+
var initSegment;
|
|
73
|
+
var tracks = [];
|
|
74
|
+
|
|
75
|
+
if (createInit) {
|
|
76
|
+
if (hasVideo) videoInitSegment = MP4.initSegment([this.videoTrack]);
|
|
77
|
+
if (hasAudio) audioInitSegment = MP4.initSegment([this.audioTrack]);
|
|
78
|
+
|
|
79
|
+
if (hasVideo) {
|
|
80
|
+
tracks.push(this.videoTrack);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (hasAudio) {
|
|
84
|
+
tracks.push(this.audioTrack);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
initSegment = MP4.initSegment(tracks);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
var videoSegment;
|
|
91
|
+
var audioSegment;
|
|
92
|
+
if (hasVideo && videoTrack.hasSample()) videoSegment = this._remuxVideo();
|
|
93
|
+
this.log.debug('[remuxVideo],len,', videoSegment ? videoSegment.byteLength : 0);
|
|
94
|
+
if (hasAudio && audioTrack.hasSample()) audioSegment = this._remuxAudio();
|
|
95
|
+
this.log.debug('[remuxAudio],len,', audioSegment ? audioSegment.byteLength : 0);
|
|
96
|
+
videoTrack.samples = [];
|
|
97
|
+
audioTrack.samples = [];
|
|
98
|
+
return {
|
|
99
|
+
initSegment: initSegment,
|
|
100
|
+
videoInitSegment: videoInitSegment,
|
|
101
|
+
audioInitSegment: audioInitSegment,
|
|
102
|
+
videoSegment: videoSegment,
|
|
103
|
+
audioSegment: audioSegment
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}, {
|
|
107
|
+
key: "_remuxVideo",
|
|
108
|
+
value: function _remuxVideo() {
|
|
109
|
+
var track = this.videoTrack;
|
|
110
|
+
var samples = track.samples;
|
|
111
|
+
var mdatSize = 0;
|
|
112
|
+
samples.forEach(function (s) {
|
|
113
|
+
mdatSize += s.units.reduce(function (t, c) {
|
|
114
|
+
return t + c.byteLength;
|
|
115
|
+
}, 0);
|
|
116
|
+
mdatSize += s.units.length * 4;
|
|
117
|
+
});
|
|
118
|
+
var mdatData = new Uint8Array(mdatSize);
|
|
119
|
+
var mdatView = new DataView(mdatData.buffer);
|
|
120
|
+
|
|
121
|
+
var _loop = function _loop(i, l, _offset, _sample) {
|
|
122
|
+
_sample = samples[i];
|
|
123
|
+
var sampleSize = 0;
|
|
124
|
+
|
|
125
|
+
_sample.units.forEach(function (u) {
|
|
126
|
+
mdatView.setUint32(_offset, u.byteLength);
|
|
127
|
+
_offset += 4;
|
|
128
|
+
mdatData.set(u, _offset);
|
|
129
|
+
_offset += u.byteLength;
|
|
130
|
+
sampleSize += 4 + u.byteLength;
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
_sample.size = sampleSize;
|
|
134
|
+
offset = _offset;
|
|
135
|
+
sample = _sample;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
|
|
139
|
+
_loop(i, l, offset, sample);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
var moof = MP4.moof(this.videoTrack.sequenceNumber++, [track]);
|
|
143
|
+
var mdat = MP4.mdat(mdatData);
|
|
144
|
+
return concatUint8Array(moof, mdat);
|
|
145
|
+
}
|
|
146
|
+
}, {
|
|
147
|
+
key: "_remuxAudio",
|
|
148
|
+
value: function _remuxAudio() {
|
|
149
|
+
var track = this.audioTrack;
|
|
150
|
+
var moof = MP4.moof(this.audioTrack.sequenceNumber++, [track]);
|
|
151
|
+
var mdatData = new Uint8Array(track.samples.reduce(function (t, c) {
|
|
152
|
+
return t + c.size;
|
|
153
|
+
}, 0));
|
|
154
|
+
track.samples.reduce(function (offset, s) {
|
|
155
|
+
mdatData.set(s.data, offset);
|
|
156
|
+
return offset + s.size;
|
|
157
|
+
}, 0);
|
|
158
|
+
var mdat = MP4.mdat(mdatData);
|
|
159
|
+
return concatUint8Array(moof, mdat);
|
|
160
|
+
}
|
|
161
|
+
}, {
|
|
162
|
+
key: "reset",
|
|
163
|
+
value: function reset() {
|
|
164
|
+
this.videoTrack.reset();
|
|
165
|
+
this.audioTrack.reset();
|
|
166
|
+
}
|
|
167
|
+
}]);
|
|
168
|
+
|
|
169
|
+
return FMP4Remuxer;
|
|
170
|
+
}();
|
|
171
|
+
|
|
172
|
+
export { FMP4Remuxer };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class Logger {
|
|
2
|
+
static disabled: boolean;
|
|
3
|
+
static enable(): void;
|
|
4
|
+
static disable(): void;
|
|
5
|
+
constructor(name: any, enable: any);
|
|
6
|
+
name: any;
|
|
7
|
+
_prefix: string;
|
|
8
|
+
debug(...args: any[]): void;
|
|
9
|
+
log(...args: any[]): void;
|
|
10
|
+
warn(...args: any[]): void;
|
|
11
|
+
error(...args: any[]): void;
|
|
12
|
+
table(...args: any[]): void;
|
|
13
|
+
}
|