@remotion/media-parser 4.0.209 → 4.0.210
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/buffer.js +2 -0
- package/dist/boxes/iso-base-media/get-sample-positions-from-track.js +1 -1
- package/dist/boxes/iso-base-media/make-track.js +14 -2
- package/dist/boxes/iso-base-media/mdat/mdat.d.ts +2 -1
- package/dist/boxes/iso-base-media/mdat/mdat.js +8 -3
- package/dist/boxes/iso-base-media/moov/moov.d.ts +2 -1
- package/dist/boxes/iso-base-media/moov/moov.js +2 -1
- package/dist/boxes/iso-base-media/process-box.d.ts +6 -3
- package/dist/boxes/iso-base-media/process-box.js +20 -5
- package/dist/boxes/iso-base-media/stsd/avcc.d.ts +1 -1
- package/dist/boxes/iso-base-media/stsd/avcc.js +2 -2
- package/dist/boxes/iso-base-media/stsd/ctts.js +2 -5
- package/dist/boxes/iso-base-media/stsd/hvcc.d.ts +1 -1
- package/dist/boxes/iso-base-media/stsd/hvcc.js +2 -2
- package/dist/boxes/iso-base-media/stsd/mebx.d.ts +2 -1
- package/dist/boxes/iso-base-media/stsd/mebx.js +2 -1
- package/dist/boxes/iso-base-media/stsd/samples.d.ts +4 -2
- package/dist/boxes/iso-base-media/stsd/samples.js +69 -11
- package/dist/boxes/iso-base-media/stsd/stsd.d.ts +2 -1
- package/dist/boxes/iso-base-media/stsd/stsd.js +2 -1
- package/dist/boxes/iso-base-media/trak/trak.d.ts +2 -1
- package/dist/boxes/iso-base-media/trak/trak.js +2 -1
- package/dist/boxes/iso-base-media/traversal.d.ts +44 -0
- package/dist/boxes/iso-base-media/traversal.js +211 -0
- package/dist/boxes/webm/color.d.ts +4 -0
- package/dist/boxes/webm/color.js +120 -0
- package/dist/boxes/webm/description.js +1 -1
- package/dist/boxes/webm/get-ready-tracks.js +3 -3
- package/dist/boxes/webm/get-sample-from-block.js +1 -1
- package/dist/boxes/webm/get-track.js +16 -1
- package/dist/boxes/webm/make-track.d.ts +9 -0
- package/dist/boxes/webm/make-track.js +260 -0
- package/dist/boxes/webm/parse-ebml.js +2 -2
- package/dist/boxes/webm/segments/all-segments.d.ts +36 -3
- package/dist/boxes/webm/segments/all-segments.js +34 -6
- package/dist/boxes/webm/traversal.d.ts +26 -1
- package/dist/boxes/webm/traversal.js +214 -1
- package/dist/create/cluster-segment.js +0 -2
- package/dist/create/cluster.d.ts +10 -2
- package/dist/create/cluster.js +16 -10
- package/dist/create/create-media.d.ts +4 -2
- package/dist/create/create-media.js +76 -14
- package/dist/create/cues.d.ts +0 -0
- package/dist/create/cues.js +1 -0
- package/dist/create/make-duration-with-padding.d.ts +1 -1
- package/dist/create/make-duration-with-padding.js +3 -3
- package/dist/create/matroska-cues.d.ts +6 -0
- package/dist/create/matroska-cues.js +50 -0
- package/dist/create/matroska-info.js +1 -1
- package/dist/create/matroska-seek.d.ts +6 -0
- package/dist/create/matroska-seek.js +32 -0
- package/dist/create/matroska-segment.d.ts +1 -0
- package/dist/create/matroska-segment.js +3 -2
- package/dist/create/matroska-trackentry.d.ts +9 -14
- package/dist/create/matroska-trackentry.js +79 -94
- package/dist/emit-available-info.d.ts +12 -0
- package/dist/emit-available-info.js +133 -0
- package/dist/esm/buffer.mjs +57 -0
- package/dist/esm/from-fetch.mjs +72 -0
- package/dist/esm/from-node.mjs +48 -0
- package/dist/esm/from-web-file.mjs +48 -0
- package/dist/esm/index.mjs +6689 -0
- package/dist/esm/web-fs.mjs +67 -0
- package/dist/get-audio-codec.d.ts +5 -5
- package/dist/get-audio-codec.js +41 -57
- package/dist/get-container.d.ts +4 -0
- package/dist/get-container.js +26 -0
- package/dist/get-duration.js +1 -1
- package/dist/get-fps.js +1 -1
- package/dist/get-sample-aspect-ratio.d.ts +1 -1
- package/dist/get-sample-aspect-ratio.js +19 -19
- package/dist/get-tracks.d.ts +13 -0
- package/dist/get-tracks.js +8 -8
- package/dist/get-video-codec.d.ts +5 -2
- package/dist/get-video-codec.js +111 -21
- package/dist/has-all-info.d.ts +2 -2
- package/dist/has-all-info.js +23 -9
- package/dist/index.d.ts +3 -1
- package/dist/options.d.ts +97 -30
- package/dist/parse-media.js +43 -62
- package/dist/parse-video.d.ts +2 -1
- package/dist/parse-video.js +3 -1
- package/dist/parser-state.js +1 -2
- package/dist/readers/from-fetch.js +24 -4
- package/dist/readers/from-node.js +13 -3
- package/dist/readers/from-web-file.js +14 -2
- package/dist/readers/reader.d.ts +6 -1
- package/dist/samples-from-moof.js +1 -1
- package/dist/traversal.d.ts +0 -21
- package/dist/traversal.js +1 -158
- package/dist/truthy.d.ts +3 -0
- package/dist/truthy.js +7 -0
- package/dist/writers/buffer.d.ts +2 -0
- package/dist/writers/buffer.js +58 -0
- package/dist/writers/web-fs.d.ts +1 -0
- package/dist/writers/web-fs.js +42 -18
- package/dist/writers/writer.d.ts +4 -2
- package/fetch.js +2 -0
- package/node.js +2 -0
- package/package.json +43 -8
- package/web-file.js +2 -0
- package/web-fs.js +2 -0
- package/.eslintrc +0 -8
- package/input.webm +0 -0
- package/src/add-new-matroska-tracks.ts +0 -23
- package/src/boxes/iso-base-media/base-type.ts +0 -4
- package/src/boxes/iso-base-media/esds/decoder-specific-config.ts +0 -68
- package/src/boxes/iso-base-media/esds/esds-descriptors.ts +0 -135
- package/src/boxes/iso-base-media/esds/esds.ts +0 -49
- package/src/boxes/iso-base-media/ftyp.ts +0 -39
- package/src/boxes/iso-base-media/get-sample-positions-from-track.ts +0 -69
- package/src/boxes/iso-base-media/make-track.ts +0 -116
- package/src/boxes/iso-base-media/mdat/mdat.ts +0 -140
- package/src/boxes/iso-base-media/mdhd.ts +0 -59
- package/src/boxes/iso-base-media/moov/moov.ts +0 -43
- package/src/boxes/iso-base-media/mvhd.ts +0 -114
- package/src/boxes/iso-base-media/process-box.ts +0 -748
- package/src/boxes/iso-base-media/stsd/av1c.ts +0 -19
- package/src/boxes/iso-base-media/stsd/avcc.ts +0 -36
- package/src/boxes/iso-base-media/stsd/colr.ts +0 -49
- package/src/boxes/iso-base-media/stsd/ctts.ts +0 -64
- package/src/boxes/iso-base-media/stsd/hvcc.ts +0 -32
- package/src/boxes/iso-base-media/stsd/keys.ts +0 -27
- package/src/boxes/iso-base-media/stsd/mebx.ts +0 -54
- package/src/boxes/iso-base-media/stsd/pasp.ts +0 -32
- package/src/boxes/iso-base-media/stsd/samples.ts +0 -359
- package/src/boxes/iso-base-media/stsd/stco.ts +0 -52
- package/src/boxes/iso-base-media/stsd/stsc.ts +0 -61
- package/src/boxes/iso-base-media/stsd/stsd.ts +0 -55
- package/src/boxes/iso-base-media/stsd/stss.ts +0 -47
- package/src/boxes/iso-base-media/stsd/stsz.ts +0 -75
- package/src/boxes/iso-base-media/stsd/stts.ts +0 -62
- package/src/boxes/iso-base-media/tfdt.ts +0 -37
- package/src/boxes/iso-base-media/tfhd.ts +0 -66
- package/src/boxes/iso-base-media/tkhd.ts +0 -150
- package/src/boxes/iso-base-media/to-date.ts +0 -9
- package/src/boxes/iso-base-media/trak/trak.ts +0 -43
- package/src/boxes/iso-base-media/trun.ts +0 -74
- package/src/boxes/iso-base-media/void-box.ts +0 -4
- package/src/boxes/webm/allowed-partial-segments.ts +0 -1
- package/src/boxes/webm/av1-codec-private.ts +0 -113
- package/src/boxes/webm/description.ts +0 -104
- package/src/boxes/webm/ebml.ts +0 -98
- package/src/boxes/webm/get-ready-tracks.ts +0 -36
- package/src/boxes/webm/get-sample-from-block.ts +0 -125
- package/src/boxes/webm/get-track.ts +0 -257
- package/src/boxes/webm/make-header.ts +0 -253
- package/src/boxes/webm/parse-ebml.ts +0 -259
- package/src/boxes/webm/parse-webm-header.ts +0 -18
- package/src/boxes/webm/segments/all-segments.ts +0 -888
- package/src/boxes/webm/segments/block-simple-block-flags.ts +0 -52
- package/src/boxes/webm/segments/parse-children.ts +0 -144
- package/src/boxes/webm/segments/track-entry.ts +0 -38
- package/src/boxes/webm/segments.ts +0 -147
- package/src/boxes/webm/traversal.ts +0 -45
- package/src/buffer-iterator.ts +0 -555
- package/src/create/cluster-segment.ts +0 -62
- package/src/create/cluster.ts +0 -64
- package/src/create/create-media.ts +0 -136
- package/src/create/make-duration-with-padding.ts +0 -15
- package/src/create/matroska-header.ts +0 -63
- package/src/create/matroska-info.ts +0 -30
- package/src/create/matroska-segment.ts +0 -10
- package/src/create/matroska-trackentry.ts +0 -325
- package/src/create/timescale.ts +0 -1
- package/src/get-audio-codec.ts +0 -270
- package/src/get-dimensions.ts +0 -47
- package/src/get-duration.ts +0 -103
- package/src/get-fps.ts +0 -113
- package/src/get-sample-aspect-ratio.ts +0 -204
- package/src/get-sample-positions.ts +0 -93
- package/src/get-tracks.ts +0 -147
- package/src/get-video-codec.ts +0 -117
- package/src/has-all-info.ts +0 -81
- package/src/index.ts +0 -18
- package/src/make-hvc1-codec-strings.ts +0 -55
- package/src/options.ts +0 -118
- package/src/parse-media.ts +0 -183
- package/src/parse-result.ts +0 -79
- package/src/parse-video.ts +0 -83
- package/src/parser-context.ts +0 -10
- package/src/parser-state.ts +0 -178
- package/src/readers/from-fetch.ts +0 -90
- package/src/readers/from-node.ts +0 -51
- package/src/readers/from-web-file.ts +0 -49
- package/src/readers/reader.ts +0 -15
- package/src/samples-from-moof.ts +0 -102
- package/src/test/aspect-ratio.test.ts +0 -42
- package/src/test/av1.test.ts +0 -108
- package/src/test/create-matroska.test.ts +0 -287
- package/src/test/duration.test.ts +0 -18
- package/src/test/keys.test.ts +0 -47
- package/src/test/matroska.test.ts +0 -463
- package/src/test/mvhd.test.ts +0 -94
- package/src/test/parse-esds.test.ts +0 -98
- package/src/test/parse-stco.test.ts +0 -61
- package/src/test/parse-stsc.test.ts +0 -104
- package/src/test/parse-stsz.test.ts +0 -57
- package/src/test/parse-stts.test.ts +0 -38
- package/src/test/parse-video.test.ts +0 -101
- package/src/test/parse-webm.test.ts +0 -17
- package/src/test/samples-from-moof.test.ts +0 -2496
- package/src/test/stream-local.test.ts +0 -743
- package/src/test/stream-remote.test.ts +0 -59
- package/src/test/stream-samples.test.ts +0 -181
- package/src/test/stsd.test.ts +0 -265
- package/src/test/tkhd.test.ts +0 -87
- package/src/traversal.ts +0 -528
- package/src/webcodec-sample-types.ts +0 -29
- package/src/writers/web-fs.ts +0 -50
- package/src/writers/writer.ts +0 -12
- package/tsconfig.json +0 -14
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import type {ReaderInterface} from './reader';
|
|
2
|
-
|
|
3
|
-
export const fetchReader: ReaderInterface = {
|
|
4
|
-
read: async (src, range, signal) => {
|
|
5
|
-
if (typeof src !== 'string') {
|
|
6
|
-
throw new Error('src must be a string when using `fetchReader`');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const resolvedUrl =
|
|
10
|
-
typeof window !== 'undefined' && typeof window.location !== 'undefined'
|
|
11
|
-
? new URL(src, window.location.origin).toString()
|
|
12
|
-
: src;
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
!resolvedUrl.startsWith('https://') &&
|
|
16
|
-
!resolvedUrl.startsWith('http://')
|
|
17
|
-
) {
|
|
18
|
-
return Promise.reject(
|
|
19
|
-
new Error(
|
|
20
|
-
resolvedUrl +
|
|
21
|
-
' is not a URL - needs to start with http:// or https://. If you want to read a local file, pass `reader: nodeReader` to parseMedia().',
|
|
22
|
-
),
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const res = await fetch(resolvedUrl, {
|
|
27
|
-
headers:
|
|
28
|
-
range === null
|
|
29
|
-
? {}
|
|
30
|
-
: typeof range === 'number'
|
|
31
|
-
? {
|
|
32
|
-
Range: `bytes=${range}`,
|
|
33
|
-
}
|
|
34
|
-
: {
|
|
35
|
-
Range: `bytes=${`${range[0]}-${range[1]}`}`,
|
|
36
|
-
},
|
|
37
|
-
signal,
|
|
38
|
-
// Disable Next.js caching
|
|
39
|
-
cache: 'no-store',
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
res.status.toString().startsWith('4') ||
|
|
44
|
-
res.status.toString().startsWith('5')
|
|
45
|
-
) {
|
|
46
|
-
throw new Error(`Server returned status code ${res.status} for ${src}`);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!res.body) {
|
|
50
|
-
throw new Error('No body');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const length = res.headers.get('content-length');
|
|
54
|
-
|
|
55
|
-
const contentLength = length === null ? null : parseInt(length, 10);
|
|
56
|
-
|
|
57
|
-
const reader = res.body.getReader();
|
|
58
|
-
|
|
59
|
-
if (signal) {
|
|
60
|
-
signal.addEventListener(
|
|
61
|
-
'abort',
|
|
62
|
-
() => {
|
|
63
|
-
reader.cancel();
|
|
64
|
-
},
|
|
65
|
-
{once: true},
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return {reader, contentLength};
|
|
70
|
-
},
|
|
71
|
-
getLength: async (src) => {
|
|
72
|
-
if (typeof src !== 'string') {
|
|
73
|
-
throw new Error('src must be a string when using `fetchReader`');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const res = await fetch(src, {
|
|
77
|
-
method: 'HEAD',
|
|
78
|
-
});
|
|
79
|
-
if (!res.body) {
|
|
80
|
-
throw new Error('No body');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const length = res.headers.get('content-length');
|
|
84
|
-
if (!length) {
|
|
85
|
-
throw new Error('No content-length');
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return parseInt(length, 10);
|
|
89
|
-
},
|
|
90
|
-
};
|
package/src/readers/from-node.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import {createReadStream} from 'fs';
|
|
2
|
-
import {stat} from 'node:fs/promises';
|
|
3
|
-
import {Readable} from 'stream';
|
|
4
|
-
import type {ReaderInterface} from './reader';
|
|
5
|
-
|
|
6
|
-
export const nodeReader: ReaderInterface = {
|
|
7
|
-
read: async (src, range, signal) => {
|
|
8
|
-
if (typeof src !== 'string') {
|
|
9
|
-
throw new Error('src must be a string when using `nodeReader`');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const stream = createReadStream(src, {
|
|
13
|
-
start: range === null ? 0 : typeof range === 'number' ? range : range[0],
|
|
14
|
-
end:
|
|
15
|
-
range === null
|
|
16
|
-
? Infinity
|
|
17
|
-
: typeof range === 'number'
|
|
18
|
-
? Infinity
|
|
19
|
-
: range[1],
|
|
20
|
-
signal,
|
|
21
|
-
});
|
|
22
|
-
const stats = await stat(src);
|
|
23
|
-
|
|
24
|
-
const reader = Readable.toWeb(
|
|
25
|
-
stream,
|
|
26
|
-
).getReader() as ReadableStreamDefaultReader<Uint8Array>;
|
|
27
|
-
|
|
28
|
-
if (signal) {
|
|
29
|
-
signal.addEventListener(
|
|
30
|
-
'abort',
|
|
31
|
-
() => {
|
|
32
|
-
reader.cancel();
|
|
33
|
-
},
|
|
34
|
-
{once: true},
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
reader,
|
|
40
|
-
contentLength: stats.size,
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
getLength: async (src) => {
|
|
44
|
-
if (typeof src !== 'string') {
|
|
45
|
-
throw new Error('src must be a string when using `nodeReader`');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const stats = await stat(src);
|
|
49
|
-
return stats.size;
|
|
50
|
-
},
|
|
51
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type {ReaderInterface} from './reader';
|
|
2
|
-
|
|
3
|
-
export const webFileReader: ReaderInterface = {
|
|
4
|
-
read: (file, range, signal) => {
|
|
5
|
-
if (typeof file === 'string') {
|
|
6
|
-
throw new Error('`inputTypeFileReader` only supports `File` objects');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const part =
|
|
10
|
-
range === null
|
|
11
|
-
? file
|
|
12
|
-
: typeof range === 'number'
|
|
13
|
-
? file.slice(range)
|
|
14
|
-
: file.slice(range[0], range[1]);
|
|
15
|
-
|
|
16
|
-
const reader = new FileReader();
|
|
17
|
-
reader.readAsArrayBuffer(file);
|
|
18
|
-
|
|
19
|
-
if (signal) {
|
|
20
|
-
signal.addEventListener(
|
|
21
|
-
'abort',
|
|
22
|
-
() => {
|
|
23
|
-
reader.abort();
|
|
24
|
-
},
|
|
25
|
-
{once: true},
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return new Promise((resolve, reject) => {
|
|
30
|
-
reader.onload = () => {
|
|
31
|
-
resolve({
|
|
32
|
-
reader: part.stream().getReader(),
|
|
33
|
-
contentLength: file.size,
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
reader.onerror = (error) => {
|
|
38
|
-
reject(error);
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
},
|
|
42
|
-
getLength: (src) => {
|
|
43
|
-
if (typeof src === 'string') {
|
|
44
|
-
throw new Error('`inputTypeFileReader` only supports `File` objects');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return Promise.resolve(src.size);
|
|
48
|
-
},
|
|
49
|
-
};
|
package/src/readers/reader.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
type ReadResult = {
|
|
2
|
-
reader: ReadableStreamDefaultReader<Uint8Array>;
|
|
3
|
-
contentLength: number | null;
|
|
4
|
-
};
|
|
5
|
-
type ReadContent = (
|
|
6
|
-
src: string | File,
|
|
7
|
-
range: [number, number] | number | null,
|
|
8
|
-
signal: AbortSignal | undefined,
|
|
9
|
-
) => Promise<ReadResult>;
|
|
10
|
-
type GetLength = (src: string | File) => Promise<number>;
|
|
11
|
-
|
|
12
|
-
export type ReaderInterface = {
|
|
13
|
-
read: ReadContent;
|
|
14
|
-
getLength: GetLength;
|
|
15
|
-
};
|
package/src/samples-from-moof.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import type {SamplePosition} from './get-sample-positions';
|
|
2
|
-
import type {AnySegment, IsoBaseMediaBox} from './parse-result';
|
|
3
|
-
import {getTfdtBox, getTfhdBox, getTrunBoxes} from './traversal';
|
|
4
|
-
|
|
5
|
-
const getSamplesFromTraf = (
|
|
6
|
-
trafSegment: IsoBaseMediaBox,
|
|
7
|
-
moofOffset: number,
|
|
8
|
-
): SamplePosition[] => {
|
|
9
|
-
if (trafSegment.type !== 'regular-box' || trafSegment.boxType !== 'traf') {
|
|
10
|
-
throw new Error('Expected traf-box');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const tfhdBox = getTfhdBox(trafSegment);
|
|
14
|
-
const defaultSampleDuration = tfhdBox?.defaultSampleDuration ?? null;
|
|
15
|
-
const defaultSampleSize = tfhdBox?.defaultSampleSize ?? null;
|
|
16
|
-
const defaultSampleFlags = tfhdBox?.defaultSampleFlags ?? null;
|
|
17
|
-
|
|
18
|
-
const tfdtBox = getTfdtBox(trafSegment);
|
|
19
|
-
const trunBoxes = getTrunBoxes(trafSegment);
|
|
20
|
-
|
|
21
|
-
let time = 0;
|
|
22
|
-
let offset = 0;
|
|
23
|
-
|
|
24
|
-
let dataOffset = 0;
|
|
25
|
-
|
|
26
|
-
const samples: SamplePosition[] = [];
|
|
27
|
-
|
|
28
|
-
for (const trunBox of trunBoxes) {
|
|
29
|
-
let i = -1;
|
|
30
|
-
|
|
31
|
-
if (trunBox.dataOffset) {
|
|
32
|
-
dataOffset = trunBox.dataOffset;
|
|
33
|
-
offset = 0;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
for (const sample of trunBox.samples) {
|
|
37
|
-
i++;
|
|
38
|
-
const duration = sample.sampleDuration ?? defaultSampleDuration;
|
|
39
|
-
if (duration === null) {
|
|
40
|
-
throw new Error('Expected duration');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const size = sample.sampleSize ?? defaultSampleSize;
|
|
44
|
-
if (size === null) {
|
|
45
|
-
throw new Error('Expected size');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const isFirstSample = i === 0;
|
|
49
|
-
const sampleFlags = sample.sampleFlags
|
|
50
|
-
? sample.sampleFlags
|
|
51
|
-
: isFirstSample && trunBox.firstSampleFlags !== null
|
|
52
|
-
? trunBox.firstSampleFlags
|
|
53
|
-
: defaultSampleFlags;
|
|
54
|
-
if (sampleFlags === null) {
|
|
55
|
-
throw new Error('Expected sample flags');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const keyframe = !((sampleFlags >> 16) & 0x1);
|
|
59
|
-
|
|
60
|
-
const dts = time + (tfdtBox?.baseMediaDecodeTime ?? 0);
|
|
61
|
-
|
|
62
|
-
const samplePosition: SamplePosition = {
|
|
63
|
-
offset: offset + (moofOffset ?? 0) + (dataOffset ?? 0),
|
|
64
|
-
dts,
|
|
65
|
-
cts: dts,
|
|
66
|
-
duration,
|
|
67
|
-
isKeyframe: keyframe,
|
|
68
|
-
size,
|
|
69
|
-
};
|
|
70
|
-
samples.push(samplePosition);
|
|
71
|
-
offset += size;
|
|
72
|
-
time += duration;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return samples;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export const getSamplesFromMoof = ({
|
|
80
|
-
moofBox,
|
|
81
|
-
trackId,
|
|
82
|
-
}: {
|
|
83
|
-
moofBox: AnySegment;
|
|
84
|
-
trackId: number;
|
|
85
|
-
}) => {
|
|
86
|
-
if (moofBox.type !== 'regular-box') {
|
|
87
|
-
throw new Error('Expected moof-box');
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const trafs = moofBox.children.filter(
|
|
91
|
-
(c) => c.type === 'regular-box' && c.boxType === 'traf',
|
|
92
|
-
) as IsoBaseMediaBox[];
|
|
93
|
-
|
|
94
|
-
const mapped = trafs.map((traf) => {
|
|
95
|
-
const tfhdBox = getTfhdBox(traf);
|
|
96
|
-
|
|
97
|
-
return tfhdBox?.trackId === trackId
|
|
98
|
-
? getSamplesFromTraf(traf, moofBox.offset)
|
|
99
|
-
: [];
|
|
100
|
-
});
|
|
101
|
-
return mapped.flat(1);
|
|
102
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import {expect, test} from 'bun:test';
|
|
2
|
-
import {
|
|
3
|
-
applyAspectRatios,
|
|
4
|
-
getDisplayAspectRatio,
|
|
5
|
-
} from '../get-sample-aspect-ratio';
|
|
6
|
-
|
|
7
|
-
test('Should calculate sample aspect ratio', () => {
|
|
8
|
-
const displayAspectRatio = getDisplayAspectRatio({
|
|
9
|
-
sampleAspectRatio: {
|
|
10
|
-
denominator: 177,
|
|
11
|
-
numerator: 56,
|
|
12
|
-
},
|
|
13
|
-
nativeDimensions: {
|
|
14
|
-
width: 1280,
|
|
15
|
-
height: 720,
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
expect(displayAspectRatio).toEqual({
|
|
20
|
-
numerator: 896,
|
|
21
|
-
denominator: 1593,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const applied = applyAspectRatios({
|
|
25
|
-
dimensions: {
|
|
26
|
-
width: 1280,
|
|
27
|
-
height: 720,
|
|
28
|
-
},
|
|
29
|
-
sampleAspectRatio: {
|
|
30
|
-
numerator: 56,
|
|
31
|
-
denominator: 177,
|
|
32
|
-
},
|
|
33
|
-
displayAspectRatio: {
|
|
34
|
-
numerator: 896,
|
|
35
|
-
denominator: 1593,
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
expect(applied).toEqual({
|
|
39
|
-
width: 405,
|
|
40
|
-
height: 720,
|
|
41
|
-
});
|
|
42
|
-
});
|
package/src/test/av1.test.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import {RenderInternals} from '@remotion/renderer';
|
|
2
|
-
import {expect, test} from 'bun:test';
|
|
3
|
-
import {trakBoxContainsVideo} from '../get-fps';
|
|
4
|
-
import {getAv1CBox} from '../get-sample-aspect-ratio';
|
|
5
|
-
import {parseMedia} from '../parse-media';
|
|
6
|
-
import {nodeReader} from '../readers/from-node';
|
|
7
|
-
import {getMoovBox, getTraks} from '../traversal';
|
|
8
|
-
|
|
9
|
-
test('AV1 in MP4', async () => {
|
|
10
|
-
const parsed = await parseMedia({
|
|
11
|
-
src: RenderInternals.exampleVideos.av1mp4,
|
|
12
|
-
fields: {
|
|
13
|
-
durationInSeconds: true,
|
|
14
|
-
fps: true,
|
|
15
|
-
videoCodec: true,
|
|
16
|
-
tracks: true,
|
|
17
|
-
audioCodec: true,
|
|
18
|
-
dimensions: true,
|
|
19
|
-
rotation: true,
|
|
20
|
-
boxes: true,
|
|
21
|
-
},
|
|
22
|
-
reader: nodeReader,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const moovBox = getMoovBox(parsed.boxes);
|
|
26
|
-
if (!moovBox) {
|
|
27
|
-
throw new Error('No moov box');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const traks = getTraks(moovBox).filter((t) => trakBoxContainsVideo(t))[0];
|
|
31
|
-
const avc1Box = getAv1CBox(traks);
|
|
32
|
-
expect(avc1Box).toEqual({
|
|
33
|
-
type: 'av1C-box',
|
|
34
|
-
privateData: new Uint8Array([
|
|
35
|
-
129, 8, 12, 0, 10, 11, 0, 0, 0, 66, 171, 191, 195, 119, 111, 228, 1,
|
|
36
|
-
]),
|
|
37
|
-
});
|
|
38
|
-
expect(avc1Box).toBeTruthy();
|
|
39
|
-
|
|
40
|
-
expect(parsed.durationInSeconds).toBe(10);
|
|
41
|
-
expect(parsed.fps).toBe(30);
|
|
42
|
-
expect(parsed.videoCodec).toBe('av1');
|
|
43
|
-
expect(parsed.videoTracks[0].codec).toEqual('av01.0.08M.08');
|
|
44
|
-
// This is true, there are no audio tracks
|
|
45
|
-
expect(parsed.audioTracks).toEqual([]);
|
|
46
|
-
expect(parsed.audioCodec).toEqual(null);
|
|
47
|
-
expect(parsed.dimensions).toEqual({
|
|
48
|
-
width: 1920,
|
|
49
|
-
height: 1080,
|
|
50
|
-
});
|
|
51
|
-
expect(parsed.rotation).toBe(0);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('AV1 in MP4 with colr atom', async () => {
|
|
55
|
-
let tracks = 0;
|
|
56
|
-
let samples = 0;
|
|
57
|
-
|
|
58
|
-
const parsed = await parseMedia({
|
|
59
|
-
src: RenderInternals.exampleVideos.av1mp4WithColr,
|
|
60
|
-
fields: {
|
|
61
|
-
durationInSeconds: true,
|
|
62
|
-
fps: true,
|
|
63
|
-
videoCodec: true,
|
|
64
|
-
tracks: true,
|
|
65
|
-
audioCodec: true,
|
|
66
|
-
dimensions: true,
|
|
67
|
-
rotation: true,
|
|
68
|
-
boxes: true,
|
|
69
|
-
},
|
|
70
|
-
reader: nodeReader,
|
|
71
|
-
onVideoTrack: () => {
|
|
72
|
-
tracks++;
|
|
73
|
-
return () => {
|
|
74
|
-
samples++;
|
|
75
|
-
};
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const moovBox = getMoovBox(parsed.boxes);
|
|
80
|
-
if (!moovBox) {
|
|
81
|
-
throw new Error('No moov box');
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const traks = getTraks(moovBox).filter((t) => trakBoxContainsVideo(t))[0];
|
|
85
|
-
const avc1Box = getAv1CBox(traks);
|
|
86
|
-
expect(avc1Box).toEqual({
|
|
87
|
-
type: 'av1C-box',
|
|
88
|
-
privateData: new Uint8Array([
|
|
89
|
-
129, 8, 12, 0, 10, 14, 0, 0, 0, 66, 171, 191, 195, 118, 0, 8, 8, 8, 8, 32,
|
|
90
|
-
]),
|
|
91
|
-
});
|
|
92
|
-
expect(avc1Box).toBeTruthy();
|
|
93
|
-
|
|
94
|
-
expect(parsed.durationInSeconds).toBe(1);
|
|
95
|
-
expect(parsed.fps).toBe(25);
|
|
96
|
-
expect(parsed.videoCodec).toBe('av1');
|
|
97
|
-
expect(parsed.videoTracks[0].codec).toEqual('av01.0.08M.08');
|
|
98
|
-
// This is true, there are no audio tracks
|
|
99
|
-
expect(parsed.audioTracks).toEqual([]);
|
|
100
|
-
expect(parsed.audioCodec).toEqual(null);
|
|
101
|
-
expect(parsed.dimensions).toEqual({
|
|
102
|
-
width: 1920,
|
|
103
|
-
height: 1080,
|
|
104
|
-
});
|
|
105
|
-
expect(parsed.rotation).toBe(0);
|
|
106
|
-
expect(tracks).toBe(1);
|
|
107
|
-
expect(samples).toBe(25);
|
|
108
|
-
});
|