@remotion/media-parser 4.0.237 → 4.0.239

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 (106) 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/parse-ebml.js +1 -1
  58. package/dist/buffer-iterator.d.ts +2 -0
  59. package/dist/buffer-iterator.js +25 -0
  60. package/dist/convert-audio-or-video-sample.d.ts +2 -0
  61. package/dist/convert-audio-or-video-sample.js +17 -0
  62. package/dist/create/iso-base-media/create-iso-base-media.js +38 -19
  63. package/dist/create/iso-base-media/trak/mdia/minf/create-stbl.js +7 -1
  64. package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stts.js +3 -0
  65. package/dist/create/media-fn.d.ts +0 -1
  66. package/dist/create/progress-tracker.d.ts +2 -0
  67. package/dist/create/progress-tracker.js +32 -8
  68. package/dist/emit-available-info.js +1 -1
  69. package/dist/esm/index.mjs +1288 -252
  70. package/dist/get-container.d.ts +1 -1
  71. package/dist/get-container.js +3 -0
  72. package/dist/get-duration.js +4 -1
  73. package/dist/get-fps.js +8 -2
  74. package/dist/get-tracks.d.ts +4 -3
  75. package/dist/get-tracks.js +9 -2
  76. package/dist/get-video-codec.d.ts +1 -2
  77. package/dist/get-video-codec.js +9 -148
  78. package/dist/index.d.ts +2 -0
  79. package/dist/metadata/get-metadata.js +3 -0
  80. package/dist/options.d.ts +3 -3
  81. package/dist/parse-media.js +3 -3
  82. package/dist/parse-result.d.ts +7 -2
  83. package/dist/parse-video.js +15 -0
  84. package/dist/register-track.d.ts +5 -5
  85. package/dist/register-track.js +16 -10
  86. package/dist/state/has-tracks-section.d.ts +3 -0
  87. package/dist/state/has-tracks-section.js +5 -0
  88. package/dist/state/parser-state.d.ts +2 -0
  89. package/dist/version.d.ts +1 -1
  90. package/dist/version.js +1 -1
  91. package/dist/webcodec-sample-types.d.ts +9 -2
  92. package/package.json +3 -3
  93. package/dist/add-new-matroska-tracks.d.ts +0 -13
  94. package/dist/add-new-matroska-tracks.js +0 -29
  95. package/dist/boxes/iso-base-media/meta/keys.d.ts +0 -10
  96. package/dist/boxes/iso-base-media/meta/keys.js +0 -17
  97. package/dist/boxes/iso-base-media/meta/list.d.ts +0 -12
  98. package/dist/boxes/iso-base-media/meta/list.js +0 -33
  99. package/dist/boxes/riff/strf.d.ts +0 -7
  100. package/dist/boxes/riff/strf.js +0 -67
  101. package/dist/create/mp3/create-mp3.d.ts +0 -2
  102. package/dist/create/mp3/create-mp3.js +0 -49
  103. package/dist/get-metadata.d.ts +0 -7
  104. package/dist/get-metadata.js +0 -63
  105. package/dist/parser-state.d.ts +0 -33
  106. 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) {
@@ -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;
package/dist/index.d.ts CHANGED
@@ -27,6 +27,8 @@ export declare const MediaParserInternals: {
27
27
  getSmallestProgress: () => number;
28
28
  updateTrackProgress: (trackNumber: number, progress: number) => void;
29
29
  waitForProgress: () => Promise<void>;
30
+ getStartingTimestamp: () => number;
31
+ setPossibleLowestTimestamp: (timestamp: number) => void;
30
32
  };
31
33
  withResolvers: <T>() => {
32
34
  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
@@ -62,7 +62,7 @@ export type TracksField = {
62
62
  videoTracks: VideoTrack[];
63
63
  audioTracks: AudioTrack[];
64
64
  };
65
- export type ParseMediaContainer = 'mp4' | 'webm' | 'avi';
65
+ export type ParseMediaContainer = 'mp4' | 'webm' | 'avi' | 'transport-stream';
66
66
  export type ParseMediaCallbacks<Fields extends Options<ParseMediaFields>> = (Fields['dimensions'] extends true ? {
67
67
  onDimensions?: (dimensions: Dimensions) => void;
68
68
  } : {}) & (Fields['durationInSeconds'] extends true ? {
@@ -90,7 +90,7 @@ export type ParseMediaCallbacks<Fields extends Options<ParseMediaFields>> = (Fie
90
90
  } : {}) & (Fields['name'] extends true ? {
91
91
  onName?: (name: string) => void;
92
92
  } : {}) & (Fields['container'] extends true ? {
93
- onContainer?: (container: ParseMediaContainer | null) => void;
93
+ onContainer?: (container: ParseMediaContainer) => void;
94
94
  } : {});
95
95
  export type ParseMediaResult<Fields extends Options<ParseMediaFields>> = (Fields['dimensions'] extends true ? {
96
96
  dimensions: Dimensions;
@@ -119,7 +119,7 @@ export type ParseMediaResult<Fields extends Options<ParseMediaFields>> = (Fields
119
119
  } : {}) & (Fields['metadata'] extends true ? {
120
120
  metadata: MetadataEntry[];
121
121
  } : {}) & (Fields['container'] extends true ? {
122
- container: ParseMediaContainer | null;
122
+ container: ParseMediaContainer;
123
123
  } : {});
124
124
  export type ParseMediaDynamicOptions<F extends Options<ParseMediaFields>> = {
125
125
  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
  };
@@ -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.239";
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.239';
@@ -1,8 +1,15 @@
1
1
  import type { AudioTrack, VideoTrack } from './get-tracks';
2
+ import type { ParseMediaContainer } from './options';
2
3
  export type OnAudioSample = (sample: AudioOrVideoSample) => void | Promise<void>;
3
4
  export type OnVideoSample = (sample: AudioOrVideoSample) => void | Promise<void>;
4
- export type OnAudioTrack = (track: AudioTrack) => OnAudioSample | Promise<OnAudioSample | null> | null;
5
- export type OnVideoTrack = (track: VideoTrack) => OnVideoSample | Promise<OnVideoSample | null> | null;
5
+ export type OnAudioTrack = (options: {
6
+ track: AudioTrack;
7
+ container: ParseMediaContainer;
8
+ }) => OnAudioSample | Promise<OnAudioSample | null> | null;
9
+ export type OnVideoTrack = (options: {
10
+ track: VideoTrack;
11
+ container: ParseMediaContainer;
12
+ }) => OnVideoSample | Promise<OnVideoSample | null> | null;
6
13
  export type AudioOrVideoSample = {
7
14
  data: Uint8Array;
8
15
  timestamp: number;
package/package.json CHANGED
@@ -3,14 +3,14 @@
3
3
  "url": "https://github.com/remotion-dev/remotion/tree/main/packages/media-parser"
4
4
  },
5
5
  "name": "@remotion/media-parser",
6
- "version": "4.0.237",
6
+ "version": "4.0.239",
7
7
  "main": "dist/index.js",
8
8
  "sideEffects": false,
9
9
  "devDependencies": {
10
10
  "@types/wicg-file-system-access": "2023.10.5",
11
11
  "eslint": "9.14.0",
12
- "@remotion/example-videos": "4.0.237",
13
- "@remotion/eslint-config-internal": "4.0.237"
12
+ "@remotion/example-videos": "4.0.239",
13
+ "@remotion/eslint-config-internal": "4.0.239"
14
14
  },
15
15
  "publishConfig": {
16
16
  "access": "public"
@@ -1,13 +0,0 @@
1
- import type { Track, VideoTrack } from './get-tracks';
2
- import type { ParserContext } from './parser-context';
3
- import type { ParserState } from './parser-state';
4
- export declare const registerTrack: ({ state, options, track, }: {
5
- state: ParserState;
6
- options: ParserContext;
7
- track: Track;
8
- }) => Promise<void>;
9
- export declare const registerVideoTrackWhenProfileIsAvailable: ({ options, state, track, }: {
10
- state: ParserState;
11
- options: ParserContext;
12
- track: VideoTrack;
13
- }) => void;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerVideoTrackWhenProfileIsAvailable = exports.registerTrack = void 0;
4
- const registerTrack = async ({ state, options, track, }) => {
5
- if (track.type === 'video' && options.onVideoTrack) {
6
- const callback = await options.onVideoTrack(track);
7
- await state.registerVideoSampleCallback(track.trackId, callback !== null && callback !== void 0 ? callback : null);
8
- }
9
- if (track.type === 'audio' && options.onAudioTrack) {
10
- const callback = await options.onAudioTrack(track);
11
- await state.registerAudioSampleCallback(track.trackId, callback !== null && callback !== void 0 ? callback : null);
12
- }
13
- };
14
- exports.registerTrack = registerTrack;
15
- const registerVideoTrackWhenProfileIsAvailable = ({ options, state, track, }) => {
16
- state.registerOnAvcProfileCallback(async (profile) => {
17
- const newTrack = {
18
- ...track,
19
- codec: 'avc1...',
20
- };
21
- console.log(profile, newTrack);
22
- await (0, exports.registerTrack)({
23
- options,
24
- state,
25
- track: newTrack,
26
- });
27
- });
28
- };
29
- exports.registerVideoTrackWhenProfileIsAvailable = registerVideoTrackWhenProfileIsAvailable;
@@ -1,10 +0,0 @@
1
- import type { BufferIterator } from '../../../buffer-iterator';
2
- import type { BaseBox } from '../base-type';
3
- export interface KeysBox extends BaseBox {
4
- type: 'keys-box';
5
- }
6
- export declare const parseKeys: ({ iterator, size, offset, }: {
7
- iterator: BufferIterator;
8
- size: number;
9
- offset: number;
10
- }) => Promise<KeysBox>;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseKeys = void 0;
4
- const parseKeys = ({ iterator, size, offset, }) => {
5
- const box = iterator.startBox(size - 8);
6
- const version = iterator.getUint8();
7
- if (version !== 0) {
8
- throw new Error(`Unsupported hdlr version: ${version}`);
9
- }
10
- box.discardRest();
11
- return Promise.resolve({
12
- type: 'keys-box',
13
- boxSize: size,
14
- offset,
15
- });
16
- };
17
- exports.parseKeys = parseKeys;