@ahmedrowaihi/mediabunny 1.65.2-beta.714 → 1.65.2-beta.716
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/bundles/mediabunny.cjs +180 -22
- package/dist/bundles/mediabunny.min.cjs +41 -41
- package/dist/bundles/mediabunny.min.mjs +42 -42
- package/dist/bundles/mediabunny.mjs +180 -22
- package/dist/bundles/mediabunny.node.cjs +180 -22
- package/dist/mediabunny.d.ts +23 -3
- package/dist/modules/src/codec-data.d.ts.map +1 -1
- package/dist/modules/src/codec-data.js +13 -0
- package/dist/modules/src/codec.d.ts +1 -1
- package/dist/modules/src/codec.d.ts.map +1 -1
- package/dist/modules/src/codec.js +12 -0
- package/dist/modules/src/crypto/cmaf-encryptor.d.ts +14 -0
- package/dist/modules/src/crypto/cmaf-encryptor.d.ts.map +1 -1
- package/dist/modules/src/crypto/cmaf-encryptor.js +38 -13
- package/dist/modules/src/crypto/encryption-boxes.js +14 -3
- package/dist/modules/src/custom-coder.d.ts +3 -2
- package/dist/modules/src/custom-coder.d.ts.map +1 -1
- package/dist/modules/src/encode.d.ts.map +1 -1
- package/dist/modules/src/encode.js +5 -0
- package/dist/modules/src/hdr-metadata.d.ts +6 -0
- package/dist/modules/src/hdr-metadata.d.ts.map +1 -1
- package/dist/modules/src/isobmff/isobmff-boxes.js +5 -0
- package/dist/modules/src/isobmff/isobmff-demuxer.d.ts +13 -0
- package/dist/modules/src/isobmff/isobmff-demuxer.d.ts.map +1 -1
- package/dist/modules/src/isobmff/isobmff-demuxer.js +110 -3
- package/dist/modules/src/isobmff/isobmff-misc.d.ts +5 -0
- package/dist/modules/src/isobmff/isobmff-misc.d.ts.map +1 -1
- package/dist/modules/src/isobmff/isobmff-misc.js +5 -0
- package/dist/modules/src/isobmff/isobmff-muxer.d.ts.map +1 -1
- package/dist/modules/src/isobmff/isobmff-muxer.js +5 -2
- package/dist/modules/src/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/codec-data.ts +11 -0
- package/src/codec.ts +12 -0
- package/src/crypto/cmaf-encryptor.ts +55 -11
- package/src/crypto/encryption-boxes.ts +17 -4
- package/src/custom-coder.ts +3 -2
- package/src/encode.ts +5 -0
- package/src/hdr-metadata.ts +6 -0
- package/src/isobmff/isobmff-boxes.ts +5 -0
- package/src/isobmff/isobmff-demuxer.ts +122 -2
- package/src/isobmff/isobmff-misc.ts +6 -0
- package/src/isobmff/isobmff-muxer.ts +5 -2
|
@@ -4850,6 +4850,16 @@ var Mediabunny = (() => {
|
|
|
4850
4850
|
return "key";
|
|
4851
4851
|
}
|
|
4852
4852
|
;
|
|
4853
|
+
case "png":
|
|
4854
|
+
{
|
|
4855
|
+
return "key";
|
|
4856
|
+
}
|
|
4857
|
+
;
|
|
4858
|
+
case "qtrle":
|
|
4859
|
+
{
|
|
4860
|
+
return null;
|
|
4861
|
+
}
|
|
4862
|
+
;
|
|
4853
4863
|
case "mpeg2":
|
|
4854
4864
|
{
|
|
4855
4865
|
const pictureHeaderAt = findMpeg2StartCode(packetData, MPEG2_PICTURE_START_CODE);
|
|
@@ -6548,6 +6558,7 @@ var Mediabunny = (() => {
|
|
|
6548
6558
|
|
|
6549
6559
|
// src/isobmff/isobmff-misc.ts
|
|
6550
6560
|
var TIMESTAMP_OFFSET = 2082844800;
|
|
6561
|
+
var TRACK_FRAGMENT_DESCRIPTION_INDEX_BASE = 65536;
|
|
6551
6562
|
var buildIsobmffMimeType = (info) => {
|
|
6552
6563
|
const base = info.hasVideo ? "video/" : info.hasAudio ? "audio/" : "application/";
|
|
6553
6564
|
let string = base + (info.isQuickTime ? "quicktime" : "mp4");
|
|
@@ -7996,6 +8007,7 @@ var Mediabunny = (() => {
|
|
|
7996
8007
|
"avin"
|
|
7997
8008
|
]);
|
|
7998
8009
|
var TRUEHD_CHANNEL_ASSIGNMENT_COUNTS = [2, 1, 1, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1];
|
|
8010
|
+
var SEIG_ENTRY_MIN_SIZE = 20;
|
|
7999
8011
|
var MAX_BOX_NESTING_DEPTH = 64;
|
|
8000
8012
|
var IsobmffDemuxer = class _IsobmffDemuxer extends Demuxer {
|
|
8001
8013
|
constructor(input) {
|
|
@@ -8019,6 +8031,10 @@ var Mediabunny = (() => {
|
|
|
8019
8031
|
this.sidxBoxes = [];
|
|
8020
8032
|
this.currentFragment = null;
|
|
8021
8033
|
this.isReadingTraf = false;
|
|
8034
|
+
/** `is_protected` per entry of the current `traf`'s own `sgpd`(`seig`), by zero-based entry index. */
|
|
8035
|
+
this.currentTrafSeigEntries = null;
|
|
8036
|
+
/** The current `traf`'s `sbgp`(`seig`) runs, applied once the `traf` is read: a `trun` may follow them. */
|
|
8037
|
+
this.currentTrafSeigRuns = null;
|
|
8022
8038
|
/**
|
|
8023
8039
|
* Caches the last fragment that was read. Based on the assumption that there will be multiple reads to the
|
|
8024
8040
|
* same fragment in quick succession.
|
|
@@ -8563,6 +8579,14 @@ var Mediabunny = (() => {
|
|
|
8563
8579
|
}
|
|
8564
8580
|
return fragment;
|
|
8565
8581
|
}
|
|
8582
|
+
/** The current `traf`'s `seig` state, cleared as it is read: one `traf`'s groups never reach the next. */
|
|
8583
|
+
takeTrafSeig() {
|
|
8584
|
+
const entries = this.currentTrafSeigEntries;
|
|
8585
|
+
const runs = this.currentTrafSeigRuns;
|
|
8586
|
+
this.currentTrafSeigEntries = null;
|
|
8587
|
+
this.currentTrafSeigRuns = null;
|
|
8588
|
+
return { entries, runs };
|
|
8589
|
+
}
|
|
8566
8590
|
readContiguousBoxes(slice) {
|
|
8567
8591
|
if (this.boxNestingDepth === MAX_BOX_NESTING_DEPTH) {
|
|
8568
8592
|
throw new Error("Invalid file: boxes are nested too deeply.");
|
|
@@ -8836,6 +8860,7 @@ var Mediabunny = (() => {
|
|
|
8836
8860
|
proresCodecInfo: null,
|
|
8837
8861
|
proresFormat: null,
|
|
8838
8862
|
hdrStaticMetadata: null,
|
|
8863
|
+
sampleEntryDepth: null,
|
|
8839
8864
|
doviConfig: null
|
|
8840
8865
|
};
|
|
8841
8866
|
} else if (handlerType === "soun") {
|
|
@@ -8918,7 +8943,9 @@ var Mediabunny = (() => {
|
|
|
8918
8943
|
track.info.height = readU16Be(slice);
|
|
8919
8944
|
track.info.squarePixelWidth = track.info.width;
|
|
8920
8945
|
track.info.squarePixelHeight = track.info.height;
|
|
8921
|
-
slice.skip(4 + 4 + 4 + 2 + 32
|
|
8946
|
+
slice.skip(4 + 4 + 4 + 2 + 32);
|
|
8947
|
+
track.info.sampleEntryDepth = readU16Be(slice);
|
|
8948
|
+
slice.skip(2);
|
|
8922
8949
|
track.frmaCodecString = null;
|
|
8923
8950
|
this.readContiguousBoxes(
|
|
8924
8951
|
slice.slice(
|
|
@@ -8952,6 +8979,10 @@ var Mediabunny = (() => {
|
|
|
8952
8979
|
} else if (codecName === "m2v1") {
|
|
8953
8980
|
track.info.codec = "mpeg2";
|
|
8954
8981
|
} else if (codecName === "mp4v") {
|
|
8982
|
+
} else if (codecName === "rle ") {
|
|
8983
|
+
track.info.codec = "qtrle";
|
|
8984
|
+
} else if (codecName === "png ") {
|
|
8985
|
+
track.info.codec = "png";
|
|
8955
8986
|
} else if (PRORES_FOURCCS.includes(lowercaseBoxName)) {
|
|
8956
8987
|
track.info.codec = "prores";
|
|
8957
8988
|
track.info.proresFormat = lowercaseBoxName;
|
|
@@ -10036,11 +10067,28 @@ var Mediabunny = (() => {
|
|
|
10036
10067
|
break;
|
|
10037
10068
|
}
|
|
10038
10069
|
this.isReadingTraf = true;
|
|
10070
|
+
this.takeTrafSeig();
|
|
10039
10071
|
try {
|
|
10040
10072
|
this.readContiguousBoxes(slice.slice(contentStartPos, boxInfo.contentSize));
|
|
10041
10073
|
} finally {
|
|
10042
10074
|
this.isReadingTraf = false;
|
|
10043
10075
|
}
|
|
10076
|
+
const seig = this.takeTrafSeig();
|
|
10077
|
+
if (seig.runs && this.currentTrack) {
|
|
10078
|
+
const trackData = this.currentFragment.trackData.get(this.currentTrack.id);
|
|
10079
|
+
const entries = seig.entries;
|
|
10080
|
+
let sampleIndex = 0;
|
|
10081
|
+
for (const run of seig.runs) {
|
|
10082
|
+
const local = run.descriptionIndex - TRACK_FRAGMENT_DESCRIPTION_INDEX_BASE - 1;
|
|
10083
|
+
const unprotected = entries !== null && local >= 0 && entries[local] === false;
|
|
10084
|
+
for (let i = 0; i < run.sampleCount; i++, sampleIndex++) {
|
|
10085
|
+
const sample = trackData?.samples[sampleIndex];
|
|
10086
|
+
if (sample && unprotected) {
|
|
10087
|
+
sample.unprotected = true;
|
|
10088
|
+
}
|
|
10089
|
+
}
|
|
10090
|
+
}
|
|
10091
|
+
}
|
|
10044
10092
|
if (this.currentTrack) {
|
|
10045
10093
|
const trackData = this.currentFragment.trackData.get(this.currentTrack.id);
|
|
10046
10094
|
cond:
|
|
@@ -10264,7 +10312,8 @@ var Mediabunny = (() => {
|
|
|
10264
10312
|
byteOffset: trackData.currentOffset,
|
|
10265
10313
|
byteSize: sampleSize,
|
|
10266
10314
|
isKeyFrame,
|
|
10267
|
-
encryption: null
|
|
10315
|
+
encryption: null,
|
|
10316
|
+
unprotected: false
|
|
10268
10317
|
});
|
|
10269
10318
|
trackData.currentOffset += sampleSize;
|
|
10270
10319
|
trackData.currentTimestamp += sampleDuration;
|
|
@@ -10335,6 +10384,62 @@ var Mediabunny = (() => {
|
|
|
10335
10384
|
}
|
|
10336
10385
|
;
|
|
10337
10386
|
break;
|
|
10387
|
+
case "sgpd":
|
|
10388
|
+
{
|
|
10389
|
+
if (!this.isReadingTraf) {
|
|
10390
|
+
break;
|
|
10391
|
+
}
|
|
10392
|
+
const version = readU8(slice);
|
|
10393
|
+
slice.skip(3);
|
|
10394
|
+
if (readAscii(slice, 4) !== "seig") {
|
|
10395
|
+
break;
|
|
10396
|
+
}
|
|
10397
|
+
const defaultLength = version === 1 ? readU32Be(slice) : 0;
|
|
10398
|
+
if (version >= 2) {
|
|
10399
|
+
slice.skip(4);
|
|
10400
|
+
}
|
|
10401
|
+
const entryCount = readU32Be(slice);
|
|
10402
|
+
const entries = [];
|
|
10403
|
+
for (let i = 0; i < entryCount; i++) {
|
|
10404
|
+
const length = version === 1 && defaultLength === 0 ? readU32Be(slice) : defaultLength;
|
|
10405
|
+
if (length < SEIG_ENTRY_MIN_SIZE || length > slice.remainingLength) {
|
|
10406
|
+
throw new Error(
|
|
10407
|
+
`Malformed sgpd box: a seig entry of ${length} bytes cannot hold its own fields.`
|
|
10408
|
+
);
|
|
10409
|
+
}
|
|
10410
|
+
slice.skip(2);
|
|
10411
|
+
entries.push(readU8(slice) !== 0);
|
|
10412
|
+
slice.skip(length - 3);
|
|
10413
|
+
}
|
|
10414
|
+
this.currentTrafSeigEntries = entries;
|
|
10415
|
+
}
|
|
10416
|
+
;
|
|
10417
|
+
break;
|
|
10418
|
+
case "sbgp":
|
|
10419
|
+
{
|
|
10420
|
+
if (!this.isReadingTraf) {
|
|
10421
|
+
break;
|
|
10422
|
+
}
|
|
10423
|
+
const version = readU8(slice);
|
|
10424
|
+
slice.skip(3);
|
|
10425
|
+
if (readAscii(slice, 4) !== "seig") {
|
|
10426
|
+
break;
|
|
10427
|
+
}
|
|
10428
|
+
if (version === 1) {
|
|
10429
|
+
slice.skip(4);
|
|
10430
|
+
}
|
|
10431
|
+
const entryCount = readU32Be(slice);
|
|
10432
|
+
const runs = [];
|
|
10433
|
+
for (let i = 0; i < entryCount; i++) {
|
|
10434
|
+
if (slice.remainingLength < 8) {
|
|
10435
|
+
throw new Error("Malformed sbgp box: it claims more runs than it holds.");
|
|
10436
|
+
}
|
|
10437
|
+
runs.push({ sampleCount: readU32Be(slice), descriptionIndex: readU32Be(slice) });
|
|
10438
|
+
}
|
|
10439
|
+
this.currentTrafSeigRuns = runs;
|
|
10440
|
+
}
|
|
10441
|
+
;
|
|
10442
|
+
break;
|
|
10338
10443
|
case "senc":
|
|
10339
10444
|
{
|
|
10340
10445
|
const track = this.currentTrack;
|
|
@@ -11091,7 +11196,7 @@ var Mediabunny = (() => {
|
|
|
11091
11196
|
return null;
|
|
11092
11197
|
}
|
|
11093
11198
|
data = readBytes(slice, fragmentSample.byteSize);
|
|
11094
|
-
if (this.internalTrack.encryptionInfo) {
|
|
11199
|
+
if (this.internalTrack.encryptionInfo && !fragmentSample.unprotected) {
|
|
11095
11200
|
const sampleEncryption = fragmentSample.encryption ?? getDefaultSampleEncryption(this.internalTrack.encryptionInfo);
|
|
11096
11201
|
if (sampleEncryption) {
|
|
11097
11202
|
data = await decryptSample(this.internalTrack, sampleEncryption, data, fragment);
|
|
@@ -11330,6 +11435,9 @@ var Mediabunny = (() => {
|
|
|
11330
11435
|
if (this.internalTrack.info.doviConfig) {
|
|
11331
11436
|
config.dolbyVision = this.internalTrack.info.doviConfig;
|
|
11332
11437
|
}
|
|
11438
|
+
if (this.internalTrack.info.sampleEntryDepth !== null) {
|
|
11439
|
+
config.bitsPerCodedSample = this.internalTrack.info.sampleEntryDepth;
|
|
11440
|
+
}
|
|
11333
11441
|
const codec = this.internalTrack.info.codec;
|
|
11334
11442
|
if ((codec === "hevc" || codec === "avc") && transferNeedsTenBits(config.colorSpace?.transfer) && (!config.hdrStaticMetadata?.masteringDisplay || !config.hdrStaticMetadata.contentLight)) {
|
|
11335
11443
|
const firstPacket = await this.getFirstPacket({});
|
|
@@ -30920,8 +31028,13 @@ var Mediabunny = (() => {
|
|
|
30920
31028
|
// Slightly less efficient than AVC
|
|
30921
31029
|
prores: 22e7 / referenceBitrate,
|
|
30922
31030
|
// Apple ProRes white paper claims 220 Mbps for 1080p 422 HQ @30Hz
|
|
30923
|
-
mpeg2: 2.5
|
|
31031
|
+
mpeg2: 2.5,
|
|
30924
31032
|
// Roughly 2.5x the bitrate of AVC for comparable quality
|
|
31033
|
+
// Neither has an encoder here, so these are only ever a size estimate for a track being copied.
|
|
31034
|
+
// 8-bit RGBA at 1080p30 is 1.99 Gbps uncompressed; QuickTime RLE barely moves that on camera
|
|
31035
|
+
// content, and PNG's filters and deflate take roughly half.
|
|
31036
|
+
qtrle: 199e7 / referenceBitrate,
|
|
31037
|
+
png: 995e6 / referenceBitrate
|
|
30925
31038
|
};
|
|
30926
31039
|
const codecAdjustedBitrate = baseBitrate * codecEfficiencyFactors[codec];
|
|
30927
31040
|
const finalBitrate = codecAdjustedBitrate * factor;
|
|
@@ -38412,7 +38525,9 @@ var Mediabunny = (() => {
|
|
|
38412
38525
|
"av1",
|
|
38413
38526
|
"vp8",
|
|
38414
38527
|
"prores",
|
|
38415
|
-
"mpeg2"
|
|
38528
|
+
"mpeg2",
|
|
38529
|
+
"qtrle",
|
|
38530
|
+
"png"
|
|
38416
38531
|
];
|
|
38417
38532
|
var PCM_AUDIO_CODECS = [
|
|
38418
38533
|
"pcm-s16",
|
|
@@ -38666,7 +38781,10 @@ var Mediabunny = (() => {
|
|
|
38666
38781
|
// Main and 4:2:2 Profile are both 8-bit; the deeper profiles are out of scope here
|
|
38667
38782
|
mpeg2: [8],
|
|
38668
38783
|
// ProRes stores 10 bits (422) or 12 bits (4444); the four-character code fixes it, so it can't be requested.
|
|
38669
|
-
prores: []
|
|
38784
|
+
prores: [],
|
|
38785
|
+
// Read-only here: neither has an encoder, so no bit depth can be requested of one
|
|
38786
|
+
qtrle: [],
|
|
38787
|
+
png: []
|
|
38670
38788
|
};
|
|
38671
38789
|
var buildVideoCodecString = (codec, width, height, bitrate, alpha, bitDepth) => {
|
|
38672
38790
|
if (bitDepth !== void 0 && !CODEC_BIT_DEPTHS[codec].includes(bitDepth)) {
|
|
@@ -38733,6 +38851,10 @@ var Mediabunny = (() => {
|
|
|
38733
38851
|
return bestFourCc;
|
|
38734
38852
|
} else if (codec === "mpeg2") {
|
|
38735
38853
|
return mpeg2CodecString(MPEG2_OBJECT_TYPE_MAIN);
|
|
38854
|
+
} else if (codec === "qtrle" || codec === "png") {
|
|
38855
|
+
throw new TypeError(
|
|
38856
|
+
`'${codec}' can be read and decoded but not encoded, so no codec string can be built for it.`
|
|
38857
|
+
);
|
|
38736
38858
|
} else {
|
|
38737
38859
|
assertNever(codec);
|
|
38738
38860
|
}
|
|
@@ -38928,6 +39050,8 @@ var Mediabunny = (() => {
|
|
|
38928
39050
|
return proresFormat ?? "apch";
|
|
38929
39051
|
} else if (codec === "mpeg2") {
|
|
38930
39052
|
return mpeg2CodecString(mpeg2ObjectTypeFromProfile(mpeg2CodecInfo?.profileAndLevelIndication ?? null));
|
|
39053
|
+
} else if (codec === "qtrle" || codec === "png") {
|
|
39054
|
+
return codec;
|
|
38931
39055
|
} else if (codec !== null) {
|
|
38932
39056
|
assertNever(codec);
|
|
38933
39057
|
}
|
|
@@ -42021,6 +42145,10 @@ var Mediabunny = (() => {
|
|
|
42021
42145
|
// QuickTime's own entry, which ffmpeg writes for `-f mov`, against the generic MPEG-4 visual one
|
|
42022
42146
|
case "mpeg2":
|
|
42023
42147
|
return isQuickTime ? "m2v1" : "mp4v";
|
|
42148
|
+
case "qtrle":
|
|
42149
|
+
return "rle ";
|
|
42150
|
+
case "png":
|
|
42151
|
+
return "png ";
|
|
42024
42152
|
}
|
|
42025
42153
|
};
|
|
42026
42154
|
var declaredVideoCodec = (codec, codecString, segmentFormat, inBandParameterSets) => {
|
|
@@ -42048,7 +42176,10 @@ var Mediabunny = (() => {
|
|
|
42048
42176
|
vp8: vpcC,
|
|
42049
42177
|
vp9: vpcC,
|
|
42050
42178
|
av1: av1C,
|
|
42051
|
-
prores: null
|
|
42179
|
+
prores: null,
|
|
42180
|
+
// Both entries are self-describing: the dimensions and the depth field are the whole configuration
|
|
42181
|
+
qtrle: null,
|
|
42182
|
+
png: null
|
|
42052
42183
|
};
|
|
42053
42184
|
var audioCodecToBoxName = (codec, fullCodecString, isQuickTime) => {
|
|
42054
42185
|
switch (codec) {
|
|
@@ -43133,7 +43264,7 @@ var Mediabunny = (() => {
|
|
|
43133
43264
|
num: displayAspectWidth * decoderConfig.codedHeight,
|
|
43134
43265
|
den: displayAspectHeight * decoderConfig.codedWidth
|
|
43135
43266
|
});
|
|
43136
|
-
const hasAlphaChannel = decoderConfig.codec === "ap4h" || decoderConfig.codec === "ap4x";
|
|
43267
|
+
const hasAlphaChannel = decoderConfig.codec === "ap4h" || decoderConfig.codec === "ap4x" || decoderConfig.bitsPerCodedSample === 32;
|
|
43137
43268
|
const newTrackData = {
|
|
43138
43269
|
muxer: this,
|
|
43139
43270
|
track,
|
|
@@ -60028,7 +60159,7 @@ ${baseUrl}${p.getFileName()}`;
|
|
|
60028
60159
|
// reserved
|
|
60029
60160
|
pattern,
|
|
60030
60161
|
// reserved (0) for v0; crypt<<4|skip for v1
|
|
60031
|
-
1
|
|
60162
|
+
options.isProtected === false ? 0 : 1
|
|
60032
60163
|
// default_is_protected
|
|
60033
60164
|
];
|
|
60034
60165
|
if (options.constantIv !== void 0) {
|
|
@@ -60050,13 +60181,18 @@ ${baseUrl}${p.getFileName()}`;
|
|
|
60050
60181
|
]);
|
|
60051
60182
|
};
|
|
60052
60183
|
var seigEntry = (options) => tenc(options).contents.subarray(4);
|
|
60184
|
+
var clearSeigEntry = () => seigEntry({
|
|
60185
|
+
kid: new Uint8Array(16),
|
|
60186
|
+
cryptByteBlock: 0,
|
|
60187
|
+
skipByteBlock: 0,
|
|
60188
|
+
isProtected: false
|
|
60189
|
+
});
|
|
60053
60190
|
var sgpdSeig = (entries) => fullBox("sgpd", 1, 0, [
|
|
60054
60191
|
chars2("seig"),
|
|
60055
60192
|
u323(entries[0].byteLength),
|
|
60056
60193
|
u323(entries.length),
|
|
60057
60194
|
entries.map((entry) => [...entry])
|
|
60058
60195
|
]);
|
|
60059
|
-
var TRACK_FRAGMENT_DESCRIPTION_INDEX_BASE = 65536;
|
|
60060
60196
|
var sbgpSeig = (runs) => fullBox("sbgp", 0, 0, [
|
|
60061
60197
|
chars2("seig"),
|
|
60062
60198
|
u323(runs.length),
|
|
@@ -64250,6 +64386,7 @@ ${baseUrl}${p.getFileName()}`;
|
|
|
64250
64386
|
return { used, runs };
|
|
64251
64387
|
};
|
|
64252
64388
|
var encryptFragments = (boxes, tracks, encryptors, scheme, options, material, offsetsBefore, applyCipher = true) => {
|
|
64389
|
+
const clear = options.clear === true;
|
|
64253
64390
|
const perSampleIvSize = usesPerSampleIv2(scheme) ? options.iv.length : 0;
|
|
64254
64391
|
const rotations = /* @__PURE__ */ new Map();
|
|
64255
64392
|
for (const track of tracks) {
|
|
@@ -64275,7 +64412,8 @@ ${baseUrl}${p.getFileName()}`;
|
|
|
64275
64412
|
offsetsBefore[i],
|
|
64276
64413
|
rotations,
|
|
64277
64414
|
currentPeriod,
|
|
64278
|
-
applyCipher
|
|
64415
|
+
applyCipher && !clear,
|
|
64416
|
+
clear
|
|
64279
64417
|
);
|
|
64280
64418
|
encryptedFragments++;
|
|
64281
64419
|
}
|
|
@@ -64451,6 +64589,11 @@ ${baseUrl}${p.getFileName()}`;
|
|
|
64451
64589
|
if (boxes.some((box2, i) => box2.type === "moof" && boxes[i + 1]?.type === "mdat")) {
|
|
64452
64590
|
encryptFragments(boxes, tracks, encryptors, scheme, options, material, offsetsBefore);
|
|
64453
64591
|
} else {
|
|
64592
|
+
if (options.clear) {
|
|
64593
|
+
throw new InvalidUsageError(
|
|
64594
|
+
"clear states that this segment is a clear lead, but this file is progressive: its samples are located by the moov sample table, which holds no per-fragment sample groups to state that they are unprotected. Fragment the file into moof/mdat first."
|
|
64595
|
+
);
|
|
64596
|
+
}
|
|
64454
64597
|
const rotating = [...material].filter(([, track]) => track.periods !== void 0).map(([id]) => id);
|
|
64455
64598
|
if (rotating.length > 0) {
|
|
64456
64599
|
throw new InvalidUsageError(
|
|
@@ -64518,7 +64661,7 @@ ${baseUrl}${p.getFileName()}`;
|
|
|
64518
64661
|
encryptFragments(segmentBoxes, tracks, encryptors, scheme, options, material, arrivedOffsets(segment), false);
|
|
64519
64662
|
return chunksOf(serializeBoxes(segmentBoxes), init);
|
|
64520
64663
|
};
|
|
64521
|
-
var encryptFragmentInPlace = (moof2, mdat2, tracks, encryptors, perSampleIvSize, moofOffset, rotations, currentPeriod, applyCipher = true) => {
|
|
64664
|
+
var encryptFragmentInPlace = (moof2, mdat2, tracks, encryptors, perSampleIvSize, moofOffset, rotations, currentPeriod, applyCipher = true, clear = false) => {
|
|
64522
64665
|
const moofSizeBefore = measureBox(moof2);
|
|
64523
64666
|
const mdatDataStart = moofOffset + moofSizeBefore + 8;
|
|
64524
64667
|
const bases = new Map(
|
|
@@ -64539,7 +64682,8 @@ ${baseUrl}${p.getFileName()}`;
|
|
|
64539
64682
|
const base = bases.get(track.trackId);
|
|
64540
64683
|
const defaultSampleSize = defaultSampleSizeOf2(tfhd2);
|
|
64541
64684
|
const encryptor = encryptors.get(track.trackId);
|
|
64542
|
-
const rotation = rotations.get(track.trackId);
|
|
64685
|
+
const rotation = clear ? void 0 : rotations.get(track.trackId);
|
|
64686
|
+
let clearSamples = 0;
|
|
64543
64687
|
const subsamplesPerSample = [];
|
|
64544
64688
|
const perSampleIvs = [];
|
|
64545
64689
|
const periodPerSample = [];
|
|
@@ -64566,20 +64710,34 @@ ${baseUrl}${p.getFileName()}`;
|
|
|
64566
64710
|
`A trun for track ${track.trackId} names sample bytes at ${cursor}..${cursor + size}, outside its ${mdat2.data.length}-byte mdat.`
|
|
64567
64711
|
);
|
|
64568
64712
|
}
|
|
64569
|
-
|
|
64570
|
-
|
|
64571
|
-
const encrypted = encryptor.encryptSample(sample);
|
|
64572
|
-
mdat2.data.set(encrypted.data, cursor);
|
|
64573
|
-
subsamplesPerSample.push(encrypted.subsamples);
|
|
64574
|
-
perSampleIvs.push(encrypted.iv);
|
|
64713
|
+
if (clear) {
|
|
64714
|
+
clearSamples++;
|
|
64575
64715
|
} else {
|
|
64576
|
-
const
|
|
64577
|
-
|
|
64578
|
-
|
|
64716
|
+
const sample = mdat2.data.subarray(cursor, cursor + size);
|
|
64717
|
+
if (applyCipher) {
|
|
64718
|
+
const encrypted = encryptor.encryptSample(sample);
|
|
64719
|
+
mdat2.data.set(encrypted.data, cursor);
|
|
64720
|
+
subsamplesPerSample.push(encrypted.subsamples);
|
|
64721
|
+
perSampleIvs.push(encrypted.iv);
|
|
64722
|
+
} else {
|
|
64723
|
+
const planned = encryptor.describeSample(sample);
|
|
64724
|
+
subsamplesPerSample.push(planned.subsamples);
|
|
64725
|
+
perSampleIvs.push(planned.iv);
|
|
64726
|
+
}
|
|
64579
64727
|
}
|
|
64580
64728
|
cursor += size;
|
|
64581
64729
|
}
|
|
64582
64730
|
}
|
|
64731
|
+
if (clear) {
|
|
64732
|
+
if (clearSamples > 0) {
|
|
64733
|
+
traf2.children = [
|
|
64734
|
+
...traf2.children ?? [],
|
|
64735
|
+
toMutable(sgpdSeig([clearSeigEntry()])),
|
|
64736
|
+
toMutable(sbgpSeig([{ sampleCount: clearSamples, entryIndex: 0 }]))
|
|
64737
|
+
];
|
|
64738
|
+
}
|
|
64739
|
+
continue;
|
|
64740
|
+
}
|
|
64583
64741
|
const groups = rotation === void 0 ? null : sampleGroups(periodPerSample);
|
|
64584
64742
|
if (groups !== null) {
|
|
64585
64743
|
traf2.children = [
|