@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.
Files changed (111) hide show
  1. package/dist/aac-codecprivate.d.ts +2 -9
  2. package/dist/aac-codecprivate.js +69 -34
  3. package/dist/add-avc-profile-to-track.js +4 -23
  4. package/dist/boxes/avc/codec-private.d.ts +2 -0
  5. package/dist/boxes/avc/codec-private.js +28 -0
  6. package/dist/boxes/avc/codec-string.d.ts +2 -0
  7. package/dist/boxes/avc/codec-string.js +7 -0
  8. package/dist/boxes/avc/color.d.ts +6 -0
  9. package/dist/boxes/avc/color.js +39 -0
  10. package/dist/boxes/avc/interpret-sps.d.ts +11 -0
  11. package/dist/boxes/avc/interpret-sps.js +44 -0
  12. package/dist/boxes/avc/key.d.ts +2 -0
  13. package/dist/boxes/avc/key.js +11 -0
  14. package/dist/boxes/avc/parse-avc.d.ts +36 -3
  15. package/dist/boxes/avc/parse-avc.js +161 -4
  16. package/dist/boxes/avc/sps-and-pps.d.ts +3 -0
  17. package/dist/boxes/avc/sps-and-pps.js +12 -0
  18. package/dist/boxes/iso-base-media/get-video-codec-from-iso-track.d.ts +2 -0
  19. package/dist/boxes/iso-base-media/get-video-codec-from-iso-track.js +55 -0
  20. package/dist/boxes/iso-base-media/make-track.js +2 -1
  21. package/dist/boxes/iso-base-media/mdat/mdat.js +8 -14
  22. package/dist/boxes/iso-base-media/process-box.js +1 -1
  23. package/dist/boxes/riff/parse-box.js +2 -2
  24. package/dist/boxes/riff/parse-movi.js +12 -14
  25. package/dist/boxes/transport-stream/adts-header.d.ts +7 -0
  26. package/dist/boxes/transport-stream/adts-header.js +56 -0
  27. package/dist/boxes/transport-stream/boxes.d.ts +41 -0
  28. package/dist/boxes/transport-stream/boxes.js +2 -0
  29. package/dist/boxes/transport-stream/discard-rest-of-packet.d.ts +3 -0
  30. package/dist/boxes/transport-stream/discard-rest-of-packet.js +13 -0
  31. package/dist/boxes/transport-stream/find-separator.d.ts +2 -0
  32. package/dist/boxes/transport-stream/find-separator.js +30 -0
  33. package/dist/boxes/transport-stream/get-tracks.d.ts +5 -0
  34. package/dist/boxes/transport-stream/get-tracks.js +33 -0
  35. package/dist/boxes/transport-stream/handle-aac-packet.d.ts +7 -0
  36. package/dist/boxes/transport-stream/handle-aac-packet.js +50 -0
  37. package/dist/boxes/transport-stream/handle-avc-packet.d.ts +8 -0
  38. package/dist/boxes/transport-stream/handle-avc-packet.js +60 -0
  39. package/dist/boxes/transport-stream/next-pes-header-store.d.ts +6 -0
  40. package/dist/boxes/transport-stream/next-pes-header-store.js +18 -0
  41. package/dist/boxes/transport-stream/parse-packet.d.ts +13 -0
  42. package/dist/boxes/transport-stream/parse-packet.js +80 -0
  43. package/dist/boxes/transport-stream/parse-pat.d.ts +8 -0
  44. package/dist/boxes/transport-stream/parse-pat.js +49 -0
  45. package/dist/boxes/transport-stream/parse-pes.d.ts +8 -0
  46. package/dist/boxes/transport-stream/parse-pes.js +76 -0
  47. package/dist/boxes/transport-stream/parse-pmt.d.ts +11 -0
  48. package/dist/boxes/transport-stream/parse-pmt.js +64 -0
  49. package/dist/boxes/transport-stream/parse-stream-packet.d.ts +15 -0
  50. package/dist/boxes/transport-stream/parse-stream-packet.js +107 -0
  51. package/dist/boxes/transport-stream/parse-transport-stream.d.ts +14 -0
  52. package/dist/boxes/transport-stream/parse-transport-stream.js +72 -0
  53. package/dist/boxes/transport-stream/process-stream-buffers.d.ts +19 -0
  54. package/dist/boxes/transport-stream/process-stream-buffers.js +42 -0
  55. package/dist/boxes/transport-stream/traversal.d.ts +6 -0
  56. package/dist/boxes/transport-stream/traversal.js +30 -0
  57. package/dist/boxes/webm/ebml.d.ts +1 -1
  58. package/dist/boxes/webm/parse-ebml.js +1 -1
  59. package/dist/buffer-iterator.d.ts +2 -0
  60. package/dist/buffer-iterator.js +25 -0
  61. package/dist/convert-audio-or-video-sample.d.ts +2 -0
  62. package/dist/convert-audio-or-video-sample.js +17 -0
  63. package/dist/create/iso-base-media/create-iso-base-media.js +38 -19
  64. package/dist/create/iso-base-media/trak/mdia/minf/create-stbl.js +7 -1
  65. package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stts.js +3 -0
  66. package/dist/create/media-fn.d.ts +0 -1
  67. package/dist/create/progress-tracker.d.ts +2 -0
  68. package/dist/create/progress-tracker.js +32 -8
  69. package/dist/emit-available-info.js +13 -2
  70. package/dist/esm/index.mjs +1325 -247
  71. package/dist/get-container.d.ts +1 -1
  72. package/dist/get-container.js +3 -0
  73. package/dist/get-duration.js +4 -1
  74. package/dist/get-fps.js +8 -2
  75. package/dist/get-location.d.ts +13 -0
  76. package/dist/get-location.js +40 -0
  77. package/dist/get-tracks.d.ts +4 -3
  78. package/dist/get-tracks.js +9 -2
  79. package/dist/get-video-codec.d.ts +1 -2
  80. package/dist/get-video-codec.js +9 -148
  81. package/dist/has-all-info.js +1 -1
  82. package/dist/index.d.ts +3 -0
  83. package/dist/metadata/get-metadata.js +3 -0
  84. package/dist/options.d.ts +11 -3
  85. package/dist/parse-media.js +3 -3
  86. package/dist/parse-result.d.ts +7 -2
  87. package/dist/parse-video.js +15 -0
  88. package/dist/register-track.d.ts +5 -5
  89. package/dist/register-track.js +16 -10
  90. package/dist/state/can-skip-tracks.js +1 -0
  91. package/dist/state/has-tracks-section.d.ts +3 -0
  92. package/dist/state/has-tracks-section.js +5 -0
  93. package/dist/state/parser-state.d.ts +2 -0
  94. package/dist/version.d.ts +1 -1
  95. package/dist/version.js +1 -1
  96. package/dist/webcodec-sample-types.d.ts +9 -2
  97. package/package.json +3 -3
  98. package/dist/add-new-matroska-tracks.d.ts +0 -13
  99. package/dist/add-new-matroska-tracks.js +0 -29
  100. package/dist/boxes/iso-base-media/meta/keys.d.ts +0 -10
  101. package/dist/boxes/iso-base-media/meta/keys.js +0 -17
  102. package/dist/boxes/iso-base-media/meta/list.d.ts +0 -12
  103. package/dist/boxes/iso-base-media/meta/list.js +0 -33
  104. package/dist/boxes/riff/strf.d.ts +0 -7
  105. package/dist/boxes/riff/strf.js +0 -67
  106. package/dist/create/mp3/create-mp3.d.ts +0 -2
  107. package/dist/create/mp3/create-mp3.js +0 -49
  108. package/dist/get-metadata.d.ts +0 -7
  109. package/dist/get-metadata.js +0 -63
  110. package/dist/parser-state.d.ts +0 -33
  111. package/dist/parser-state.js +0 -162
@@ -1,4 +1,4 @@
1
1
  import type { ParseMediaContainer } from './options';
2
2
  import type { Structure } from './parse-result';
3
- export declare const getContainer: (segments: Structure) => ParseMediaContainer | null;
3
+ export declare const getContainer: (segments: Structure) => ParseMediaContainer;
4
4
  export declare const hasContainer: (boxes: Structure) => boolean;
@@ -9,6 +9,9 @@ const getContainer = (segments) => {
9
9
  if (segments.type === 'matroska') {
10
10
  return 'webm';
11
11
  }
12
+ if (segments.type === 'transport-stream') {
13
+ return 'transport-stream';
14
+ }
12
15
  if (segments.type === 'riff') {
13
16
  if ((0, traversal_1.isRiffAvi)(segments)) {
14
17
  return 'avi';
@@ -89,7 +89,10 @@ const getDuration = (structure, parserState) => {
89
89
  if (structure.type === 'riff') {
90
90
  return getDurationFromAvi(structure);
91
91
  }
92
- throw new Error('Has no duration');
92
+ if (structure.type === 'transport-stream') {
93
+ return null;
94
+ }
95
+ throw new Error('Has no duration ' + structure);
93
96
  };
94
97
  exports.getDuration = getDuration;
95
98
  const hasDuration = (structure, parserState) => {
package/dist/get-fps.js CHANGED
@@ -93,21 +93,27 @@ const getFps = (segments) => {
93
93
  if (segments.type === 'riff') {
94
94
  return getFpsFromAvi(segments);
95
95
  }
96
- // TODO: Matroska doesn't have Matroska
96
+ // TODO: Matroska doesn't have fps
97
97
  if (segments.type === 'matroska') {
98
98
  return null;
99
99
  }
100
+ if (segments.type === 'transport-stream') {
101
+ return null;
102
+ }
100
103
  throw new Error('Cannot get fps, not implemented');
101
104
  };
102
105
  exports.getFps = getFps;
103
106
  const hasFps = (boxes) => {
104
107
  try {
105
- // Matroska has no FPS metadata
108
+ // Matroska and Transport stream has no FPS metadata
106
109
  // Not bothering to parse
107
110
  // Idea: `guaranteedFps` field
108
111
  if (boxes.type === 'matroska') {
109
112
  return true;
110
113
  }
114
+ if (boxes.type === 'transport-stream') {
115
+ return true;
116
+ }
111
117
  return (0, exports.getFps)(boxes) !== null;
112
118
  }
113
119
  catch (_a) {
@@ -0,0 +1,13 @@
1
+ import type { Structure } from './parse-result';
2
+ export type MediaParserLocation = {
3
+ latitude: number;
4
+ longitude: number;
5
+ altitude: number | null;
6
+ horizontalAccuracy: number | null;
7
+ };
8
+ export declare function parseLocation(locationString: string): {
9
+ latitude: number;
10
+ longitude: number;
11
+ altitude: number | null;
12
+ } | null;
13
+ export declare const getLocation: (structure: Structure) => MediaParserLocation | null;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLocation = void 0;
4
+ exports.parseLocation = parseLocation;
5
+ const get_metadata_1 = require("./metadata/get-metadata");
6
+ function parseLocation(locationString) {
7
+ const locationPattern = /^([+-]\d{2}\.?\d{0,10})([+-]\d{3}\.?\d{0,10})([+-]\d+(\.\d+)?)?\/$/;
8
+ const match = locationString.match(locationPattern);
9
+ if (!match) {
10
+ return null;
11
+ }
12
+ // Extract latitude, longitude, and altitude
13
+ const latitude = parseFloat(match[1]);
14
+ const longitude = parseFloat(match[2]);
15
+ const altitude = match[3] ? parseFloat(match[3]) : null;
16
+ return {
17
+ latitude,
18
+ longitude,
19
+ altitude,
20
+ };
21
+ }
22
+ const getLocation = (structure) => {
23
+ const metadata = (0, get_metadata_1.getMetadata)(structure);
24
+ const locationEntry = metadata.find((entry) => entry.key === 'com.apple.quicktime.location.ISO6709');
25
+ const horizontalAccuracy = metadata.find((entry) => entry.key === 'com.apple.quicktime.location.accuracy.horizontal');
26
+ if (locationEntry) {
27
+ const parsed = parseLocation(locationEntry.value);
28
+ if (parsed === null) {
29
+ return null;
30
+ }
31
+ return {
32
+ ...parsed,
33
+ horizontalAccuracy: (horizontalAccuracy === null || horizontalAccuracy === void 0 ? void 0 : horizontalAccuracy.value)
34
+ ? parseFloat(String(horizontalAccuracy.value))
35
+ : null,
36
+ };
37
+ }
38
+ return null;
39
+ };
40
+ exports.getLocation = getLocation;
@@ -1,3 +1,4 @@
1
+ import type { MatrixCoefficients, Primaries, TransferCharacteristics } from './boxes/avc/color';
1
2
  import type { MoovBox } from './boxes/iso-base-media/moov/moov';
2
3
  import type { TrakBox } from './boxes/iso-base-media/trak/trak';
3
4
  import type { AllTracks } from './boxes/riff/get-tracks-from-avi';
@@ -8,9 +9,9 @@ type SampleAspectRatio = {
8
9
  denominator: number;
9
10
  };
10
11
  export type VideoTrackColorParams = {
11
- transferCharacteristics: 'bt709' | 'smpte170m' | 'iec61966-2-1' | 'arib-std-b67' | null;
12
- matrixCoefficients: 'bt709' | 'bt470bg' | 'rgb' | 'smpte170m' | 'bt2020' | null;
13
- primaries: 'bt709' | 'smpte170m' | 'bt470bg' | 'bt2020' | null;
12
+ transferCharacteristics: TransferCharacteristics | null;
13
+ matrixCoefficients: MatrixCoefficients | null;
14
+ primaries: Primaries | null;
14
15
  fullRange: boolean | null;
15
16
  };
16
17
  export type MediaParserVideoCodec = 'vp8' | 'vp9' | 'h264' | 'av1' | 'h265' | 'prores';
@@ -4,6 +4,7 @@ exports.getTracks = exports.hasTracks = exports.getNumberOfTracks = void 0;
4
4
  const make_track_1 = require("./boxes/iso-base-media/make-track");
5
5
  const traversal_1 = require("./boxes/iso-base-media/traversal");
6
6
  const get_tracks_from_avi_1 = require("./boxes/riff/get-tracks-from-avi");
7
+ const get_tracks_1 = require("./boxes/transport-stream/get-tracks");
7
8
  const get_ready_tracks_1 = require("./boxes/webm/get-ready-tracks");
8
9
  const traversal_2 = require("./boxes/webm/traversal");
9
10
  const getNumberOfTracks = (moovBox) => {
@@ -34,7 +35,10 @@ const hasTracks = (structure, state) => {
34
35
  if (structure.type === 'riff') {
35
36
  return (0, get_tracks_from_avi_1.hasAllTracksFromAvi)(structure, state);
36
37
  }
37
- throw new Error('Unknown container');
38
+ if (structure.type === 'transport-stream') {
39
+ return (0, get_tracks_1.hasAllTracksFromTransportStream)(structure, state);
40
+ }
41
+ throw new Error('Unknown container ' + structure);
38
42
  };
39
43
  exports.hasTracks = hasTracks;
40
44
  const getTracksFromMa = (segments, state) => {
@@ -107,6 +111,9 @@ const getTracks = (segments, state) => {
107
111
  if (segments.type === 'riff') {
108
112
  return (0, get_tracks_from_avi_1.getTracksFromAvi)(segments, state);
109
113
  }
110
- throw new Error('Unknown container');
114
+ if (segments.type === 'transport-stream') {
115
+ return (0, get_tracks_1.getTracksFromTransportStream)(segments, state);
116
+ }
117
+ throw new Error(`Unknown container${segments}`);
111
118
  };
112
119
  exports.getTracks = getTracks;
@@ -2,8 +2,7 @@ import type { TrakBox } from './boxes/iso-base-media/trak/trak';
2
2
  import { type MediaParserVideoCodec, type VideoTrackColorParams } from './get-tracks';
3
3
  import type { Structure } from './parse-result';
4
4
  import type { ParserState } from './state/parser-state';
5
- export declare const getVideoCodecFromIsoTrak: (trakBox: TrakBox) => "h264" | "av1" | "h265" | "prores";
6
- export declare const getVideoCodec: (boxes: Structure) => MediaParserVideoCodec | null;
5
+ export declare const getVideoCodec: (boxes: Structure, state: ParserState) => MediaParserVideoCodec | null;
7
6
  export declare const hasVideoCodec: (boxes: Structure, state: ParserState) => boolean;
8
7
  export declare const getVideoPrivateData: (trakBox: TrakBox) => Uint8Array | null;
9
8
  export declare const getIsoBmColrConfig: (trakBox: TrakBox) => VideoTrackColorParams | null;
@@ -1,129 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getVideoCodecString = exports.getIsoBmColrConfig = exports.getVideoPrivateData = exports.hasVideoCodec = exports.getVideoCodec = exports.getVideoCodecFromIsoTrak = void 0;
4
- const traversal_1 = require("./boxes/iso-base-media/traversal");
5
- const traversal_2 = require("./boxes/riff/traversal");
3
+ exports.getVideoCodecString = exports.getIsoBmColrConfig = exports.getVideoPrivateData = exports.hasVideoCodec = exports.getVideoCodec = void 0;
4
+ const color_1 = require("./boxes/avc/color");
6
5
  const av1_codec_private_1 = require("./boxes/webm/av1-codec-private");
7
- const get_fps_1 = require("./get-fps");
8
6
  const get_sample_aspect_ratio_1 = require("./get-sample-aspect-ratio");
9
7
  const get_tracks_1 = require("./get-tracks");
10
- const getVideoCodecFromIsoTrak = (trakBox) => {
11
- const stsdBox = (0, traversal_1.getStsdBox)(trakBox);
12
- if (stsdBox && stsdBox.type === 'stsd-box') {
13
- const videoSample = stsdBox.samples.find((s) => s.type === 'video');
14
- if (videoSample && videoSample.type === 'video') {
15
- if (videoSample.format === 'hvc1') {
16
- return 'h265';
17
- }
18
- if (videoSample.format === 'avc1') {
19
- return 'h264';
20
- }
21
- if (videoSample.format === 'av01') {
22
- return 'av1';
23
- }
24
- // ap4h: ProRes 4444
25
- if (videoSample.format === 'ap4h') {
26
- return 'prores';
27
- }
28
- // ap4x: ap4x: ProRes 4444 XQ
29
- if (videoSample.format === 'ap4x') {
30
- return 'prores';
31
- }
32
- // apch: ProRes 422 High Quality
33
- if (videoSample.format === 'apch') {
34
- return 'prores';
35
- }
36
- // apcn: ProRes 422 Standard Definition
37
- if (videoSample.format === 'apcn') {
38
- return 'prores';
39
- }
40
- // apcs: ProRes 422 LT
41
- if (videoSample.format === 'apcs') {
42
- return 'prores';
43
- }
44
- // apco: ProRes 422 Proxy
45
- if (videoSample.format === 'apco') {
46
- return 'prores';
47
- }
48
- // aprh: ProRes RAW High Quality
49
- if (videoSample.format === 'aprh') {
50
- return 'prores';
51
- }
52
- // aprn: ProRes RAW Standard Definition
53
- if (videoSample.format === 'aprn') {
54
- return 'prores';
55
- }
56
- }
57
- }
58
- throw new Error('Could not find video codec');
59
- };
60
- exports.getVideoCodecFromIsoTrak = getVideoCodecFromIsoTrak;
61
- const getVideoCodecFromMatroska = (boxes) => {
62
- const mainSegment = boxes.find((b) => b.type === 'Segment');
63
- if (!mainSegment || mainSegment.type !== 'Segment') {
64
- return null;
65
- }
66
- const tracksSegment = mainSegment.value.find((b) => b.type === 'Tracks');
67
- if (!tracksSegment || tracksSegment.type !== 'Tracks') {
68
- return null;
69
- }
70
- for (const track of tracksSegment.value) {
71
- if (track.type === 'TrackEntry') {
72
- const trackType = track.value.find((b) => b.type === 'CodecID');
73
- if (trackType && trackType.type === 'CodecID') {
74
- if (trackType.value === 'V_VP8') {
75
- return 'vp8';
76
- }
77
- if (trackType.value === 'V_VP9') {
78
- return 'vp9';
79
- }
80
- if (trackType.value === 'V_AV1') {
81
- return 'av1';
82
- }
83
- if (trackType.value === 'V_MPEG4/ISO/AVC') {
84
- return 'h264';
85
- }
86
- if (trackType.value === 'V_MPEGH/ISO/HEVC') {
87
- return 'h265';
88
- }
89
- }
90
- }
91
- }
92
- throw new Error('Could not find video codec');
93
- };
94
- const getVideoCodecFromAvi = (structure) => {
95
- const strl = (0, traversal_2.getStrlBoxes)(structure);
96
- for (const s of strl) {
97
- const strh = (0, traversal_2.getStrhBox)(s.children);
98
- if (!strh) {
99
- throw new Error('No strh box');
100
- }
101
- if (strh.fccType === 'auds') {
102
- continue;
103
- }
104
- if (strh.handler === 'H264') {
105
- return 'h264';
106
- }
107
- }
108
- throw new Error('Unsupported codec');
109
- };
110
- const getVideoCodec = (boxes) => {
111
- if (boxes.type === 'iso-base-media') {
112
- const moovBox = (0, traversal_1.getMoovBox)(boxes.boxes);
113
- if (moovBox) {
114
- const trakBox = (0, traversal_1.getTraks)(moovBox).filter((t) => (0, get_fps_1.trakBoxContainsVideo)(t))[0];
115
- if (trakBox) {
116
- return (0, exports.getVideoCodecFromIsoTrak)(trakBox);
117
- }
118
- }
119
- }
120
- if (boxes.type === 'riff') {
121
- return getVideoCodecFromAvi(boxes);
122
- }
123
- if (boxes.type === 'matroska') {
124
- return getVideoCodecFromMatroska(boxes.boxes);
125
- }
126
- return null;
8
+ const getVideoCodec = (boxes, state) => {
9
+ var _a, _b;
10
+ const track = (0, get_tracks_1.getTracks)(boxes, state);
11
+ return (_b = (_a = track.videoTracks[0]) === null || _a === void 0 ? void 0 : _a.codecWithoutConfig) !== null && _b !== void 0 ? _b : null;
127
12
  };
128
13
  exports.getVideoCodec = getVideoCodec;
129
14
  const hasVideoCodec = (boxes, state) => {
@@ -166,33 +51,9 @@ const getIsoBmColrConfig = (trakBox) => {
166
51
  // https://github.com/bbc/qtff-parameter-editor
167
52
  return {
168
53
  fullRange: colrAtom.fullRangeFlag,
169
- matrixCoefficients: colrAtom.matrixIndex === 1
170
- ? 'bt709'
171
- : colrAtom.matrixIndex === 5
172
- ? 'bt470bg'
173
- : colrAtom.matrixIndex === 6
174
- ? 'smpte170m'
175
- : colrAtom.matrixIndex === 9
176
- ? 'bt2020'
177
- : null,
178
- primaries: colrAtom.primaries === 1
179
- ? 'bt709'
180
- : colrAtom.primaries === 5
181
- ? 'bt470bg'
182
- : colrAtom.primaries === 6
183
- ? 'smpte170m'
184
- : colrAtom.primaries === 9
185
- ? 'bt2020'
186
- : null,
187
- transferCharacteristics: colrAtom.transfer === 1
188
- ? 'bt709'
189
- : colrAtom.transfer === 6
190
- ? 'smpte170m'
191
- : colrAtom.transfer === 13
192
- ? 'iec61966-2-1'
193
- : colrAtom.transfer === 18
194
- ? 'arib-std-b67'
195
- : null,
54
+ matrixCoefficients: (0, color_1.getMatrixCoefficientsFromIndex)(colrAtom.matrixIndex),
55
+ primaries: (0, color_1.getPrimariesFromIndex)(colrAtom.primaries),
56
+ transferCharacteristics: (0, color_1.getTransferCharacteristicsFromIndex)(colrAtom.transfer),
196
57
  };
197
58
  };
198
59
  exports.getIsoBmColrConfig = getIsoBmColrConfig;
@@ -51,7 +51,7 @@ const getAvailableInfo = (options, structure, state) => {
51
51
  if (key === 'container') {
52
52
  return Boolean(structure && (0, get_container_1.hasContainer)(structure));
53
53
  }
54
- if (key === 'metadata') {
54
+ if (key === 'metadata' || key === 'location') {
55
55
  return false;
56
56
  }
57
57
  throw new Error(`Unknown key: ${key}`);
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export { parseMedia } from './parse-media';
9
9
  export { AudioOrVideoSample, OnAudioSample, OnAudioTrack, OnVideoSample, OnVideoTrack, } from './webcodec-sample-types';
10
10
  export type { MediaFn } from './create/media-fn';
11
11
  export { Dimensions } from './get-dimensions';
12
+ export { MediaParserLocation } from './get-location';
12
13
  export type { ReaderInterface } from './readers/reader';
13
14
  export declare const MediaParserInternals: {
14
15
  createMatroskaMedia: ({ writer, onBytesProgress, onMillisecondsProgress, filename, logLevel, progressTracker, }: import("./create/media-fn").MediaFnGeneratorInput) => Promise<import("./create/media-fn").MediaFn>;
@@ -27,6 +28,8 @@ export declare const MediaParserInternals: {
27
28
  getSmallestProgress: () => number;
28
29
  updateTrackProgress: (trackNumber: number, progress: number) => void;
29
30
  waitForProgress: () => Promise<void>;
31
+ getStartingTimestamp: () => number;
32
+ setPossibleLowestTimestamp: (timestamp: number) => void;
30
33
  };
31
34
  withResolvers: <T>() => {
32
35
  promise: Promise<T>;
@@ -11,6 +11,9 @@ const getMetadata = (structure) => {
11
11
  if (structure.type === 'riff') {
12
12
  return (0, metadata_from_riff_1.getMetadataFromRiff)(structure);
13
13
  }
14
+ if (structure.type === 'transport-stream') {
15
+ return [];
16
+ }
14
17
  return (0, metadata_from_iso_1.getMetadataFromIsoBase)(structure);
15
18
  };
16
19
  exports.getMetadata = getMetadata;
package/dist/options.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Dimensions } from './get-dimensions';
2
+ import type { MediaParserLocation } from './get-location';
2
3
  import type { AudioTrack, MediaParserAudioCodec, MediaParserVideoCodec, VideoTrack } from './get-tracks';
3
4
  import type { LogLevel } from './log';
4
5
  import type { MetadataEntry } from './metadata/get-metadata';
@@ -23,6 +24,7 @@ export type ParseMediaFields = {
23
24
  container: boolean;
24
25
  isHdr: boolean;
25
26
  metadata: boolean;
27
+ location: boolean;
26
28
  };
27
29
  export type AllParseMediaFields = {
28
30
  dimensions: true;
@@ -40,6 +42,7 @@ export type AllParseMediaFields = {
40
42
  container: true;
41
43
  isHdr: true;
42
44
  metadata: true;
45
+ location: true;
43
46
  };
44
47
  export type Options<Fields extends ParseMediaFields> = {
45
48
  dimensions?: Fields['dimensions'];
@@ -57,12 +60,13 @@ export type Options<Fields extends ParseMediaFields> = {
57
60
  container?: Fields['container'];
58
61
  isHdr?: Fields['isHdr'];
59
62
  metadata?: Fields['metadata'];
63
+ location?: Fields['location'];
60
64
  };
61
65
  export type TracksField = {
62
66
  videoTracks: VideoTrack[];
63
67
  audioTracks: AudioTrack[];
64
68
  };
65
- export type ParseMediaContainer = 'mp4' | 'webm' | 'avi';
69
+ export type ParseMediaContainer = 'mp4' | 'webm' | 'avi' | 'transport-stream';
66
70
  export type ParseMediaCallbacks<Fields extends Options<ParseMediaFields>> = (Fields['dimensions'] extends true ? {
67
71
  onDimensions?: (dimensions: Dimensions) => void;
68
72
  } : {}) & (Fields['durationInSeconds'] extends true ? {
@@ -81,6 +85,8 @@ export type ParseMediaCallbacks<Fields extends Options<ParseMediaFields>> = (Fie
81
85
  onRotation?: (rotation: number | null) => void;
82
86
  } : {}) & (Fields['metadata'] extends true ? {
83
87
  onMetadata?: (metadata: MetadataEntry[]) => void;
88
+ } : {}) & (Fields['location'] extends true ? {
89
+ onLocation?: (location: MediaParserLocation | null) => void;
84
90
  } : {}) & (Fields['unrotatedDimensions'] extends true ? {
85
91
  onUnrotatedDimensions?: (dimensions: Dimensions) => void;
86
92
  } : {}) & (Fields['isHdr'] extends true ? {
@@ -90,7 +96,7 @@ export type ParseMediaCallbacks<Fields extends Options<ParseMediaFields>> = (Fie
90
96
  } : {}) & (Fields['name'] extends true ? {
91
97
  onName?: (name: string) => void;
92
98
  } : {}) & (Fields['container'] extends true ? {
93
- onContainer?: (container: ParseMediaContainer | null) => void;
99
+ onContainer?: (container: ParseMediaContainer) => void;
94
100
  } : {});
95
101
  export type ParseMediaResult<Fields extends Options<ParseMediaFields>> = (Fields['dimensions'] extends true ? {
96
102
  dimensions: Dimensions;
@@ -118,8 +124,10 @@ export type ParseMediaResult<Fields extends Options<ParseMediaFields>> = (Fields
118
124
  name: string;
119
125
  } : {}) & (Fields['metadata'] extends true ? {
120
126
  metadata: MetadataEntry[];
127
+ } : {}) & (Fields['location'] extends true ? {
128
+ location: MediaParserLocation | null;
121
129
  } : {}) & (Fields['container'] extends true ? {
122
- container: ParseMediaContainer | null;
130
+ container: ParseMediaContainer;
123
131
  } : {});
124
132
  export type ParseMediaDynamicOptions<F extends Options<ParseMediaFields>> = {
125
133
  fields?: F;
@@ -51,10 +51,10 @@ const parseMedia = async ({ src, fields, reader: readerInterface = from_fetch_1.
51
51
  };
52
52
  triggerInfoEmit();
53
53
  while (parseResult === null || parseResult.status === 'incomplete') {
54
- if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
55
- throw new Error('Aborted');
56
- }
57
54
  while (true) {
55
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
56
+ throw new Error('Aborted');
57
+ }
58
58
  const result = await currentReader.reader.read();
59
59
  if (iterator) {
60
60
  if (!result.done) {
@@ -28,6 +28,7 @@ import type { TrakBox } from './boxes/iso-base-media/trak/trak';
28
28
  import type { TrunBox } from './boxes/iso-base-media/trun';
29
29
  import type { VoidBox } from './boxes/iso-base-media/void-box';
30
30
  import type { RiffBox } from './boxes/riff/riff-box';
31
+ import type { TransportStreamBox } from './boxes/transport-stream/boxes';
31
32
  import type { MatroskaSegment } from './boxes/webm/segments';
32
33
  export interface RegularBox extends BaseBox {
33
34
  boxType: string;
@@ -37,7 +38,7 @@ export interface RegularBox extends BaseBox {
37
38
  type: 'regular-box';
38
39
  }
39
40
  export type IsoBaseMediaBox = RegularBox | FtypBox | MvhdBox | TkhdBox | StsdBox | MebxBox | KeysBox | MoovBox | TrakBox | SttsBox | MdhdBox | IlstBox | EsdsBox | MdatBox | StszBox | StcoBox | StscBox | AvccBox | HvccBox | VoidBox | StssBox | PaspBox | CttsBox | Av1CBox | TrunBox | HdlrBox | ColorParameterBox | TfdtBox | TfhdBox;
40
- export type AnySegment = MatroskaSegment | IsoBaseMediaBox | RiffBox;
41
+ export type AnySegment = MatroskaSegment | IsoBaseMediaBox | RiffBox | TransportStreamBox;
41
42
  export type IsoBaseMediaStructure = {
42
43
  type: 'iso-base-media';
43
44
  boxes: IsoBaseMediaBox[];
@@ -50,7 +51,11 @@ export type MatroskaStructure = {
50
51
  type: 'matroska';
51
52
  boxes: MatroskaSegment[];
52
53
  };
53
- export type Structure = IsoBaseMediaStructure | RiffStructure | MatroskaStructure;
54
+ export type TransportStreamStructure = {
55
+ type: 'transport-stream';
56
+ boxes: TransportStreamBox[];
57
+ };
58
+ export type Structure = IsoBaseMediaStructure | RiffStructure | MatroskaStructure | TransportStreamStructure;
54
59
  export type ParseResult<TStructure extends Structure> = {
55
60
  status: 'done';
56
61
  segments: TStructure;
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseVideo = void 0;
4
4
  const process_box_1 = require("./boxes/iso-base-media/process-box");
5
5
  const parse_box_1 = require("./boxes/riff/parse-box");
6
+ const next_pes_header_store_1 = require("./boxes/transport-stream/next-pes-header-store");
7
+ const parse_transport_stream_1 = require("./boxes/transport-stream/parse-transport-stream");
6
8
  const parse_webm_header_1 = require("./boxes/webm/parse-webm-header");
7
9
  const log_1 = require("./log");
8
10
  const parseVideo = ({ iterator, options, signal, logLevel, fields, }) => {
@@ -31,6 +33,19 @@ const parseVideo = ({ iterator, options, signal, logLevel, fields, }) => {
31
33
  log_1.Log.verbose(logLevel, 'Detected Matroska container');
32
34
  return (0, parse_webm_header_1.parseWebm)({ counter: iterator, parserContext: options, fields });
33
35
  }
36
+ if (iterator.isTransportStream()) {
37
+ return (0, parse_transport_stream_1.parseTransportStream)({
38
+ iterator,
39
+ parserContext: options,
40
+ structure: {
41
+ type: 'transport-stream',
42
+ boxes: [],
43
+ },
44
+ streamBuffers: new Map(),
45
+ fields,
46
+ nextPesHeaderStore: (0, next_pes_header_store_1.makeNextPesHeaderStore)(),
47
+ });
48
+ }
34
49
  if (iterator.isMp3()) {
35
50
  return Promise.reject(new Error('MP3 files are not yet supported'));
36
51
  }
@@ -1,13 +1,13 @@
1
1
  import type { Track, VideoTrack } from './get-tracks';
2
+ import type { ParseMediaContainer } from './options';
2
3
  import type { ParserContext } from './parser-context';
3
- import type { ParserState } from './state/parser-state';
4
- export declare const registerTrack: ({ state, options, track, }: {
5
- state: ParserState;
4
+ export declare const registerTrack: ({ options, track, container, }: {
6
5
  options: ParserContext;
7
6
  track: Track;
7
+ container: ParseMediaContainer;
8
8
  }) => Promise<void>;
9
- export declare const registerVideoTrackWhenProfileIsAvailable: ({ options, state, track, }: {
10
- state: ParserState;
9
+ export declare const registerVideoTrackWhenProfileIsAvailable: ({ options, track, container, }: {
11
10
  options: ParserContext;
12
11
  track: VideoTrack;
12
+ container: ParseMediaContainer;
13
13
  }) => void;
@@ -2,23 +2,29 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.registerVideoTrackWhenProfileIsAvailable = exports.registerTrack = void 0;
4
4
  const add_avc_profile_to_track_1 = require("./add-avc-profile-to-track");
5
- const registerTrack = async ({ state, options, track, }) => {
6
- if (track.type === 'video' && options.onVideoTrack) {
7
- const callback = await options.onVideoTrack(track);
8
- await state.registerVideoSampleCallback(track.trackId, callback !== null && callback !== void 0 ? callback : null);
5
+ const registerTrack = async ({ options, track, container, }) => {
6
+ if (track.type === 'video') {
7
+ options.parserState.tracks.addTrack(track);
8
+ if (options.onVideoTrack) {
9
+ const callback = await options.onVideoTrack({ track, container });
10
+ await options.parserState.registerVideoSampleCallback(track.trackId, callback !== null && callback !== void 0 ? callback : null);
11
+ }
9
12
  }
10
- if (track.type === 'audio' && options.onAudioTrack) {
11
- const callback = await options.onAudioTrack(track);
12
- await state.registerAudioSampleCallback(track.trackId, callback !== null && callback !== void 0 ? callback : null);
13
+ if (track.type === 'audio') {
14
+ options.parserState.tracks.addTrack(track);
15
+ if (options.onAudioTrack) {
16
+ const callback = await options.onAudioTrack({ track, container });
17
+ await options.parserState.registerAudioSampleCallback(track.trackId, callback !== null && callback !== void 0 ? callback : null);
18
+ }
13
19
  }
14
20
  };
15
21
  exports.registerTrack = registerTrack;
16
- const registerVideoTrackWhenProfileIsAvailable = ({ options, state, track, }) => {
17
- state.registerOnAvcProfileCallback(async (profile) => {
22
+ const registerVideoTrackWhenProfileIsAvailable = ({ options, track, container, }) => {
23
+ options.parserState.registerOnAvcProfileCallback(async (profile) => {
18
24
  await (0, exports.registerTrack)({
19
25
  options,
20
- state,
21
26
  track: (0, add_avc_profile_to_track_1.addAvcProfileToTrack)(track, profile),
27
+ container,
22
28
  });
23
29
  });
24
30
  };
@@ -17,6 +17,7 @@ const needsTracksField = {
17
17
  unrotatedDimensions: true,
18
18
  videoCodec: true,
19
19
  metadata: true,
20
+ location: true,
20
21
  };
21
22
  const makeCanSkipTracksState = ({ hasAudioTrackHandlers, fields, hasVideoTrackHandlers, }) => {
22
23
  return {
@@ -1,6 +1,9 @@
1
+ import type { Track } from '../get-tracks';
1
2
  import type { CanSkipTracksState } from './can-skip-tracks';
2
3
  export declare const makeTracksSectionState: (canSkipTracksState: CanSkipTracksState) => {
3
4
  hasAllTracks: () => boolean;
4
5
  setIsDone: () => void;
6
+ addTrack: (track: Track) => void;
7
+ getTracks: () => Track[];
5
8
  ensureHasTracksAtEnd: () => void;
6
9
  };
@@ -2,12 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeTracksSectionState = void 0;
4
4
  const makeTracksSectionState = (canSkipTracksState) => {
5
+ const tracks = [];
5
6
  let doneWithTracks = false;
6
7
  return {
7
8
  hasAllTracks: () => doneWithTracks,
8
9
  setIsDone: () => {
9
10
  doneWithTracks = true;
10
11
  },
12
+ addTrack: (track) => {
13
+ tracks.push(track);
14
+ },
15
+ getTracks: () => tracks,
11
16
  ensureHasTracksAtEnd: () => {
12
17
  if (canSkipTracksState.canSkipTracks()) {
13
18
  return;
@@ -41,6 +41,8 @@ export declare const makeParserState: ({ hasAudioTrackHandlers, hasVideoTrackHan
41
41
  tracks: {
42
42
  hasAllTracks: () => boolean;
43
43
  setIsDone: () => void;
44
+ addTrack: (track: import("..").Track) => void;
45
+ getTracks: () => import("..").Track[];
44
46
  ensureHasTracksAtEnd: () => void;
45
47
  };
46
48
  canSkipTracksState: {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "4.0.237";
1
+ export declare const VERSION = "4.0.240";
package/dist/version.js CHANGED
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // Automatically generated on publish
5
- exports.VERSION = '4.0.237';
5
+ exports.VERSION = '4.0.240';