@invintusmedia/tomp4 1.2.0 → 1.2.1
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/tomp4.js +606 -163
- package/package.json +2 -1
- package/src/fmp4/converter.js +604 -161
- package/src/fmp4/utils.js +13 -6
- package/src/index.js +3 -3
- package/src/thumbnail.js +2 -2
package/src/fmp4/utils.js
CHANGED
|
@@ -85,22 +85,29 @@ export function createBox(type, ...payloads) {
|
|
|
85
85
|
* Parse tfhd (track fragment header) box
|
|
86
86
|
* Extracts track ID and default sample values
|
|
87
87
|
* @param {Uint8Array} tfhdData - tfhd box data
|
|
88
|
-
* @
|
|
88
|
+
* @param {{defaultSampleDuration?: number, defaultSampleSize?: number, defaultSampleFlags?: number}} defaults - Defaults (e.g. from trex)
|
|
89
|
+
* @returns {{trackId: number, flags: number, baseDataOffset: number, defaultSampleDuration: number, defaultSampleSize: number, defaultSampleFlags: number}}
|
|
89
90
|
*/
|
|
90
|
-
export function parseTfhd(tfhdData) {
|
|
91
|
+
export function parseTfhd(tfhdData, defaults = {}) {
|
|
91
92
|
const view = new DataView(tfhdData.buffer, tfhdData.byteOffset, tfhdData.byteLength);
|
|
92
93
|
const flags = (tfhdData[9] << 16) | (tfhdData[10] << 8) | tfhdData[11];
|
|
93
94
|
const trackId = view.getUint32(12);
|
|
94
95
|
let offset = 16;
|
|
95
|
-
let
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
let baseDataOffset = 0;
|
|
97
|
+
let defaultSampleDuration = defaults.defaultSampleDuration || 0;
|
|
98
|
+
let defaultSampleSize = defaults.defaultSampleSize || 0;
|
|
99
|
+
let defaultSampleFlags = defaults.defaultSampleFlags || 0;
|
|
100
|
+
|
|
101
|
+
if (flags & 0x1) {
|
|
102
|
+
baseDataOffset = Number(view.getBigUint64(offset));
|
|
103
|
+
offset += 8;
|
|
104
|
+
}
|
|
98
105
|
if (flags & 0x2) offset += 4; // sample-description-index
|
|
99
106
|
if (flags & 0x8) { defaultSampleDuration = view.getUint32(offset); offset += 4; }
|
|
100
107
|
if (flags & 0x10) { defaultSampleSize = view.getUint32(offset); offset += 4; }
|
|
101
108
|
if (flags & 0x20) { defaultSampleFlags = view.getUint32(offset); offset += 4; }
|
|
102
109
|
|
|
103
|
-
return { trackId, defaultSampleDuration, defaultSampleSize, defaultSampleFlags };
|
|
110
|
+
return { trackId, flags, baseDataOffset, defaultSampleDuration, defaultSampleSize, defaultSampleFlags };
|
|
104
111
|
}
|
|
105
112
|
|
|
106
113
|
/**
|
package/src/index.js
CHANGED
|
@@ -177,7 +177,7 @@ function convertData(data, options = {}) {
|
|
|
177
177
|
case 'mpegts':
|
|
178
178
|
return convertTsToMp4(uint8, options);
|
|
179
179
|
case 'fmp4':
|
|
180
|
-
return convertFmp4ToMp4(uint8);
|
|
180
|
+
return convertFmp4ToMp4(uint8, options);
|
|
181
181
|
case 'mp4':
|
|
182
182
|
return uint8;
|
|
183
183
|
default:
|
|
@@ -301,7 +301,7 @@ async function toMp4(input, options = {}) {
|
|
|
301
301
|
|
|
302
302
|
// Attach utilities to main function
|
|
303
303
|
toMp4.fromTs = (data, options) => new Mp4Result(convertTsToMp4(data instanceof ArrayBuffer ? new Uint8Array(data) : data, options));
|
|
304
|
-
toMp4.fromFmp4 = (data) => new Mp4Result(convertFmp4ToMp4(data instanceof ArrayBuffer ? new Uint8Array(data) : data));
|
|
304
|
+
toMp4.fromFmp4 = (data, options = {}) => new Mp4Result(convertFmp4ToMp4(data instanceof ArrayBuffer ? new Uint8Array(data) : data, options));
|
|
305
305
|
toMp4.stitchFmp4 = (segments, options) => new Mp4Result(stitchFmp4(segments, options));
|
|
306
306
|
toMp4.stitchTs = (segments) => new Mp4Result(stitchTs(segments));
|
|
307
307
|
toMp4.concatTs = concatTs;
|
|
@@ -331,7 +331,7 @@ toMp4.TSParser = TSParser;
|
|
|
331
331
|
toMp4.RemoteMp4 = RemoteMp4;
|
|
332
332
|
|
|
333
333
|
// Version (injected at build time for dist, read from package.json for ESM)
|
|
334
|
-
toMp4.version = '1.2.
|
|
334
|
+
toMp4.version = '1.2.1';
|
|
335
335
|
|
|
336
336
|
// Export
|
|
337
337
|
export {
|
package/src/thumbnail.js
CHANGED
|
@@ -142,8 +142,8 @@ export async function thumbnail(input, options = {}) {
|
|
|
142
142
|
});
|
|
143
143
|
mp4Cleanup = () => mp4.revokeURL();
|
|
144
144
|
mediaUrl = mp4.toURL();
|
|
145
|
-
// The clip is normalized to start at 0
|
|
146
|
-
localSeek = 0
|
|
145
|
+
// The clip is normalized to requested start at t=0.
|
|
146
|
+
localSeek = 0;
|
|
147
147
|
};
|
|
148
148
|
|
|
149
149
|
const isSegmentsObject =
|