mediabunny 1.35.1 → 1.36.0

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.
Files changed (69) hide show
  1. package/dist/bundles/mediabunny.cjs +177 -170
  2. package/dist/bundles/mediabunny.min.cjs +8 -7
  3. package/dist/bundles/mediabunny.min.mjs +9 -8
  4. package/dist/bundles/mediabunny.mjs +177 -170
  5. package/dist/modules/shared/aac-misc.d.ts +30 -0
  6. package/dist/modules/shared/aac-misc.d.ts.map +1 -0
  7. package/dist/modules/shared/aac-misc.js +107 -0
  8. package/dist/modules/shared/bitstream.d.ts +22 -0
  9. package/dist/modules/shared/bitstream.d.ts.map +1 -0
  10. package/dist/modules/shared/bitstream.js +69 -0
  11. package/dist/modules/src/adts/adts-demuxer.d.ts.map +1 -1
  12. package/dist/modules/src/adts/adts-demuxer.js +1 -1
  13. package/dist/modules/src/adts/adts-muxer.d.ts.map +1 -1
  14. package/dist/modules/src/adts/adts-muxer.js +2 -2
  15. package/dist/modules/src/adts/adts-reader.js +1 -1
  16. package/dist/modules/src/codec-data.d.ts.map +1 -1
  17. package/dist/modules/src/codec-data.js +2 -1
  18. package/dist/modules/src/codec.d.ts +1 -16
  19. package/dist/modules/src/codec.d.ts.map +1 -1
  20. package/dist/modules/src/codec.js +2 -73
  21. package/dist/modules/src/conversion.d.ts.map +1 -1
  22. package/dist/modules/src/conversion.js +3 -0
  23. package/dist/modules/src/flac/flac-demuxer.d.ts.map +1 -1
  24. package/dist/modules/src/flac/flac-demuxer.js +2 -1
  25. package/dist/modules/src/flac/flac-misc.d.ts.map +1 -1
  26. package/dist/modules/src/flac/flac-misc.js +2 -1
  27. package/dist/modules/src/flac/flac-muxer.d.ts.map +1 -1
  28. package/dist/modules/src/flac/flac-muxer.js +2 -1
  29. package/dist/modules/src/isobmff/isobmff-boxes.d.ts.map +1 -1
  30. package/dist/modules/src/isobmff/isobmff-boxes.js +2 -1
  31. package/dist/modules/src/isobmff/isobmff-demuxer.d.ts.map +1 -1
  32. package/dist/modules/src/isobmff/isobmff-demuxer.js +4 -2
  33. package/dist/modules/src/isobmff/isobmff-muxer.d.ts.map +1 -1
  34. package/dist/modules/src/isobmff/isobmff-muxer.js +2 -1
  35. package/dist/modules/src/matroska/ebml.d.ts +4 -4
  36. package/dist/modules/src/matroska/matroska-muxer.d.ts.map +1 -1
  37. package/dist/modules/src/matroska/matroska-muxer.js +4 -2
  38. package/dist/modules/src/media-source.d.ts.map +1 -1
  39. package/dist/modules/src/media-source.js +2 -1
  40. package/dist/modules/src/misc.d.ts +1 -14
  41. package/dist/modules/src/misc.d.ts.map +1 -1
  42. package/dist/modules/src/misc.js +0 -63
  43. package/dist/modules/src/mpeg-ts/mpeg-ts-demuxer.d.ts.map +1 -1
  44. package/dist/modules/src/mpeg-ts/mpeg-ts-demuxer.js +4 -2
  45. package/dist/modules/src/mpeg-ts/mpeg-ts-muxer.d.ts.map +1 -1
  46. package/dist/modules/src/mpeg-ts/mpeg-ts-muxer.js +4 -3
  47. package/dist/modules/src/tsconfig.tsbuildinfo +1 -1
  48. package/package.json +2 -2
  49. package/src/adts/adts-demuxer.ts +2 -1
  50. package/src/adts/adts-muxer.ts +4 -3
  51. package/src/adts/adts-reader.ts +1 -1
  52. package/src/codec-data.ts +1 -1
  53. package/src/codec.ts +1 -101
  54. package/src/conversion.ts +6 -0
  55. package/src/flac/flac-demuxer.ts +1 -1
  56. package/src/flac/flac-misc.ts +2 -1
  57. package/src/flac/flac-muxer.ts +1 -1
  58. package/src/isobmff/isobmff-boxes.ts +1 -1
  59. package/src/isobmff/isobmff-demuxer.ts +2 -2
  60. package/src/isobmff/isobmff-muxer.ts +1 -3
  61. package/src/matroska/matroska-muxer.ts +2 -4
  62. package/src/media-source.ts +1 -2
  63. package/src/misc.ts +2 -79
  64. package/src/mpeg-ts/mpeg-ts-demuxer.ts +2 -3
  65. package/src/mpeg-ts/mpeg-ts-muxer.ts +4 -3
  66. package/dist/modules/src/adts/adts-misc.d.ts +0 -16
  67. package/dist/modules/src/adts/adts-misc.d.ts.map +0 -1
  68. package/dist/modules/src/adts/adts-misc.js +0 -35
  69. package/src/adts/adts-misc.ts +0 -47
@@ -179,67 +179,6 @@ var Mediabunny = (() => {
179
179
  var isU32 = (value) => {
180
180
  return value >= 0 && value < 2 ** 32;
181
181
  };
182
- var Bitstream = class _Bitstream {
183
- constructor(bytes2) {
184
- this.bytes = bytes2;
185
- /** Current offset in bits. */
186
- this.pos = 0;
187
- }
188
- seekToByte(byteOffset) {
189
- this.pos = 8 * byteOffset;
190
- }
191
- readBit() {
192
- const byteIndex = Math.floor(this.pos / 8);
193
- const byte = this.bytes[byteIndex] ?? 0;
194
- const bitIndex = 7 - (this.pos & 7);
195
- const bit = (byte & 1 << bitIndex) >> bitIndex;
196
- this.pos++;
197
- return bit;
198
- }
199
- readBits(n) {
200
- if (n === 1) {
201
- return this.readBit();
202
- }
203
- let result = 0;
204
- for (let i = 0; i < n; i++) {
205
- result <<= 1;
206
- result |= this.readBit();
207
- }
208
- return result;
209
- }
210
- writeBits(n, value) {
211
- const end = this.pos + n;
212
- for (let i = this.pos; i < end; i++) {
213
- const byteIndex = Math.floor(i / 8);
214
- let byte = this.bytes[byteIndex];
215
- const bitIndex = 7 - (i & 7);
216
- byte &= ~(1 << bitIndex);
217
- byte |= (value & 1 << end - i - 1) >> end - i - 1 << bitIndex;
218
- this.bytes[byteIndex] = byte;
219
- }
220
- this.pos = end;
221
- }
222
- readAlignedByte() {
223
- if (this.pos % 8 !== 0) {
224
- throw new Error("Bitstream is not byte-aligned.");
225
- }
226
- const byteIndex = this.pos / 8;
227
- const byte = this.bytes[byteIndex] ?? 0;
228
- this.pos += 8;
229
- return byte;
230
- }
231
- skipBits(n) {
232
- this.pos += n;
233
- }
234
- getBitsLeft() {
235
- return this.bytes.length * 8 - this.pos;
236
- }
237
- clone() {
238
- const clone = new _Bitstream(this.bytes);
239
- clone.pos = this.pos;
240
- return clone;
241
- }
242
- };
243
182
  var readExpGolomb = (bitstream) => {
244
183
  let leadingZeroBits = 0;
245
184
  while (bitstream.readBits(1) === 0 && leadingZeroBits < 32) {
@@ -939,6 +878,178 @@ var Mediabunny = (() => {
939
878
  }
940
879
  };
941
880
 
881
+ // shared/bitstream.ts
882
+ var Bitstream = class _Bitstream {
883
+ constructor(bytes2) {
884
+ this.bytes = bytes2;
885
+ /** Current offset in bits. */
886
+ this.pos = 0;
887
+ }
888
+ seekToByte(byteOffset) {
889
+ this.pos = 8 * byteOffset;
890
+ }
891
+ readBit() {
892
+ const byteIndex = Math.floor(this.pos / 8);
893
+ const byte = this.bytes[byteIndex] ?? 0;
894
+ const bitIndex = 7 - (this.pos & 7);
895
+ const bit = (byte & 1 << bitIndex) >> bitIndex;
896
+ this.pos++;
897
+ return bit;
898
+ }
899
+ readBits(n) {
900
+ if (n === 1) {
901
+ return this.readBit();
902
+ }
903
+ let result = 0;
904
+ for (let i = 0; i < n; i++) {
905
+ result <<= 1;
906
+ result |= this.readBit();
907
+ }
908
+ return result;
909
+ }
910
+ writeBits(n, value) {
911
+ const end = this.pos + n;
912
+ for (let i = this.pos; i < end; i++) {
913
+ const byteIndex = Math.floor(i / 8);
914
+ let byte = this.bytes[byteIndex];
915
+ const bitIndex = 7 - (i & 7);
916
+ byte &= ~(1 << bitIndex);
917
+ byte |= (value & 1 << end - i - 1) >> end - i - 1 << bitIndex;
918
+ this.bytes[byteIndex] = byte;
919
+ }
920
+ this.pos = end;
921
+ }
922
+ readAlignedByte() {
923
+ if (this.pos % 8 !== 0) {
924
+ throw new Error("Bitstream is not byte-aligned.");
925
+ }
926
+ const byteIndex = this.pos / 8;
927
+ const byte = this.bytes[byteIndex] ?? 0;
928
+ this.pos += 8;
929
+ return byte;
930
+ }
931
+ skipBits(n) {
932
+ this.pos += n;
933
+ }
934
+ getBitsLeft() {
935
+ return this.bytes.length * 8 - this.pos;
936
+ }
937
+ clone() {
938
+ const clone = new _Bitstream(this.bytes);
939
+ clone.pos = this.pos;
940
+ return clone;
941
+ }
942
+ };
943
+
944
+ // shared/aac-misc.ts
945
+ var aacFrequencyTable = [
946
+ 96e3,
947
+ 88200,
948
+ 64e3,
949
+ 48e3,
950
+ 44100,
951
+ 32e3,
952
+ 24e3,
953
+ 22050,
954
+ 16e3,
955
+ 12e3,
956
+ 11025,
957
+ 8e3,
958
+ 7350
959
+ ];
960
+ var aacChannelMap = [-1, 1, 2, 3, 4, 5, 6, 8];
961
+ var parseAacAudioSpecificConfig = (bytes2) => {
962
+ if (!bytes2 || bytes2.byteLength < 2) {
963
+ throw new TypeError("AAC description must be at least 2 bytes long.");
964
+ }
965
+ const bitstream = new Bitstream(bytes2);
966
+ let objectType = bitstream.readBits(5);
967
+ if (objectType === 31) {
968
+ objectType = 32 + bitstream.readBits(6);
969
+ }
970
+ const frequencyIndex = bitstream.readBits(4);
971
+ let sampleRate = null;
972
+ if (frequencyIndex === 15) {
973
+ sampleRate = bitstream.readBits(24);
974
+ } else {
975
+ if (frequencyIndex < aacFrequencyTable.length) {
976
+ sampleRate = aacFrequencyTable[frequencyIndex];
977
+ }
978
+ }
979
+ const channelConfiguration = bitstream.readBits(4);
980
+ let numberOfChannels = null;
981
+ if (channelConfiguration >= 1 && channelConfiguration <= 7) {
982
+ numberOfChannels = aacChannelMap[channelConfiguration];
983
+ }
984
+ return {
985
+ objectType,
986
+ frequencyIndex,
987
+ sampleRate,
988
+ channelConfiguration,
989
+ numberOfChannels
990
+ };
991
+ };
992
+ var buildAacAudioSpecificConfig = (config) => {
993
+ let frequencyIndex = aacFrequencyTable.indexOf(config.sampleRate);
994
+ let customSampleRate = null;
995
+ if (frequencyIndex === -1) {
996
+ frequencyIndex = 15;
997
+ customSampleRate = config.sampleRate;
998
+ }
999
+ const channelConfiguration = aacChannelMap.indexOf(config.numberOfChannels);
1000
+ if (channelConfiguration === -1) {
1001
+ throw new TypeError(`Unsupported number of channels: ${config.numberOfChannels}`);
1002
+ }
1003
+ let bitCount = 5 + 4 + 4;
1004
+ if (config.objectType >= 32) {
1005
+ bitCount += 6;
1006
+ }
1007
+ if (frequencyIndex === 15) {
1008
+ bitCount += 24;
1009
+ }
1010
+ const byteCount = Math.ceil(bitCount / 8);
1011
+ const bytes2 = new Uint8Array(byteCount);
1012
+ const bitstream = new Bitstream(bytes2);
1013
+ if (config.objectType < 32) {
1014
+ bitstream.writeBits(5, config.objectType);
1015
+ } else {
1016
+ bitstream.writeBits(5, 31);
1017
+ bitstream.writeBits(6, config.objectType - 32);
1018
+ }
1019
+ bitstream.writeBits(4, frequencyIndex);
1020
+ if (frequencyIndex === 15) {
1021
+ bitstream.writeBits(24, customSampleRate);
1022
+ }
1023
+ bitstream.writeBits(4, channelConfiguration);
1024
+ return bytes2;
1025
+ };
1026
+ var buildAdtsHeaderTemplate = (config) => {
1027
+ const header = new Uint8Array(7);
1028
+ const bitstream = new Bitstream(header);
1029
+ const { objectType, frequencyIndex, channelConfiguration } = config;
1030
+ const profile = objectType - 1;
1031
+ bitstream.writeBits(12, 4095);
1032
+ bitstream.writeBits(1, 0);
1033
+ bitstream.writeBits(2, 0);
1034
+ bitstream.writeBits(1, 1);
1035
+ bitstream.writeBits(2, profile);
1036
+ bitstream.writeBits(4, frequencyIndex);
1037
+ bitstream.writeBits(1, 0);
1038
+ bitstream.writeBits(3, channelConfiguration);
1039
+ bitstream.writeBits(1, 0);
1040
+ bitstream.writeBits(1, 0);
1041
+ bitstream.writeBits(1, 0);
1042
+ bitstream.writeBits(1, 0);
1043
+ bitstream.skipBits(13);
1044
+ bitstream.writeBits(11, 2047);
1045
+ bitstream.writeBits(2, 0);
1046
+ return { header, bitstream };
1047
+ };
1048
+ var writeAdtsFrameLength = (bitstream, frameLength) => {
1049
+ bitstream.pos = 30;
1050
+ bitstream.writeBits(13, frameLength);
1051
+ };
1052
+
942
1053
  // src/codec.ts
943
1054
  var VIDEO_CODECS = [
944
1055
  "avc",
@@ -1418,87 +1529,6 @@ var Mediabunny = (() => {
1418
1529
  }
1419
1530
  throw new TypeError(`Unhandled codec '${codec}'.`);
1420
1531
  };
1421
- var aacFrequencyTable = [
1422
- 96e3,
1423
- 88200,
1424
- 64e3,
1425
- 48e3,
1426
- 44100,
1427
- 32e3,
1428
- 24e3,
1429
- 22050,
1430
- 16e3,
1431
- 12e3,
1432
- 11025,
1433
- 8e3,
1434
- 7350
1435
- ];
1436
- var aacChannelMap = [-1, 1, 2, 3, 4, 5, 6, 8];
1437
- var parseAacAudioSpecificConfig = (bytes2) => {
1438
- if (!bytes2 || bytes2.byteLength < 2) {
1439
- throw new TypeError("AAC description must be at least 2 bytes long.");
1440
- }
1441
- const bitstream = new Bitstream(bytes2);
1442
- let objectType = bitstream.readBits(5);
1443
- if (objectType === 31) {
1444
- objectType = 32 + bitstream.readBits(6);
1445
- }
1446
- const frequencyIndex = bitstream.readBits(4);
1447
- let sampleRate = null;
1448
- if (frequencyIndex === 15) {
1449
- sampleRate = bitstream.readBits(24);
1450
- } else {
1451
- if (frequencyIndex < aacFrequencyTable.length) {
1452
- sampleRate = aacFrequencyTable[frequencyIndex];
1453
- }
1454
- }
1455
- const channelConfiguration = bitstream.readBits(4);
1456
- let numberOfChannels = null;
1457
- if (channelConfiguration >= 1 && channelConfiguration <= 7) {
1458
- numberOfChannels = aacChannelMap[channelConfiguration];
1459
- }
1460
- return {
1461
- objectType,
1462
- frequencyIndex,
1463
- sampleRate,
1464
- channelConfiguration,
1465
- numberOfChannels
1466
- };
1467
- };
1468
- var buildAacAudioSpecificConfig = (config) => {
1469
- let frequencyIndex = aacFrequencyTable.indexOf(config.sampleRate);
1470
- let customSampleRate = null;
1471
- if (frequencyIndex === -1) {
1472
- frequencyIndex = 15;
1473
- customSampleRate = config.sampleRate;
1474
- }
1475
- const channelConfiguration = aacChannelMap.indexOf(config.numberOfChannels);
1476
- if (channelConfiguration === -1) {
1477
- throw new TypeError(`Unsupported number of channels: ${config.numberOfChannels}`);
1478
- }
1479
- let bitCount = 5 + 4 + 4;
1480
- if (config.objectType >= 32) {
1481
- bitCount += 6;
1482
- }
1483
- if (frequencyIndex === 15) {
1484
- bitCount += 24;
1485
- }
1486
- const byteCount = Math.ceil(bitCount / 8);
1487
- const bytes2 = new Uint8Array(byteCount);
1488
- const bitstream = new Bitstream(bytes2);
1489
- if (config.objectType < 32) {
1490
- bitstream.writeBits(5, config.objectType);
1491
- } else {
1492
- bitstream.writeBits(5, 31);
1493
- bitstream.writeBits(6, config.objectType - 32);
1494
- }
1495
- bitstream.writeBits(4, frequencyIndex);
1496
- if (frequencyIndex === 15) {
1497
- bitstream.writeBits(24, customSampleRate);
1498
- }
1499
- bitstream.writeBits(4, channelConfiguration);
1500
- return bytes2;
1501
- };
1502
1532
  var OPUS_SAMPLE_RATE = 48e3;
1503
1533
  var PCM_CODEC_REGEX = /^pcm-([usf])(\d+)+(be)?$/;
1504
1534
  var parsePcmCodec = (codec) => {
@@ -19821,34 +19851,6 @@ var Mediabunny = (() => {
19821
19851
  }
19822
19852
  };
19823
19853
 
19824
- // src/adts/adts-misc.ts
19825
- var buildAdtsHeaderTemplate = (config) => {
19826
- const header = new Uint8Array(7);
19827
- const bitstream = new Bitstream(header);
19828
- const { objectType, frequencyIndex, channelConfiguration } = config;
19829
- const profile = objectType - 1;
19830
- bitstream.writeBits(12, 4095);
19831
- bitstream.writeBits(1, 0);
19832
- bitstream.writeBits(2, 0);
19833
- bitstream.writeBits(1, 1);
19834
- bitstream.writeBits(2, profile);
19835
- bitstream.writeBits(4, frequencyIndex);
19836
- bitstream.writeBits(1, 0);
19837
- bitstream.writeBits(3, channelConfiguration);
19838
- bitstream.writeBits(1, 0);
19839
- bitstream.writeBits(1, 0);
19840
- bitstream.writeBits(1, 0);
19841
- bitstream.writeBits(1, 0);
19842
- bitstream.skipBits(13);
19843
- bitstream.writeBits(11, 2047);
19844
- bitstream.writeBits(2, 0);
19845
- return { header, bitstream };
19846
- };
19847
- var writeAdtsFrameLength = (bitstream, frameLength) => {
19848
- bitstream.pos = 30;
19849
- bitstream.writeBits(13, frameLength);
19850
- };
19851
-
19852
19854
  // src/adts/adts-muxer.ts
19853
19855
  var AdtsMuxer = class extends Muxer {
19854
19856
  constructor(output, format) {
@@ -28779,6 +28781,11 @@ Tracks were discarded because your environment is not able to encode any of the
28779
28781
  The @mediabunny/mp3-encoder extension package provides support for encoding MP3.`
28780
28782
  );
28781
28783
  }
28784
+ if (codecs.includes("aac")) {
28785
+ elements.push(
28786
+ "\nThe @mediabunny/aac-encoder extension package provides support for encoding AAC."
28787
+ );
28788
+ }
28782
28789
  if (codecs.includes("ac3") || codecs.includes("eac3")) {
28783
28790
  elements.push(
28784
28791
  "\nThe @mediabunny/ac3 extension package provides support for encoding and decoding AC-3/E-AC-3."