@remotion/media-parser 4.0.237 → 4.0.240
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/aac-codecprivate.d.ts +2 -9
- package/dist/aac-codecprivate.js +69 -34
- package/dist/add-avc-profile-to-track.js +4 -23
- package/dist/boxes/avc/codec-private.d.ts +2 -0
- package/dist/boxes/avc/codec-private.js +28 -0
- package/dist/boxes/avc/codec-string.d.ts +2 -0
- package/dist/boxes/avc/codec-string.js +7 -0
- package/dist/boxes/avc/color.d.ts +6 -0
- package/dist/boxes/avc/color.js +39 -0
- package/dist/boxes/avc/interpret-sps.d.ts +11 -0
- package/dist/boxes/avc/interpret-sps.js +44 -0
- package/dist/boxes/avc/key.d.ts +2 -0
- package/dist/boxes/avc/key.js +11 -0
- package/dist/boxes/avc/parse-avc.d.ts +36 -3
- package/dist/boxes/avc/parse-avc.js +161 -4
- package/dist/boxes/avc/sps-and-pps.d.ts +3 -0
- package/dist/boxes/avc/sps-and-pps.js +12 -0
- package/dist/boxes/iso-base-media/get-video-codec-from-iso-track.d.ts +2 -0
- package/dist/boxes/iso-base-media/get-video-codec-from-iso-track.js +55 -0
- package/dist/boxes/iso-base-media/make-track.js +2 -1
- package/dist/boxes/iso-base-media/mdat/mdat.js +8 -14
- package/dist/boxes/iso-base-media/process-box.js +1 -1
- package/dist/boxes/riff/parse-box.js +2 -2
- package/dist/boxes/riff/parse-movi.js +12 -14
- package/dist/boxes/transport-stream/adts-header.d.ts +7 -0
- package/dist/boxes/transport-stream/adts-header.js +56 -0
- package/dist/boxes/transport-stream/boxes.d.ts +41 -0
- package/dist/boxes/transport-stream/boxes.js +2 -0
- package/dist/boxes/transport-stream/discard-rest-of-packet.d.ts +3 -0
- package/dist/boxes/transport-stream/discard-rest-of-packet.js +13 -0
- package/dist/boxes/transport-stream/find-separator.d.ts +2 -0
- package/dist/boxes/transport-stream/find-separator.js +30 -0
- package/dist/boxes/transport-stream/get-tracks.d.ts +5 -0
- package/dist/boxes/transport-stream/get-tracks.js +33 -0
- package/dist/boxes/transport-stream/handle-aac-packet.d.ts +7 -0
- package/dist/boxes/transport-stream/handle-aac-packet.js +50 -0
- package/dist/boxes/transport-stream/handle-avc-packet.d.ts +8 -0
- package/dist/boxes/transport-stream/handle-avc-packet.js +60 -0
- package/dist/boxes/transport-stream/next-pes-header-store.d.ts +6 -0
- package/dist/boxes/transport-stream/next-pes-header-store.js +18 -0
- package/dist/boxes/transport-stream/parse-packet.d.ts +13 -0
- package/dist/boxes/transport-stream/parse-packet.js +80 -0
- package/dist/boxes/transport-stream/parse-pat.d.ts +8 -0
- package/dist/boxes/transport-stream/parse-pat.js +49 -0
- package/dist/boxes/transport-stream/parse-pes.d.ts +8 -0
- package/dist/boxes/transport-stream/parse-pes.js +76 -0
- package/dist/boxes/transport-stream/parse-pmt.d.ts +11 -0
- package/dist/boxes/transport-stream/parse-pmt.js +64 -0
- package/dist/boxes/transport-stream/parse-stream-packet.d.ts +15 -0
- package/dist/boxes/transport-stream/parse-stream-packet.js +107 -0
- package/dist/boxes/transport-stream/parse-transport-stream.d.ts +14 -0
- package/dist/boxes/transport-stream/parse-transport-stream.js +72 -0
- package/dist/boxes/transport-stream/process-stream-buffers.d.ts +19 -0
- package/dist/boxes/transport-stream/process-stream-buffers.js +42 -0
- package/dist/boxes/transport-stream/traversal.d.ts +6 -0
- package/dist/boxes/transport-stream/traversal.js +30 -0
- package/dist/boxes/webm/ebml.d.ts +1 -1
- package/dist/boxes/webm/parse-ebml.js +1 -1
- package/dist/buffer-iterator.d.ts +2 -0
- package/dist/buffer-iterator.js +25 -0
- package/dist/convert-audio-or-video-sample.d.ts +2 -0
- package/dist/convert-audio-or-video-sample.js +17 -0
- package/dist/create/iso-base-media/create-iso-base-media.js +38 -19
- package/dist/create/iso-base-media/trak/mdia/minf/create-stbl.js +7 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stts.js +3 -0
- package/dist/create/media-fn.d.ts +0 -1
- package/dist/create/progress-tracker.d.ts +2 -0
- package/dist/create/progress-tracker.js +32 -8
- package/dist/emit-available-info.js +13 -2
- package/dist/esm/index.mjs +1325 -247
- package/dist/get-container.d.ts +1 -1
- package/dist/get-container.js +3 -0
- package/dist/get-duration.js +4 -1
- package/dist/get-fps.js +8 -2
- package/dist/get-location.d.ts +13 -0
- package/dist/get-location.js +40 -0
- package/dist/get-tracks.d.ts +4 -3
- package/dist/get-tracks.js +9 -2
- package/dist/get-video-codec.d.ts +1 -2
- package/dist/get-video-codec.js +9 -148
- package/dist/has-all-info.js +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/metadata/get-metadata.js +3 -0
- package/dist/options.d.ts +11 -3
- package/dist/parse-media.js +3 -3
- package/dist/parse-result.d.ts +7 -2
- package/dist/parse-video.js +15 -0
- package/dist/register-track.d.ts +5 -5
- package/dist/register-track.js +16 -10
- package/dist/state/can-skip-tracks.js +1 -0
- package/dist/state/has-tracks-section.d.ts +3 -0
- package/dist/state/has-tracks-section.js +5 -0
- package/dist/state/parser-state.d.ts +2 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/webcodec-sample-types.d.ts +9 -2
- package/package.json +3 -3
- package/dist/add-new-matroska-tracks.d.ts +0 -13
- package/dist/add-new-matroska-tracks.js +0 -29
- package/dist/boxes/iso-base-media/meta/keys.d.ts +0 -10
- package/dist/boxes/iso-base-media/meta/keys.js +0 -17
- package/dist/boxes/iso-base-media/meta/list.d.ts +0 -12
- package/dist/boxes/iso-base-media/meta/list.js +0 -33
- package/dist/boxes/riff/strf.d.ts +0 -7
- package/dist/boxes/riff/strf.js +0 -67
- package/dist/create/mp3/create-mp3.d.ts +0 -2
- package/dist/create/mp3/create-mp3.js +0 -49
- package/dist/get-metadata.d.ts +0 -7
- package/dist/get-metadata.js +0 -63
- package/dist/parser-state.d.ts +0 -33
- package/dist/parser-state.js +0 -162
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* bytes 17,144: 00010 001 | 1 0010 000
|
|
3
|
-
^^^^^ ^^^ ^ ^^^^ ^
|
|
4
|
-
| | | | padding
|
|
5
|
-
| | |
|
|
6
|
-
| | +-- channelConfiguration (2)
|
|
7
|
-
| +-- samplingFrequencyIndex (3)
|
|
8
|
-
+-- audioConfigType (2)
|
|
9
|
-
*/
|
|
1
|
+
export declare const getSampleRateFromSampleFrequencyIndex: (samplingFrequencyIndex: number) => 96000 | 88200 | 64000 | 48000 | 44100 | 32000 | 24000 | 22050 | 16000 | 12000 | 11025 | 8000 | 7350;
|
|
10
2
|
export declare const createAacCodecPrivate: ({ audioObjectType, sampleRate, channelConfiguration, }: {
|
|
11
3
|
audioObjectType: number;
|
|
12
4
|
sampleRate: number;
|
|
@@ -17,3 +9,4 @@ export declare const parseAacCodecPrivate: (bytes: Uint8Array) => {
|
|
|
17
9
|
sampleRate: number;
|
|
18
10
|
channelConfiguration: number;
|
|
19
11
|
};
|
|
12
|
+
export declare const mapAudioObjectTypeToCodecString: (audioObjectType: number) => "mp4a.40.2" | "mp4a.40.5" | "mp4a.40.29" | "mp4a.40.1" | "mp4a.40.3" | "mp4a.40.4" | "mp4a.40.17" | "mp4a.40.23";
|
package/dist/aac-codecprivate.js
CHANGED
|
@@ -1,4 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapAudioObjectTypeToCodecString = exports.parseAacCodecPrivate = exports.createAacCodecPrivate = exports.getSampleRateFromSampleFrequencyIndex = void 0;
|
|
4
|
+
const getSampleRateFromSampleFrequencyIndex = (samplingFrequencyIndex) => {
|
|
5
|
+
switch (samplingFrequencyIndex) {
|
|
6
|
+
case 0:
|
|
7
|
+
return 96000;
|
|
8
|
+
case 1:
|
|
9
|
+
return 88200;
|
|
10
|
+
case 2:
|
|
11
|
+
return 64000;
|
|
12
|
+
case 3:
|
|
13
|
+
return 48000;
|
|
14
|
+
case 4:
|
|
15
|
+
return 44100;
|
|
16
|
+
case 5:
|
|
17
|
+
return 32000;
|
|
18
|
+
case 6:
|
|
19
|
+
return 24000;
|
|
20
|
+
case 7:
|
|
21
|
+
return 22050;
|
|
22
|
+
case 8:
|
|
23
|
+
return 16000;
|
|
24
|
+
case 9:
|
|
25
|
+
return 12000;
|
|
26
|
+
case 10:
|
|
27
|
+
return 11025;
|
|
28
|
+
case 11:
|
|
29
|
+
return 8000;
|
|
30
|
+
case 12:
|
|
31
|
+
return 7350;
|
|
32
|
+
default:
|
|
33
|
+
throw new Error(`Unexpected sampling frequency index ${samplingFrequencyIndex}`);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.getSampleRateFromSampleFrequencyIndex = getSampleRateFromSampleFrequencyIndex;
|
|
2
37
|
// codec private, for example [17, 144]
|
|
3
38
|
// audioObjectType = 2 = 'AAC LC'
|
|
4
39
|
// samplingFrequencyIndex = 3 = '48000 Hz'
|
|
@@ -12,8 +47,6 @@
|
|
|
12
47
|
| +-- samplingFrequencyIndex (3)
|
|
13
48
|
+-- audioConfigType (2)
|
|
14
49
|
*/
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.parseAacCodecPrivate = exports.createAacCodecPrivate = void 0;
|
|
17
50
|
// https://wiki.multimedia.cx/index.php/MPEG-4_Audio#Channel_Configurations
|
|
18
51
|
const getConfigForSampleRate = (sampleRate) => {
|
|
19
52
|
if (sampleRate === 96000) {
|
|
@@ -81,38 +114,7 @@ const parseAacCodecPrivate = (bytes) => {
|
|
|
81
114
|
const audioObjectType = parseInt(bits.slice(0, 5), 2);
|
|
82
115
|
const samplingFrequencyIndex = parseInt(bits.slice(5, 9), 2);
|
|
83
116
|
const channelConfiguration = parseInt(bits.slice(9, 13), 2);
|
|
84
|
-
const sampleRate = (()
|
|
85
|
-
switch (samplingFrequencyIndex) {
|
|
86
|
-
case 0:
|
|
87
|
-
return 96000;
|
|
88
|
-
case 1:
|
|
89
|
-
return 88200;
|
|
90
|
-
case 2:
|
|
91
|
-
return 64000;
|
|
92
|
-
case 3:
|
|
93
|
-
return 48000;
|
|
94
|
-
case 4:
|
|
95
|
-
return 44100;
|
|
96
|
-
case 5:
|
|
97
|
-
return 32000;
|
|
98
|
-
case 6:
|
|
99
|
-
return 24000;
|
|
100
|
-
case 7:
|
|
101
|
-
return 22050;
|
|
102
|
-
case 8:
|
|
103
|
-
return 16000;
|
|
104
|
-
case 9:
|
|
105
|
-
return 12000;
|
|
106
|
-
case 10:
|
|
107
|
-
return 11025;
|
|
108
|
-
case 11:
|
|
109
|
-
return 8000;
|
|
110
|
-
case 12:
|
|
111
|
-
return 7350;
|
|
112
|
-
default:
|
|
113
|
-
throw new Error(`Unexpected sampling frequency index ${samplingFrequencyIndex}`);
|
|
114
|
-
}
|
|
115
|
-
})();
|
|
117
|
+
const sampleRate = (0, exports.getSampleRateFromSampleFrequencyIndex)(samplingFrequencyIndex);
|
|
116
118
|
return {
|
|
117
119
|
audioObjectType,
|
|
118
120
|
sampleRate,
|
|
@@ -120,3 +122,36 @@ const parseAacCodecPrivate = (bytes) => {
|
|
|
120
122
|
};
|
|
121
123
|
};
|
|
122
124
|
exports.parseAacCodecPrivate = parseAacCodecPrivate;
|
|
125
|
+
const mapAudioObjectTypeToCodecString = (audioObjectType) => {
|
|
126
|
+
/**
|
|
127
|
+
* 1. 1 - mp4a.40.2: MPEG-4 AAC LC (Low Complexity)
|
|
128
|
+
2. 2 - mp4a.40.5: MPEG-4 AAC HE (High Efficiency)
|
|
129
|
+
3. 3 - mp4a.40.29: MPEG-4 AAC HEv2 (High Efficiency v2)
|
|
130
|
+
4. 4 - mp4a.40.1: MPEG-4 AAC Main
|
|
131
|
+
5. 5 - mp4a.40.3: MPEG-4 AAC SSR (Scalable Sample Rate)
|
|
132
|
+
6. 6 - mp4a.40.4: MPEG-4 AAC LTP (Long Term Prediction)
|
|
133
|
+
7. 17 - mp4a.40.17: MPEG-4 AAC LD (Low Delay)
|
|
134
|
+
8. 23 - mp4a.40.23: MPEG-4 AAC ELD (Enhanced Low Delay)
|
|
135
|
+
*/
|
|
136
|
+
switch (audioObjectType) {
|
|
137
|
+
case 1:
|
|
138
|
+
return 'mp4a.40.2';
|
|
139
|
+
case 2:
|
|
140
|
+
return 'mp4a.40.5';
|
|
141
|
+
case 3:
|
|
142
|
+
return 'mp4a.40.29';
|
|
143
|
+
case 4:
|
|
144
|
+
return 'mp4a.40.1';
|
|
145
|
+
case 5:
|
|
146
|
+
return 'mp4a.40.3';
|
|
147
|
+
case 6:
|
|
148
|
+
return 'mp4a.40.4';
|
|
149
|
+
case 17:
|
|
150
|
+
return 'mp4a.40.17';
|
|
151
|
+
case 23:
|
|
152
|
+
return 'mp4a.40.23';
|
|
153
|
+
default:
|
|
154
|
+
throw new Error(`Unexpected audio object type ${audioObjectType}`);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
exports.mapAudioObjectTypeToCodecString = mapAudioObjectTypeToCodecString;
|
|
@@ -1,35 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addAvcProfileToTrack = void 0;
|
|
4
|
-
const
|
|
4
|
+
const codec_private_1 = require("./boxes/avc/codec-private");
|
|
5
|
+
const codec_string_1 = require("./boxes/avc/codec-string");
|
|
5
6
|
const addAvcProfileToTrack = (track, avc1Profile) => {
|
|
6
7
|
if (avc1Profile === null) {
|
|
7
8
|
return track;
|
|
8
9
|
}
|
|
9
10
|
return {
|
|
10
11
|
...track,
|
|
11
|
-
codec:
|
|
12
|
-
codecPrivate: (0,
|
|
13
|
-
new Uint8Array([
|
|
14
|
-
// https://gist.github.com/uupaa/8493378ec15f644a3d2b
|
|
15
|
-
1,
|
|
16
|
-
avc1Profile.sps.level,
|
|
17
|
-
avc1Profile.sps.compatibility,
|
|
18
|
-
avc1Profile.sps.profile,
|
|
19
|
-
0xff,
|
|
20
|
-
0xe1,
|
|
21
|
-
]),
|
|
22
|
-
// sequence parameter set length
|
|
23
|
-
(0, make_header_1.serializeUint16)(avc1Profile.sps.sps.length),
|
|
24
|
-
// sequence parameter set
|
|
25
|
-
avc1Profile.sps.sps,
|
|
26
|
-
// num of PPS
|
|
27
|
-
new Uint8Array([0x01]),
|
|
28
|
-
// picture parameter set length
|
|
29
|
-
(0, make_header_1.serializeUint16)(avc1Profile.pps.pps.length),
|
|
30
|
-
// PPS
|
|
31
|
-
avc1Profile.pps.pps,
|
|
32
|
-
]),
|
|
12
|
+
codec: (0, codec_string_1.getCodecStringFromSpsAndPps)(avc1Profile.sps),
|
|
13
|
+
codecPrivate: (0, codec_private_1.getAvccBoxContent)(avc1Profile),
|
|
33
14
|
};
|
|
34
15
|
};
|
|
35
16
|
exports.addAvcProfileToTrack = addAvcProfileToTrack;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAvccBoxContent = void 0;
|
|
4
|
+
const make_header_1 = require("../webm/make-header");
|
|
5
|
+
const getAvccBoxContent = (avc1Profile) => {
|
|
6
|
+
return (0, make_header_1.combineUint8Arrays)([
|
|
7
|
+
new Uint8Array([
|
|
8
|
+
// https://gist.github.com/uupaa/8493378ec15f644a3d2b
|
|
9
|
+
1, // version
|
|
10
|
+
avc1Profile.sps.spsData.level,
|
|
11
|
+
avc1Profile.sps.spsData.compatibility,
|
|
12
|
+
avc1Profile.sps.spsData.profile,
|
|
13
|
+
0xff,
|
|
14
|
+
0xe1,
|
|
15
|
+
]),
|
|
16
|
+
// sequence parameter set length
|
|
17
|
+
(0, make_header_1.serializeUint16)(avc1Profile.sps.sps.length),
|
|
18
|
+
// sequence parameter set
|
|
19
|
+
avc1Profile.sps.sps,
|
|
20
|
+
// num of PPS
|
|
21
|
+
new Uint8Array([0x01]),
|
|
22
|
+
// picture parameter set length
|
|
23
|
+
(0, make_header_1.serializeUint16)(avc1Profile.pps.pps.length),
|
|
24
|
+
// PPS
|
|
25
|
+
avc1Profile.pps.pps,
|
|
26
|
+
]);
|
|
27
|
+
};
|
|
28
|
+
exports.getAvccBoxContent = getAvccBoxContent;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCodecStringFromSpsAndPps = void 0;
|
|
4
|
+
const getCodecStringFromSpsAndPps = (sps) => {
|
|
5
|
+
return `avc1.${sps.spsData.profile.toString(16).padStart(2, '0')}${sps.spsData.compatibility.toString(16).padStart(2, '0')}${sps.spsData.level.toString(16).padStart(2, '0')}`;
|
|
6
|
+
};
|
|
7
|
+
exports.getCodecStringFromSpsAndPps = getCodecStringFromSpsAndPps;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type MatrixCoefficients = 'bt709' | 'bt470bg' | 'rgb' | 'smpte170m' | 'bt2020';
|
|
2
|
+
export declare const getMatrixCoefficientsFromIndex: (index: number) => MatrixCoefficients | null;
|
|
3
|
+
export type TransferCharacteristics = 'bt709' | 'smpte170m' | 'iec61966-2-1' | 'arib-std-b67';
|
|
4
|
+
export declare const getTransferCharacteristicsFromIndex: (index: number) => TransferCharacteristics | null;
|
|
5
|
+
export type Primaries = 'bt709' | 'smpte170m' | 'bt470bg' | 'bt2020' | null;
|
|
6
|
+
export declare const getPrimariesFromIndex: (index: number) => Primaries | null;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPrimariesFromIndex = exports.getTransferCharacteristicsFromIndex = exports.getMatrixCoefficientsFromIndex = void 0;
|
|
4
|
+
const getMatrixCoefficientsFromIndex = (index) => {
|
|
5
|
+
return index === 1
|
|
6
|
+
? 'bt709'
|
|
7
|
+
: index === 5
|
|
8
|
+
? 'bt470bg'
|
|
9
|
+
: index === 6
|
|
10
|
+
? 'smpte170m'
|
|
11
|
+
: index === 9
|
|
12
|
+
? 'bt2020'
|
|
13
|
+
: null;
|
|
14
|
+
};
|
|
15
|
+
exports.getMatrixCoefficientsFromIndex = getMatrixCoefficientsFromIndex;
|
|
16
|
+
const getTransferCharacteristicsFromIndex = (index) => {
|
|
17
|
+
return index === 1
|
|
18
|
+
? 'bt709'
|
|
19
|
+
: index === 6
|
|
20
|
+
? 'smpte170m'
|
|
21
|
+
: index === 13
|
|
22
|
+
? 'iec61966-2-1'
|
|
23
|
+
: index === 18
|
|
24
|
+
? 'arib-std-b67'
|
|
25
|
+
: null;
|
|
26
|
+
};
|
|
27
|
+
exports.getTransferCharacteristicsFromIndex = getTransferCharacteristicsFromIndex;
|
|
28
|
+
const getPrimariesFromIndex = (index) => {
|
|
29
|
+
return index === 1
|
|
30
|
+
? 'bt709'
|
|
31
|
+
: index === 5
|
|
32
|
+
? 'bt470bg'
|
|
33
|
+
: index === 6
|
|
34
|
+
? 'smpte170m'
|
|
35
|
+
: index === 9
|
|
36
|
+
? 'bt2020'
|
|
37
|
+
: null;
|
|
38
|
+
};
|
|
39
|
+
exports.getPrimariesFromIndex = getPrimariesFromIndex;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { VideoTrackColorParams } from '../../get-tracks';
|
|
2
|
+
import type { SpsInfo } from './parse-avc';
|
|
3
|
+
export declare const getDimensionsFromSps: (sps: SpsInfo) => {
|
|
4
|
+
height: number;
|
|
5
|
+
width: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const getSampleAspectRatioFromSps: (sps: SpsInfo) => {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
export declare const getVideoColorFromSps: (sps: SpsInfo) => VideoTrackColorParams;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVideoColorFromSps = exports.getSampleAspectRatioFromSps = exports.getDimensionsFromSps = void 0;
|
|
4
|
+
const color_1 = require("./color");
|
|
5
|
+
const getDimensionsFromSps = (sps) => {
|
|
6
|
+
const height = sps.pic_height_in_map_units_minus1;
|
|
7
|
+
const width = sps.pic_width_in_mbs_minus1;
|
|
8
|
+
return {
|
|
9
|
+
height: (height + 1) * 16,
|
|
10
|
+
width: (width + 1) * 16,
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
exports.getDimensionsFromSps = getDimensionsFromSps;
|
|
14
|
+
const getSampleAspectRatioFromSps = (sps) => {
|
|
15
|
+
var _a;
|
|
16
|
+
if (((_a = sps.vui_parameters) === null || _a === void 0 ? void 0 : _a.sar_height) && sps.vui_parameters.sar_width) {
|
|
17
|
+
return {
|
|
18
|
+
width: sps.vui_parameters.sar_width,
|
|
19
|
+
height: sps.vui_parameters.sar_height,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
width: 1,
|
|
24
|
+
height: 1,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
exports.getSampleAspectRatioFromSps = getSampleAspectRatioFromSps;
|
|
28
|
+
const getVideoColorFromSps = (sps) => {
|
|
29
|
+
var _a, _b, _c, _d, _e;
|
|
30
|
+
const matrixCoefficients = (_a = sps.vui_parameters) === null || _a === void 0 ? void 0 : _a.matrix_coefficients;
|
|
31
|
+
const transferCharacteristics = (_b = sps.vui_parameters) === null || _b === void 0 ? void 0 : _b.transfer_characteristics;
|
|
32
|
+
const colorPrimaries = (_c = sps.vui_parameters) === null || _c === void 0 ? void 0 : _c.colour_primaries;
|
|
33
|
+
return {
|
|
34
|
+
matrixCoefficients: matrixCoefficients
|
|
35
|
+
? (0, color_1.getMatrixCoefficientsFromIndex)(matrixCoefficients)
|
|
36
|
+
: null,
|
|
37
|
+
transferCharacteristics: transferCharacteristics
|
|
38
|
+
? (0, color_1.getTransferCharacteristicsFromIndex)(transferCharacteristics)
|
|
39
|
+
: null,
|
|
40
|
+
primaries: colorPrimaries ? (0, color_1.getPrimariesFromIndex)(colorPrimaries) : null,
|
|
41
|
+
fullRange: (_e = (_d = sps.vui_parameters) === null || _d === void 0 ? void 0 : _d.video_full_range_flag) !== null && _e !== void 0 ? _e : null,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
exports.getVideoColorFromSps = getVideoColorFromSps;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getKeyFrameOrDeltaFromAvcInfo = void 0;
|
|
4
|
+
const getKeyFrameOrDeltaFromAvcInfo = (infos) => {
|
|
5
|
+
const keyOrDelta = infos.find((i) => i.type === 'keyframe' || i.type === 'delta-frame');
|
|
6
|
+
if (!keyOrDelta) {
|
|
7
|
+
throw new Error('expected avc to contain info about key or delta');
|
|
8
|
+
}
|
|
9
|
+
return keyOrDelta.type === 'keyframe' ? 'key' : 'delta';
|
|
10
|
+
};
|
|
11
|
+
exports.getKeyFrameOrDeltaFromAvcInfo = getKeyFrameOrDeltaFromAvcInfo;
|
|
@@ -1,7 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
type VuiParameters = {
|
|
2
|
+
sar_width: number | null;
|
|
3
|
+
sar_height: number | null;
|
|
4
|
+
overscan_appropriate_flag: number | null;
|
|
5
|
+
video_format: number | null;
|
|
6
|
+
video_full_range_flag: boolean | null;
|
|
7
|
+
colour_primaries: number | null;
|
|
8
|
+
transfer_characteristics: number | null;
|
|
9
|
+
matrix_coefficients: number | null;
|
|
10
|
+
chroma_sample_loc_type_top_field: number | null;
|
|
11
|
+
chroma_sample_loc_type_bottom_field: number | null;
|
|
12
|
+
};
|
|
13
|
+
export type SpsInfo = {
|
|
2
14
|
profile: number;
|
|
3
|
-
level: number;
|
|
4
15
|
compatibility: number;
|
|
16
|
+
level: number;
|
|
17
|
+
seq_parameter_set_id: number;
|
|
18
|
+
separate_colour_plane_flag: number | null;
|
|
19
|
+
bit_depth_luma_minus8: number | null;
|
|
20
|
+
bit_depth_chroma_minus8: number | null;
|
|
21
|
+
qpprime_y_zero_transform_bypass_flag: number | null;
|
|
22
|
+
log2_max_frame_num_minus4: number | null;
|
|
23
|
+
log2_max_pic_order_cnt_lsb_minus4: number | null;
|
|
24
|
+
max_num_ref_frames: number | null;
|
|
25
|
+
gaps_in_frame_num_value_allowed_flag: number | null;
|
|
26
|
+
pic_width_in_mbs_minus1: number;
|
|
27
|
+
pic_height_in_map_units_minus1: number;
|
|
28
|
+
mb_adaptive_frame_field_flag: number | null;
|
|
29
|
+
direct_8x8_inference_flag: number | null;
|
|
30
|
+
frame_crop_left_offset: number | null;
|
|
31
|
+
frame_crop_right_offset: number | null;
|
|
32
|
+
frame_crop_top_offset: number | null;
|
|
33
|
+
frame_crop_bottom_offset: number | null;
|
|
34
|
+
vui_parameters: VuiParameters | null;
|
|
35
|
+
};
|
|
36
|
+
export type AvcProfileInfo = {
|
|
37
|
+
spsData: SpsInfo;
|
|
5
38
|
sps: Uint8Array;
|
|
6
39
|
type: 'avc-profile';
|
|
7
40
|
};
|
|
@@ -9,7 +42,7 @@ export type AvcPPs = {
|
|
|
9
42
|
type: 'avc-pps';
|
|
10
43
|
pps: Uint8Array;
|
|
11
44
|
};
|
|
12
|
-
type AvcInfo = AvcProfileInfo | AvcPPs | {
|
|
45
|
+
export type AvcInfo = AvcProfileInfo | AvcPPs | {
|
|
13
46
|
type: 'keyframe';
|
|
14
47
|
} | {
|
|
15
48
|
type: 'delta-frame';
|
|
@@ -1,15 +1,174 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// https://www.itu.int/rec/T-REC-H.264-202408-I/en
|
|
3
|
+
// Page 455
|
|
2
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
5
|
exports.parseAvc = void 0;
|
|
4
6
|
const buffer_iterator_1 = require("../../buffer-iterator");
|
|
7
|
+
const Extended_SAR = 255;
|
|
8
|
+
const readVuiParameters = (iterator) => {
|
|
9
|
+
let sar_width = null;
|
|
10
|
+
let sar_height = null;
|
|
11
|
+
let overscan_appropriate_flag = null;
|
|
12
|
+
let video_format = null;
|
|
13
|
+
let video_full_range_flag = null;
|
|
14
|
+
let colour_primaries = null;
|
|
15
|
+
let transfer_characteristics = null;
|
|
16
|
+
let matrix_coefficients = null;
|
|
17
|
+
let chroma_sample_loc_type_top_field = null;
|
|
18
|
+
let chroma_sample_loc_type_bottom_field = null;
|
|
19
|
+
const aspect_ratio_info_present_flag = iterator.getBits(1);
|
|
20
|
+
if (aspect_ratio_info_present_flag) {
|
|
21
|
+
const aspect_ratio_idc = iterator.getBits(8);
|
|
22
|
+
if (aspect_ratio_idc === Extended_SAR) {
|
|
23
|
+
sar_width = iterator.getBits(16);
|
|
24
|
+
sar_height = iterator.getBits(16);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const overscan_info_present_flag = iterator.getBits(1);
|
|
28
|
+
if (overscan_info_present_flag) {
|
|
29
|
+
overscan_appropriate_flag = iterator.getBits(1);
|
|
30
|
+
}
|
|
31
|
+
const video_signal_type_present_flag = iterator.getBits(1);
|
|
32
|
+
if (video_signal_type_present_flag) {
|
|
33
|
+
video_format = iterator.getBits(3);
|
|
34
|
+
video_full_range_flag = Boolean(iterator.getBits(1));
|
|
35
|
+
const colour_description_present_flag = iterator.getBits(1);
|
|
36
|
+
if (colour_description_present_flag) {
|
|
37
|
+
colour_primaries = iterator.getBits(8);
|
|
38
|
+
transfer_characteristics = iterator.getBits(8);
|
|
39
|
+
matrix_coefficients = iterator.getBits(8);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const chroma_loc_info_present_flag = iterator.getBits(1);
|
|
43
|
+
if (chroma_loc_info_present_flag) {
|
|
44
|
+
chroma_sample_loc_type_top_field = iterator.readExpGolomb();
|
|
45
|
+
chroma_sample_loc_type_bottom_field = iterator.readExpGolomb();
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
sar_width,
|
|
49
|
+
sar_height,
|
|
50
|
+
overscan_appropriate_flag,
|
|
51
|
+
chroma_sample_loc_type_bottom_field,
|
|
52
|
+
chroma_sample_loc_type_top_field,
|
|
53
|
+
colour_primaries,
|
|
54
|
+
matrix_coefficients,
|
|
55
|
+
transfer_characteristics,
|
|
56
|
+
video_format,
|
|
57
|
+
video_full_range_flag,
|
|
58
|
+
};
|
|
59
|
+
};
|
|
5
60
|
const readSps = (iterator) => {
|
|
6
61
|
const profile = iterator.getUint8();
|
|
7
62
|
const compatibility = iterator.getUint8();
|
|
8
63
|
const level = iterator.getUint8();
|
|
64
|
+
iterator.startReadingBits();
|
|
65
|
+
const seq_parameter_set_id = iterator.readExpGolomb();
|
|
66
|
+
let separate_colour_plane_flag = null;
|
|
67
|
+
let bit_depth_luma_minus8 = null;
|
|
68
|
+
let bit_depth_chroma_minus8 = null;
|
|
69
|
+
let qpprime_y_zero_transform_bypass_flag = null;
|
|
70
|
+
let log2_max_frame_num_minus4 = null;
|
|
71
|
+
let log2_max_pic_order_cnt_lsb_minus4 = null;
|
|
72
|
+
let max_num_ref_frames = null;
|
|
73
|
+
let gaps_in_frame_num_value_allowed_flag = null;
|
|
74
|
+
let mb_adaptive_frame_field_flag = null;
|
|
75
|
+
let direct_8x8_inference_flag = null;
|
|
76
|
+
let frame_crop_left_offset = null;
|
|
77
|
+
let frame_crop_right_offset = null;
|
|
78
|
+
let frame_crop_top_offset = null;
|
|
79
|
+
let frame_crop_bottom_offset = null;
|
|
80
|
+
let vui_parameters = null;
|
|
81
|
+
// Page 71
|
|
82
|
+
if (!(profile === 100 ||
|
|
83
|
+
profile === 110 ||
|
|
84
|
+
profile === 122 ||
|
|
85
|
+
profile === 244 ||
|
|
86
|
+
profile === 44 ||
|
|
87
|
+
profile === 83 ||
|
|
88
|
+
profile === 86 ||
|
|
89
|
+
profile === 118 ||
|
|
90
|
+
profile === 128 ||
|
|
91
|
+
profile === 138 ||
|
|
92
|
+
profile === 139 ||
|
|
93
|
+
profile === 134 ||
|
|
94
|
+
profile === 135)) {
|
|
95
|
+
throw new Error('Invalid profile');
|
|
96
|
+
}
|
|
97
|
+
const chromaFormat = iterator.readExpGolomb();
|
|
98
|
+
if (chromaFormat === 3) {
|
|
99
|
+
separate_colour_plane_flag = iterator.getBits(1);
|
|
100
|
+
}
|
|
101
|
+
bit_depth_luma_minus8 = iterator.readExpGolomb();
|
|
102
|
+
bit_depth_chroma_minus8 = iterator.readExpGolomb();
|
|
103
|
+
qpprime_y_zero_transform_bypass_flag = iterator.getBits(1);
|
|
104
|
+
const seq_scaling_matrix_present_flag = iterator.getBits(1);
|
|
105
|
+
const seq_scaling_list_present_flag = [];
|
|
106
|
+
if (seq_scaling_matrix_present_flag) {
|
|
107
|
+
for (let i = 0; i < (chromaFormat !== 3 ? 8 : 12); i++) {
|
|
108
|
+
seq_scaling_list_present_flag[i] = iterator.getBits(1);
|
|
109
|
+
if (seq_scaling_list_present_flag[i]) {
|
|
110
|
+
if (i < 6) {
|
|
111
|
+
// scaling_list not implemented
|
|
112
|
+
throw new Error('Not implemented');
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// scaling_list not implemented
|
|
116
|
+
throw new Error('Not implemented');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
log2_max_frame_num_minus4 = iterator.readExpGolomb();
|
|
122
|
+
const pic_order_cnt_type = iterator.readExpGolomb();
|
|
123
|
+
if (pic_order_cnt_type === 0) {
|
|
124
|
+
log2_max_pic_order_cnt_lsb_minus4 = iterator.readExpGolomb();
|
|
125
|
+
}
|
|
126
|
+
else if (pic_order_cnt_type === 1) {
|
|
127
|
+
throw new Error('pic_order_cnt_type = 1 not implemented');
|
|
128
|
+
}
|
|
129
|
+
max_num_ref_frames = iterator.readExpGolomb();
|
|
130
|
+
gaps_in_frame_num_value_allowed_flag = iterator.getBits(1);
|
|
131
|
+
const pic_width_in_mbs_minus1 = iterator.readExpGolomb();
|
|
132
|
+
const pic_height_in_map_units_minus1 = iterator.readExpGolomb();
|
|
133
|
+
const frame_mbs_only_flag = iterator.getBits(1);
|
|
134
|
+
if (!frame_mbs_only_flag) {
|
|
135
|
+
mb_adaptive_frame_field_flag = iterator.getBits(1);
|
|
136
|
+
}
|
|
137
|
+
direct_8x8_inference_flag = iterator.getBits(1);
|
|
138
|
+
const frame_cropping_flag = iterator.getBits(1);
|
|
139
|
+
if (frame_cropping_flag) {
|
|
140
|
+
frame_crop_left_offset = iterator.readExpGolomb();
|
|
141
|
+
frame_crop_right_offset = iterator.readExpGolomb();
|
|
142
|
+
frame_crop_top_offset = iterator.readExpGolomb();
|
|
143
|
+
frame_crop_bottom_offset = iterator.readExpGolomb();
|
|
144
|
+
}
|
|
145
|
+
const vui_parameters_present_flag = iterator.getBits(1);
|
|
146
|
+
if (vui_parameters_present_flag) {
|
|
147
|
+
vui_parameters = readVuiParameters(iterator);
|
|
148
|
+
}
|
|
149
|
+
iterator.stopReadingBits();
|
|
9
150
|
return {
|
|
10
151
|
profile,
|
|
11
152
|
compatibility,
|
|
12
153
|
level,
|
|
154
|
+
bit_depth_chroma_minus8,
|
|
155
|
+
bit_depth_luma_minus8,
|
|
156
|
+
gaps_in_frame_num_value_allowed_flag,
|
|
157
|
+
log2_max_frame_num_minus4,
|
|
158
|
+
log2_max_pic_order_cnt_lsb_minus4,
|
|
159
|
+
max_num_ref_frames,
|
|
160
|
+
pic_height_in_map_units_minus1,
|
|
161
|
+
pic_width_in_mbs_minus1,
|
|
162
|
+
qpprime_y_zero_transform_bypass_flag,
|
|
163
|
+
separate_colour_plane_flag,
|
|
164
|
+
seq_parameter_set_id,
|
|
165
|
+
direct_8x8_inference_flag,
|
|
166
|
+
frame_crop_bottom_offset,
|
|
167
|
+
frame_crop_left_offset,
|
|
168
|
+
frame_crop_right_offset,
|
|
169
|
+
frame_crop_top_offset,
|
|
170
|
+
mb_adaptive_frame_field_flag,
|
|
171
|
+
vui_parameters,
|
|
13
172
|
};
|
|
14
173
|
};
|
|
15
174
|
const findEnd = (buffer) => {
|
|
@@ -37,11 +196,9 @@ const inspect = (buffer) => {
|
|
|
37
196
|
if (type === 7) {
|
|
38
197
|
const end = findEnd(buffer);
|
|
39
198
|
const data = readSps(iterator);
|
|
40
|
-
const sps = buffer.slice(
|
|
199
|
+
const sps = buffer.slice(0, end === null ? Infinity : end);
|
|
41
200
|
return {
|
|
42
|
-
|
|
43
|
-
profile: data.profile,
|
|
44
|
-
compatibility: data.compatibility,
|
|
201
|
+
spsData: data,
|
|
45
202
|
sps,
|
|
46
203
|
type: 'avc-profile',
|
|
47
204
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSpsAndPps = void 0;
|
|
4
|
+
const getSpsAndPps = (infos) => {
|
|
5
|
+
const avcProfile = infos.find((i) => i.type === 'avc-profile');
|
|
6
|
+
const ppsProfile = infos.find((i) => i.type === 'avc-pps');
|
|
7
|
+
if (!avcProfile || !ppsProfile) {
|
|
8
|
+
throw new Error('Expected avcProfile and ppsProfile');
|
|
9
|
+
}
|
|
10
|
+
return { pps: ppsProfile, sps: avcProfile };
|
|
11
|
+
};
|
|
12
|
+
exports.getSpsAndPps = getSpsAndPps;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVideoCodecFromIsoTrak = void 0;
|
|
4
|
+
const traversal_1 = require("./traversal");
|
|
5
|
+
const getVideoCodecFromIsoTrak = (trakBox) => {
|
|
6
|
+
const stsdBox = (0, traversal_1.getStsdBox)(trakBox);
|
|
7
|
+
if (stsdBox && stsdBox.type === 'stsd-box') {
|
|
8
|
+
const videoSample = stsdBox.samples.find((s) => s.type === 'video');
|
|
9
|
+
if (videoSample && videoSample.type === 'video') {
|
|
10
|
+
if (videoSample.format === 'hvc1') {
|
|
11
|
+
return 'h265';
|
|
12
|
+
}
|
|
13
|
+
if (videoSample.format === 'avc1') {
|
|
14
|
+
return 'h264';
|
|
15
|
+
}
|
|
16
|
+
if (videoSample.format === 'av01') {
|
|
17
|
+
return 'av1';
|
|
18
|
+
}
|
|
19
|
+
// ap4h: ProRes 4444
|
|
20
|
+
if (videoSample.format === 'ap4h') {
|
|
21
|
+
return 'prores';
|
|
22
|
+
}
|
|
23
|
+
// ap4x: ap4x: ProRes 4444 XQ
|
|
24
|
+
if (videoSample.format === 'ap4x') {
|
|
25
|
+
return 'prores';
|
|
26
|
+
}
|
|
27
|
+
// apch: ProRes 422 High Quality
|
|
28
|
+
if (videoSample.format === 'apch') {
|
|
29
|
+
return 'prores';
|
|
30
|
+
}
|
|
31
|
+
// apcn: ProRes 422 Standard Definition
|
|
32
|
+
if (videoSample.format === 'apcn') {
|
|
33
|
+
return 'prores';
|
|
34
|
+
}
|
|
35
|
+
// apcs: ProRes 422 LT
|
|
36
|
+
if (videoSample.format === 'apcs') {
|
|
37
|
+
return 'prores';
|
|
38
|
+
}
|
|
39
|
+
// apco: ProRes 422 Proxy
|
|
40
|
+
if (videoSample.format === 'apco') {
|
|
41
|
+
return 'prores';
|
|
42
|
+
}
|
|
43
|
+
// aprh: ProRes RAW High Quality
|
|
44
|
+
if (videoSample.format === 'aprh') {
|
|
45
|
+
return 'prores';
|
|
46
|
+
}
|
|
47
|
+
// aprn: ProRes RAW Standard Definition
|
|
48
|
+
if (videoSample.format === 'aprn') {
|
|
49
|
+
return 'prores';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
throw new Error('Could not find video codec');
|
|
54
|
+
};
|
|
55
|
+
exports.getVideoCodecFromIsoTrak = getVideoCodecFromIsoTrak;
|