@remotion/media-parser 4.0.231 → 4.0.232

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 (95) hide show
  1. package/dist/add-avc-profile-to-track.d.ts +3 -0
  2. package/dist/add-avc-profile-to-track.js +35 -0
  3. package/dist/add-new-matroska-tracks.d.ts +6 -1
  4. package/dist/add-new-matroska-tracks.js +16 -1
  5. package/dist/boxes/avc/parse-avc.d.ts +18 -0
  6. package/dist/boxes/avc/parse-avc.js +96 -0
  7. package/dist/boxes/iso-base-media/make-track.js +3 -3
  8. package/dist/boxes/iso-base-media/mdat/mdat.d.ts +2 -2
  9. package/dist/boxes/iso-base-media/mdat/mdat.js +5 -2
  10. package/dist/boxes/iso-base-media/moov/moov.js +2 -2
  11. package/dist/boxes/iso-base-media/process-box.d.ts +5 -5
  12. package/dist/boxes/iso-base-media/process-box.js +38 -37
  13. package/dist/boxes/iso-base-media/stsd/mebx.js +2 -2
  14. package/dist/boxes/iso-base-media/stsd/samples.d.ts +2 -2
  15. package/dist/boxes/iso-base-media/stsd/samples.js +9 -9
  16. package/dist/boxes/iso-base-media/trak/trak.js +2 -2
  17. package/dist/boxes/iso-base-media/traversal.d.ts +1 -1
  18. package/dist/boxes/riff/expect-riff-box.d.ts +16 -0
  19. package/dist/boxes/riff/expect-riff-box.js +49 -0
  20. package/dist/boxes/riff/get-tracks-from-avi.d.ts +21 -0
  21. package/dist/boxes/riff/get-tracks-from-avi.js +108 -0
  22. package/dist/boxes/riff/is-movi.d.ts +2 -0
  23. package/dist/boxes/riff/is-movi.js +12 -0
  24. package/dist/boxes/riff/parse-avih.d.ts +6 -0
  25. package/dist/boxes/riff/parse-avih.js +32 -0
  26. package/dist/boxes/riff/parse-box.d.ts +13 -0
  27. package/dist/boxes/riff/parse-box.js +113 -0
  28. package/dist/boxes/riff/parse-fmt-box.d.ts +7 -0
  29. package/dist/boxes/riff/parse-fmt-box.js +33 -0
  30. package/dist/boxes/riff/parse-list-box.d.ts +8 -0
  31. package/dist/boxes/riff/parse-list-box.js +30 -0
  32. package/dist/boxes/riff/parse-movi.d.ts +17 -0
  33. package/dist/boxes/riff/parse-movi.js +122 -0
  34. package/dist/boxes/riff/parse-riff-box.d.ts +10 -0
  35. package/dist/boxes/riff/parse-riff-box.js +33 -0
  36. package/dist/boxes/riff/parse-strf.d.ts +7 -0
  37. package/dist/boxes/riff/parse-strf.js +67 -0
  38. package/dist/boxes/riff/parse-strh.d.ts +6 -0
  39. package/dist/boxes/riff/parse-strh.js +46 -0
  40. package/dist/boxes/riff/riff-box.d.ts +81 -0
  41. package/dist/boxes/riff/riff-box.js +2 -0
  42. package/dist/boxes/riff/strf.d.ts +7 -0
  43. package/dist/boxes/riff/strf.js +67 -0
  44. package/dist/boxes/riff/timescale.d.ts +1 -0
  45. package/dist/boxes/riff/timescale.js +4 -0
  46. package/dist/boxes/riff/traversal.d.ts +8 -0
  47. package/dist/boxes/riff/traversal.js +36 -0
  48. package/dist/boxes/webm/parse-ebml.js +2 -2
  49. package/dist/boxes/webm/parse-webm-header.d.ts +2 -2
  50. package/dist/boxes/webm/parse-webm-header.js +7 -7
  51. package/dist/boxes/webm/traversal.d.ts +2 -2
  52. package/dist/buffer-iterator.d.ts +6 -1
  53. package/dist/buffer-iterator.js +24 -5
  54. package/dist/create/iso-base-media/create-iso-base-media.js +0 -4
  55. package/dist/create/matroska/create-matroska-media.js +0 -4
  56. package/dist/create/media-fn.d.ts +0 -1
  57. package/dist/create/mp3/create-mp3.d.ts +2 -0
  58. package/dist/create/mp3/create-mp3.js +49 -0
  59. package/dist/create/wav/create-wav.d.ts +2 -0
  60. package/dist/create/wav/create-wav.js +108 -0
  61. package/dist/emit-available-info.d.ts +2 -2
  62. package/dist/emit-available-info.js +6 -4
  63. package/dist/esm/from-node.mjs +2 -1
  64. package/dist/esm/index.mjs +1487 -431
  65. package/dist/get-audio-codec.d.ts +3 -3
  66. package/dist/get-audio-codec.js +2 -2
  67. package/dist/get-container.d.ts +3 -3
  68. package/dist/get-container.js +9 -7
  69. package/dist/get-dimensions.d.ts +3 -3
  70. package/dist/get-duration.d.ts +3 -3
  71. package/dist/get-duration.js +32 -14
  72. package/dist/get-fps.d.ts +3 -3
  73. package/dist/get-fps.js +31 -4
  74. package/dist/get-tracks.d.ts +4 -7
  75. package/dist/get-tracks.js +55 -27
  76. package/dist/get-video-codec.d.ts +5 -4
  77. package/dist/get-video-codec.js +38 -10
  78. package/dist/has-all-info.d.ts +2 -2
  79. package/dist/has-all-info.js +4 -4
  80. package/dist/index.d.ts +1 -0
  81. package/dist/index.js +2 -0
  82. package/dist/options.d.ts +9 -9
  83. package/dist/parse-media.js +2 -0
  84. package/dist/parse-result.d.ts +20 -6
  85. package/dist/parse-video.d.ts +2 -2
  86. package/dist/parse-video.js +5 -16
  87. package/dist/parser-context.d.ts +1 -0
  88. package/dist/parser-state.d.ts +11 -0
  89. package/dist/parser-state.js +30 -0
  90. package/dist/readers/from-node.js +2 -1
  91. package/dist/register-track.d.ts +13 -0
  92. package/dist/register-track.js +25 -0
  93. package/dist/version.d.ts +1 -1
  94. package/dist/version.js +1 -1
  95. package/package.json +3 -3
@@ -25,24 +25,38 @@ import type { TkhdBox } from './boxes/iso-base-media/tkhd';
25
25
  import type { TrakBox } from './boxes/iso-base-media/trak/trak';
26
26
  import type { TrunBox } from './boxes/iso-base-media/trun';
27
27
  import type { VoidBox } from './boxes/iso-base-media/void-box';
28
+ import type { RiffBox } from './boxes/riff/riff-box';
28
29
  import type { MatroskaSegment } from './boxes/webm/segments';
29
30
  export interface RegularBox extends BaseBox {
30
31
  boxType: string;
31
32
  boxSize: number;
32
- children: AnySegment[];
33
+ children: IsoBaseMediaBox[];
33
34
  offset: number;
34
35
  type: 'regular-box';
35
36
  }
36
37
  export type IsoBaseMediaBox = RegularBox | FtypBox | MvhdBox | TkhdBox | StsdBox | MebxBox | KeysBox | MoovBox | TrakBox | SttsBox | MdhdBox | EsdsBox | MdatBox | StszBox | StcoBox | StscBox | AvccBox | HvccBox | VoidBox | StssBox | PaspBox | CttsBox | Av1CBox | TrunBox | ColorParameterBox | TfdtBox | TfhdBox;
37
- export type AnySegment = MatroskaSegment | IsoBaseMediaBox;
38
- export type ParseResult = {
38
+ export type AnySegment = MatroskaSegment | IsoBaseMediaBox | RiffBox;
39
+ export type IsoBaseMediaStructure = {
40
+ type: 'iso-base-media';
41
+ boxes: IsoBaseMediaBox[];
42
+ };
43
+ export type RiffStructure = {
44
+ type: 'riff';
45
+ boxes: RiffBox[];
46
+ };
47
+ export type MatroskaStructure = {
48
+ type: 'matroska';
49
+ boxes: MatroskaSegment[];
50
+ };
51
+ export type Structure = IsoBaseMediaStructure | RiffStructure | MatroskaStructure;
52
+ export type ParseResult<TStructure extends Structure> = {
39
53
  status: 'done';
40
- segments: AnySegment[];
54
+ segments: TStructure;
41
55
  } | {
42
56
  status: 'incomplete';
43
- segments: AnySegment[];
57
+ segments: TStructure;
44
58
  skipTo: number | null;
45
- continueParsing: () => Promise<ParseResult>;
59
+ continueParsing: () => Promise<ParseResult<TStructure>>;
46
60
  };
47
61
  export type MatroskaParseResult = {
48
62
  status: 'done';
@@ -1,6 +1,6 @@
1
1
  import type { BufferIterator } from './buffer-iterator';
2
2
  import { type LogLevel } from './log';
3
- import type { IsoBaseMediaBox, ParseResult } from './parse-result';
3
+ import type { IsoBaseMediaBox, ParseResult, Structure } from './parse-result';
4
4
  import type { ParserContext } from './parser-context';
5
5
  export type PartialMdatBox = {
6
6
  type: 'partial-mdat-box';
@@ -20,4 +20,4 @@ export declare const parseVideo: ({ iterator, options, signal, logLevel, }: {
20
20
  options: ParserContext;
21
21
  signal: AbortSignal | null;
22
22
  logLevel: LogLevel;
23
- }) => Promise<ParseResult>;
23
+ }) => Promise<ParseResult<Structure>>;
@@ -2,30 +2,19 @@
2
2
  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
+ const parse_box_1 = require("./boxes/riff/parse-box");
5
6
  const parse_webm_header_1 = require("./boxes/webm/parse-webm-header");
6
7
  const log_1 = require("./log");
7
8
  const parseVideo = ({ iterator, options, signal, logLevel, }) => {
8
9
  if (iterator.bytesRemaining() === 0) {
9
- return Promise.resolve({
10
- status: 'incomplete',
11
- segments: [],
12
- continueParsing: () => {
13
- return (0, exports.parseVideo)({
14
- iterator,
15
- options,
16
- signal,
17
- logLevel,
18
- });
19
- },
20
- skipTo: null,
21
- });
10
+ return Promise.reject(new Error('no bytes'));
22
11
  }
23
12
  if (iterator.isRiff()) {
24
- throw new Error('AVI files are not yet supported');
13
+ return Promise.resolve((0, parse_box_1.parseRiff)({ iterator, options }));
25
14
  }
26
15
  if (iterator.isIsoBaseMedia()) {
27
16
  log_1.Log.verbose(logLevel, 'Detected ISO Base Media container');
28
- return (0, process_box_1.parseBoxes)({
17
+ return (0, process_box_1.parseIsoBaseMediaBoxes)({
29
18
  iterator,
30
19
  maxBytes: Infinity,
31
20
  allowIncompleteBoxes: true,
@@ -38,7 +27,7 @@ const parseVideo = ({ iterator, options, signal, logLevel, }) => {
38
27
  }
39
28
  if (iterator.isWebm()) {
40
29
  log_1.Log.verbose(logLevel, 'Detected Matroska container');
41
- return Promise.resolve((0, parse_webm_header_1.parseWebm)(iterator, options));
30
+ return (0, parse_webm_header_1.parseWebm)(iterator, options);
42
31
  }
43
32
  if (iterator.isMp3()) {
44
33
  return Promise.reject(new Error('MP3 files are not yet supported'));
@@ -7,4 +7,5 @@ export type ParserContext = {
7
7
  parserState: ParserState;
8
8
  nullifySamples: boolean;
9
9
  supportsContentRange: boolean;
10
+ nextTrackIndex: number;
10
11
  };
@@ -1,13 +1,21 @@
1
+ import type { AvcPPs, AvcProfileInfo } from './boxes/avc/parse-avc';
1
2
  import type { OnTrackEntrySegment } from './boxes/webm/segments';
2
3
  import type { TrackInfo } from './boxes/webm/segments/track-entry';
3
4
  import type { AudioOrVideoSample, OnAudioSample, OnVideoSample } from './webcodec-sample-types';
4
5
  export type InternalStats = {};
6
+ export type SpsAndPps = {
7
+ sps: AvcProfileInfo;
8
+ pps: AvcPPs;
9
+ };
10
+ type AvcProfileInfoCallback = (profile: SpsAndPps) => Promise<void>;
5
11
  export declare const makeParserState: ({ hasAudioCallbacks, hasVideoCallbacks, signal, }: {
6
12
  hasAudioCallbacks: boolean;
7
13
  hasVideoCallbacks: boolean;
8
14
  signal: AbortSignal | undefined;
9
15
  }) => {
10
16
  onTrackEntrySegment: OnTrackEntrySegment;
17
+ onProfile: (profile: SpsAndPps) => Promise<void>;
18
+ registerOnAvcProfileCallback: (callback: AvcProfileInfoCallback) => void;
11
19
  getTrackInfoByNumber: (id: number) => TrackInfo;
12
20
  registerVideoSampleCallback: (id: number, callback: OnVideoSample | null) => Promise<void>;
13
21
  setTimestampOffset: (byteOffset: number, timestamp: number) => void;
@@ -18,5 +26,8 @@ export declare const makeParserState: ({ hasAudioCallbacks, hasVideoCallbacks, s
18
26
  getInternalStats: () => {};
19
27
  getTimescale: () => number;
20
28
  setTimescale: (newTimescale: number) => void;
29
+ getSamplesForTrack: (trackId: number) => number;
30
+ getAvcProfile: () => SpsAndPps | null;
21
31
  };
22
32
  export type ParserState = ReturnType<typeof makeParserState>;
33
+ export {};
@@ -59,8 +59,23 @@ const makeParserState = ({ hasAudioCallbacks, hasVideoCallbacks, signal, }) => {
59
59
  }
60
60
  return timestampMap.get(byteOffset);
61
61
  };
62
+ const samplesForTrack = {};
63
+ const profileCallbacks = [];
64
+ const registerOnAvcProfileCallback = (callback) => {
65
+ profileCallbacks.push(callback);
66
+ };
67
+ let avcProfile = null;
68
+ const onProfile = async (profile) => {
69
+ avcProfile = profile;
70
+ for (const callback of profileCallbacks) {
71
+ await callback(profile);
72
+ }
73
+ profileCallbacks.length = 0;
74
+ };
62
75
  return {
63
76
  onTrackEntrySegment,
77
+ onProfile,
78
+ registerOnAvcProfileCallback,
64
79
  getTrackInfoByNumber: (id) => trackEntries[id],
65
80
  registerVideoSampleCallback: async (id, callback) => {
66
81
  var _a;
@@ -94,6 +109,10 @@ const makeParserState = ({ hasAudioCallbacks, hasVideoCallbacks, signal, }) => {
94
109
  if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
95
110
  throw new Error('Aborted');
96
111
  }
112
+ if (typeof samplesForTrack[trackId] === 'undefined') {
113
+ samplesForTrack[trackId] = 0;
114
+ }
115
+ samplesForTrack[trackId]++;
97
116
  const callback = audioSampleCallbacks[trackId];
98
117
  if (callback) {
99
118
  await callback(audioSample);
@@ -111,6 +130,10 @@ const makeParserState = ({ hasAudioCallbacks, hasVideoCallbacks, signal, }) => {
111
130
  if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
112
131
  throw new Error('Aborted');
113
132
  }
133
+ if (typeof samplesForTrack[trackId] === 'undefined') {
134
+ samplesForTrack[trackId] = 0;
135
+ }
136
+ samplesForTrack[trackId]++;
114
137
  const callback = videoSampleCallbacks[trackId];
115
138
  if (callback) {
116
139
  await callback(videoSample);
@@ -127,6 +150,13 @@ const makeParserState = ({ hasAudioCallbacks, hasVideoCallbacks, signal, }) => {
127
150
  getInternalStats: () => ({}),
128
151
  getTimescale,
129
152
  setTimescale,
153
+ getSamplesForTrack: (trackId) => {
154
+ var _a;
155
+ return (_a = samplesForTrack[trackId]) !== null && _a !== void 0 ? _a : 0;
156
+ },
157
+ getAvcProfile: () => {
158
+ return avcProfile;
159
+ },
130
160
  };
131
161
  };
132
162
  exports.makeParserState = makeParserState;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nodeReader = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const promises_1 = require("node:fs/promises");
6
+ const path_1 = require("path");
6
7
  const stream_1 = require("stream");
7
8
  exports.nodeReader = {
8
9
  read: async (src, range, signal) => {
@@ -37,7 +38,7 @@ exports.nodeReader = {
37
38
  },
38
39
  },
39
40
  contentLength: stats.size,
40
- name: src.split('/').pop(),
41
+ name: src.split(path_1.sep).pop(),
41
42
  supportsContentRange: true,
42
43
  };
43
44
  },
@@ -0,0 +1,13 @@
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;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerVideoTrackWhenProfileIsAvailable = exports.registerTrack = void 0;
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);
9
+ }
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
+ }
14
+ };
15
+ exports.registerTrack = registerTrack;
16
+ const registerVideoTrackWhenProfileIsAvailable = ({ options, state, track, }) => {
17
+ state.registerOnAvcProfileCallback(async (profile) => {
18
+ await (0, exports.registerTrack)({
19
+ options,
20
+ state,
21
+ track: (0, add_avc_profile_to_track_1.addAvcProfileToTrack)(track, profile),
22
+ });
23
+ });
24
+ };
25
+ exports.registerVideoTrackWhenProfileIsAvailable = registerVideoTrackWhenProfileIsAvailable;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "4.0.231";
1
+ export declare const VERSION = "4.0.232";
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.231';
5
+ exports.VERSION = '4.0.232';
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.231",
6
+ "version": "4.0.232",
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.231",
13
- "@remotion/eslint-config-internal": "4.0.231"
12
+ "@remotion/example-videos": "4.0.232",
13
+ "@remotion/eslint-config-internal": "4.0.232"
14
14
  },
15
15
  "publishConfig": {
16
16
  "access": "public"