@remotion/media-parser 4.0.240 → 4.0.241
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/dist/boxes/avc/codec-private.d.ts +1 -1
- package/dist/boxes/transport-stream/adts-header.d.ts +1 -1
- package/dist/boxes/transport-stream/discard-rest-of-packet.d.ts +1 -1
- package/dist/boxes/webm/ebml.d.ts +1 -1
- package/dist/boxes/webm/make-header.d.ts +3 -3
- package/dist/buffer-iterator.d.ts +2 -6
- package/dist/buffer-iterator.js +4 -29
- package/dist/create/iso-base-media/codec-specific/avc1.d.ts +1 -1
- package/dist/create/iso-base-media/codec-specific/create-codec-specific-data.d.ts +1 -1
- package/dist/create/iso-base-media/codec-specific/mp4a.d.ts +1 -1
- package/dist/create/iso-base-media/create-colr.d.ts +1 -1
- package/dist/create/iso-base-media/create-ftyp.d.ts +2 -2
- package/dist/create/iso-base-media/create-ilst.d.ts +1 -1
- package/dist/create/iso-base-media/create-mdia.d.ts +1 -1
- package/dist/create/iso-base-media/create-moov.d.ts +1 -1
- package/dist/create/iso-base-media/create-mvhd.d.ts +1 -1
- package/dist/create/iso-base-media/create-trak.d.ts +1 -1
- package/dist/create/iso-base-media/create-udta.d.ts +1 -1
- package/dist/create/iso-base-media/create-url.d.ts +1 -1
- package/dist/create/iso-base-media/ilst/create-cmt.d.ts +1 -1
- package/dist/create/iso-base-media/ilst/create-too.d.ts +1 -1
- package/dist/create/iso-base-media/mdia/create-mdhd.d.ts +1 -1
- package/dist/create/iso-base-media/mp4-header.d.ts +1 -1
- package/dist/create/iso-base-media/primitives.d.ts +13 -13
- package/dist/create/iso-base-media/serialize-track.d.ts +1 -1
- package/dist/create/iso-base-media/trak/create-tkhd.d.ts +2 -2
- package/dist/create/iso-base-media/trak/mdia/create-minf.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/create-dinf.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/create-smhd.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/create-stbl.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/create-vmhd.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-ctts.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stco.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stsc.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stss.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stsz.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stts.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/stsd/create-avc1.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/stsd/create-avcc.d.ts +1 -1
- package/dist/create/iso-base-media/trak/mdia/minf/stbl/stsd/create-pasp.d.ts +1 -1
- package/dist/create/iso-base-media/udta/create-meta.d.ts +1 -1
- package/dist/create/iso-base-media/udta/meta/create-hdlr.d.ts +1 -1
- package/dist/create/matroska/cluster-segment.d.ts +1 -1
- package/dist/emit-available-info.d.ts +6 -3
- package/dist/emit-available-info.js +107 -69
- package/dist/errors/detect-file-type.d.ts +1 -0
- package/dist/errors/detect-file-type.js +88 -0
- package/dist/errors/file-types.d.ts +1 -0
- package/dist/errors/file-types.js +88 -0
- package/dist/errors.d.ts +68 -0
- package/dist/errors.js +71 -0
- package/dist/esm/from-fetch.mjs +1 -0
- package/dist/esm/from-node.mjs +1 -0
- package/dist/esm/from-web-file.mjs +2 -1
- package/dist/esm/index.mjs +633 -109
- package/dist/file-types/bmp.d.ts +6 -0
- package/dist/file-types/bmp.js +23 -0
- package/dist/file-types/detect-file-type.d.ts +42 -0
- package/dist/file-types/detect-file-type.js +59 -0
- package/dist/file-types/get-jpeg-dimensions.d.ts +4 -0
- package/dist/file-types/get-jpeg-dimensions.js +32 -0
- package/dist/file-types/index.d.ts +2 -0
- package/dist/file-types/index.js +57 -0
- package/dist/file-types/jpeg.d.ts +12 -0
- package/dist/file-types/jpeg.js +44 -0
- package/dist/file-types/pdf.d.ts +4 -0
- package/dist/file-types/pdf.js +12 -0
- package/dist/file-types/png.d.ts +10 -0
- package/dist/file-types/png.js +32 -0
- package/dist/file-types/webp.d.ts +6 -0
- package/dist/file-types/webp.js +69 -0
- package/dist/file-types.d.ts +1 -0
- package/dist/file-types.js +88 -0
- package/dist/get-audio-codec.d.ts +1 -1
- package/dist/get-fields-from-callbacks.d.ts +5 -0
- package/dist/get-fields-from-callbacks.js +27 -0
- package/dist/has-all-info.d.ts +5 -1
- package/dist/has-all-info.js +10 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +7 -1
- package/dist/options.d.ts +36 -53
- package/dist/parse-media.js +53 -14
- package/dist/parse-video.d.ts +4 -1
- package/dist/parse-video.js +71 -8
- package/dist/probing/detect-file-type.d.ts +1 -0
- package/dist/probing/detect-file-type.js +88 -0
- package/dist/probing/get-jpeg-dimensions.d.ts +4 -0
- package/dist/probing/get-jpeg-dimensions.js +32 -0
- package/dist/readers/from-fetch.js +1 -0
- package/dist/readers/from-node.js +1 -0
- package/dist/readers/from-web-file.js +1 -0
- package/dist/readers/reader.d.ts +1 -0
- package/dist/state/can-skip-tracks.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isBmp = void 0;
|
|
4
|
+
const detect_file_type_1 = require("./detect-file-type");
|
|
5
|
+
function getBmpDimensions(bmpData) {
|
|
6
|
+
if (bmpData.length < 26) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const view = new DataView(bmpData.buffer, bmpData.byteOffset);
|
|
10
|
+
return {
|
|
11
|
+
width: view.getUint32(18, true),
|
|
12
|
+
height: Math.abs(view.getInt32(22, true)),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const isBmp = (data) => {
|
|
16
|
+
const bmpPattern = new Uint8Array([0x42, 0x4d]);
|
|
17
|
+
if ((0, detect_file_type_1.matchesPattern)(bmpPattern)(data.subarray(0, 2))) {
|
|
18
|
+
const bmp = getBmpDimensions(data);
|
|
19
|
+
return { dimensions: bmp, type: 'bmp' };
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
};
|
|
23
|
+
exports.isBmp = isBmp;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { BmpType } from './bmp';
|
|
2
|
+
import type { JpegType } from './jpeg';
|
|
3
|
+
import type { PdfType } from './pdf';
|
|
4
|
+
import type { PngType } from './png';
|
|
5
|
+
import type { WebpType } from './webp';
|
|
6
|
+
export declare const matchesPattern: (pattern: Uint8Array) => (data: Uint8Array) => boolean;
|
|
7
|
+
export declare const isRiffAvi: (data: Uint8Array) => boolean;
|
|
8
|
+
export declare const isRiffWave: (data: Uint8Array) => boolean;
|
|
9
|
+
export declare const isWebm: (data: Uint8Array) => boolean;
|
|
10
|
+
export declare const isIsoBaseMedia: (data: Uint8Array) => boolean;
|
|
11
|
+
export declare const isTransportStream: (data: Uint8Array) => boolean;
|
|
12
|
+
export declare const isMp3: (data: Uint8Array) => boolean;
|
|
13
|
+
export declare const isGif: (data: Uint8Array) => boolean;
|
|
14
|
+
export declare const isAac: (data: Uint8Array) => boolean;
|
|
15
|
+
export type RiffType = {
|
|
16
|
+
type: 'riff';
|
|
17
|
+
};
|
|
18
|
+
export type WebmType = {
|
|
19
|
+
type: 'webm';
|
|
20
|
+
};
|
|
21
|
+
export type IsoBaseMediaType = {
|
|
22
|
+
type: 'iso-base-media';
|
|
23
|
+
};
|
|
24
|
+
export type TransportStreamType = {
|
|
25
|
+
type: 'transport-stream';
|
|
26
|
+
};
|
|
27
|
+
export type Mp3Type = {
|
|
28
|
+
type: 'mp3';
|
|
29
|
+
};
|
|
30
|
+
export type AacType = {
|
|
31
|
+
type: 'aac';
|
|
32
|
+
};
|
|
33
|
+
export type WavType = {
|
|
34
|
+
type: 'wav';
|
|
35
|
+
};
|
|
36
|
+
export type GifType = {
|
|
37
|
+
type: 'gif';
|
|
38
|
+
};
|
|
39
|
+
export type UnknownType = {
|
|
40
|
+
type: 'unknown';
|
|
41
|
+
};
|
|
42
|
+
export type FileType = JpegType | WebpType | RiffType | WebmType | WavType | PdfType | AacType | IsoBaseMediaType | TransportStreamType | Mp3Type | GifType | PngType | BmpType | AacType | UnknownType;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAac = exports.isGif = exports.isMp3 = exports.isTransportStream = exports.isIsoBaseMedia = exports.isWebm = exports.isRiffWave = exports.isRiffAvi = exports.matchesPattern = void 0;
|
|
4
|
+
const make_header_1 = require("../boxes/webm/make-header");
|
|
5
|
+
const matchesPattern = (pattern) => {
|
|
6
|
+
return (data) => {
|
|
7
|
+
return pattern.every((value, index) => data[index] === value);
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
exports.matchesPattern = matchesPattern;
|
|
11
|
+
const isRiffAvi = (data) => {
|
|
12
|
+
const riffPattern = new Uint8Array([0x52, 0x49, 0x46, 0x46]);
|
|
13
|
+
if (!(0, exports.matchesPattern)(riffPattern)(data.subarray(0, 4))) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const fileType = data.subarray(8, 12);
|
|
17
|
+
return new TextDecoder().decode(fileType) === 'AVI ';
|
|
18
|
+
};
|
|
19
|
+
exports.isRiffAvi = isRiffAvi;
|
|
20
|
+
const isRiffWave = (data) => {
|
|
21
|
+
const riffPattern = new Uint8Array([0x52, 0x49, 0x46, 0x46]);
|
|
22
|
+
if (!(0, exports.matchesPattern)(riffPattern)(data.subarray(0, 4))) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const fileType = data.subarray(8, 12);
|
|
26
|
+
return new TextDecoder().decode(fileType) === 'WAVE';
|
|
27
|
+
};
|
|
28
|
+
exports.isRiffWave = isRiffWave;
|
|
29
|
+
const isWebm = (data) => {
|
|
30
|
+
return (0, exports.matchesPattern)(make_header_1.webmPattern)(data.subarray(0, 4));
|
|
31
|
+
};
|
|
32
|
+
exports.isWebm = isWebm;
|
|
33
|
+
const isIsoBaseMedia = (data) => {
|
|
34
|
+
const isoBaseMediaMp4Pattern = new TextEncoder().encode('ftyp');
|
|
35
|
+
return (0, exports.matchesPattern)(isoBaseMediaMp4Pattern)(data.subarray(4, 8));
|
|
36
|
+
};
|
|
37
|
+
exports.isIsoBaseMedia = isIsoBaseMedia;
|
|
38
|
+
const isTransportStream = (data) => {
|
|
39
|
+
return data[0] === 0x47 && data[188] === 0x47;
|
|
40
|
+
};
|
|
41
|
+
exports.isTransportStream = isTransportStream;
|
|
42
|
+
const isMp3 = (data) => {
|
|
43
|
+
const mpegPattern = new Uint8Array([0xff, 0xf3, 0xe4, 0x64]);
|
|
44
|
+
const id3Pattern = new Uint8Array([73, 68, 51, 3]);
|
|
45
|
+
const subarray = data.subarray(0, 4);
|
|
46
|
+
return ((0, exports.matchesPattern)(mpegPattern)(subarray) ||
|
|
47
|
+
(0, exports.matchesPattern)(id3Pattern)(subarray));
|
|
48
|
+
};
|
|
49
|
+
exports.isMp3 = isMp3;
|
|
50
|
+
const isGif = (data) => {
|
|
51
|
+
const gifPattern = new Uint8Array([0x47, 0x49, 0x46, 0x38]);
|
|
52
|
+
return (0, exports.matchesPattern)(gifPattern)(data.subarray(0, 4));
|
|
53
|
+
};
|
|
54
|
+
exports.isGif = isGif;
|
|
55
|
+
const isAac = (data) => {
|
|
56
|
+
const aacPattern = new Uint8Array([0xff, 0xf1]);
|
|
57
|
+
return (0, exports.matchesPattern)(aacPattern)(data.subarray(0, 2));
|
|
58
|
+
};
|
|
59
|
+
exports.isAac = isAac;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getJpegDimensions = getJpegDimensions;
|
|
4
|
+
function getJpegDimensions(data) {
|
|
5
|
+
let offset = 0;
|
|
6
|
+
// Helper function to read a 16-bit big-endian integer
|
|
7
|
+
function readUint16BE(o) {
|
|
8
|
+
return (data[o] << 8) | data[o + 1];
|
|
9
|
+
}
|
|
10
|
+
// Skip the Start of Image (SOI) marker
|
|
11
|
+
if (readUint16BE(offset) !== 0xffd8) {
|
|
12
|
+
return null; // Not a valid JPEG file
|
|
13
|
+
}
|
|
14
|
+
offset += 2;
|
|
15
|
+
while (offset < data.length) {
|
|
16
|
+
if (data[offset] === 0xff) {
|
|
17
|
+
const marker = data[offset + 1];
|
|
18
|
+
if (marker === 0xc0 || marker === 0xc2) {
|
|
19
|
+
// SOF0 or SOF2
|
|
20
|
+
const height = readUint16BE(offset + 5);
|
|
21
|
+
const width = readUint16BE(offset + 7);
|
|
22
|
+
return { width, height };
|
|
23
|
+
}
|
|
24
|
+
const length = readUint16BE(offset + 2);
|
|
25
|
+
offset += length + 2; // Move to the next marker
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
offset++;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return null; // Return null if dimensions are not found
|
|
32
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectFileType = void 0;
|
|
4
|
+
const bmp_1 = require("./bmp");
|
|
5
|
+
const detect_file_type_1 = require("./detect-file-type");
|
|
6
|
+
const jpeg_1 = require("./jpeg");
|
|
7
|
+
const pdf_1 = require("./pdf");
|
|
8
|
+
const png_1 = require("./png");
|
|
9
|
+
const webp_1 = require("./webp");
|
|
10
|
+
const detectFileType = (data) => {
|
|
11
|
+
if ((0, detect_file_type_1.isRiffWave)(data)) {
|
|
12
|
+
return { type: 'wav' };
|
|
13
|
+
}
|
|
14
|
+
if ((0, detect_file_type_1.isRiffAvi)(data)) {
|
|
15
|
+
return { type: 'riff' };
|
|
16
|
+
}
|
|
17
|
+
if ((0, detect_file_type_1.isAac)(data)) {
|
|
18
|
+
return { type: 'aac' };
|
|
19
|
+
}
|
|
20
|
+
const webp = (0, webp_1.isWebp)(data);
|
|
21
|
+
if (webp) {
|
|
22
|
+
return webp;
|
|
23
|
+
}
|
|
24
|
+
if ((0, detect_file_type_1.isWebm)(data)) {
|
|
25
|
+
return { type: 'webm' };
|
|
26
|
+
}
|
|
27
|
+
if ((0, detect_file_type_1.isIsoBaseMedia)(data)) {
|
|
28
|
+
return { type: 'iso-base-media' };
|
|
29
|
+
}
|
|
30
|
+
if ((0, detect_file_type_1.isTransportStream)(data)) {
|
|
31
|
+
return { type: 'transport-stream' };
|
|
32
|
+
}
|
|
33
|
+
if ((0, detect_file_type_1.isMp3)(data)) {
|
|
34
|
+
return { type: 'mp3' };
|
|
35
|
+
}
|
|
36
|
+
if ((0, detect_file_type_1.isGif)(data)) {
|
|
37
|
+
return { type: 'gif' };
|
|
38
|
+
}
|
|
39
|
+
const png = (0, png_1.isPng)(data);
|
|
40
|
+
if (png) {
|
|
41
|
+
return png;
|
|
42
|
+
}
|
|
43
|
+
const pdf = (0, pdf_1.isPdf)(data);
|
|
44
|
+
if (pdf) {
|
|
45
|
+
return pdf;
|
|
46
|
+
}
|
|
47
|
+
const bmp = (0, bmp_1.isBmp)(data);
|
|
48
|
+
if (bmp) {
|
|
49
|
+
return bmp;
|
|
50
|
+
}
|
|
51
|
+
const jpeg = (0, jpeg_1.isJpeg)(data);
|
|
52
|
+
if (jpeg) {
|
|
53
|
+
return jpeg;
|
|
54
|
+
}
|
|
55
|
+
return { type: 'unknown' };
|
|
56
|
+
};
|
|
57
|
+
exports.detectFileType = detectFileType;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function getJpegDimensions(data: Uint8Array): {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
} | null;
|
|
5
|
+
export declare const isJpeg: (data: Uint8Array) => JpegType | null;
|
|
6
|
+
export type JpegType = {
|
|
7
|
+
type: 'jpeg';
|
|
8
|
+
dimensions: {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
} | null;
|
|
12
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isJpeg = void 0;
|
|
4
|
+
exports.getJpegDimensions = getJpegDimensions;
|
|
5
|
+
const detect_file_type_1 = require("./detect-file-type");
|
|
6
|
+
function getJpegDimensions(data) {
|
|
7
|
+
let offset = 0;
|
|
8
|
+
// Helper function to read a 16-bit big-endian integer
|
|
9
|
+
function readUint16BE(o) {
|
|
10
|
+
return (data[o] << 8) | data[o + 1];
|
|
11
|
+
}
|
|
12
|
+
// Skip the Start of Image (SOI) marker
|
|
13
|
+
if (readUint16BE(offset) !== 0xffd8) {
|
|
14
|
+
return null; // Not a valid JPEG file
|
|
15
|
+
}
|
|
16
|
+
offset += 2;
|
|
17
|
+
while (offset < data.length) {
|
|
18
|
+
if (data[offset] === 0xff) {
|
|
19
|
+
const marker = data[offset + 1];
|
|
20
|
+
if (marker === 0xc0 || marker === 0xc2) {
|
|
21
|
+
// SOF0 or SOF2
|
|
22
|
+
const height = readUint16BE(offset + 5);
|
|
23
|
+
const width = readUint16BE(offset + 7);
|
|
24
|
+
return { width, height };
|
|
25
|
+
}
|
|
26
|
+
const length = readUint16BE(offset + 2);
|
|
27
|
+
offset += length + 2; // Move to the next marker
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
offset++;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null; // Return null if dimensions are not found
|
|
34
|
+
}
|
|
35
|
+
const isJpeg = (data) => {
|
|
36
|
+
const jpegPattern = new Uint8Array([0xff, 0xd8]);
|
|
37
|
+
const jpeg = (0, detect_file_type_1.matchesPattern)(jpegPattern)(data.subarray(0, 2));
|
|
38
|
+
if (!jpeg) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const dim = getJpegDimensions(data);
|
|
42
|
+
return { dimensions: dim, type: 'jpeg' };
|
|
43
|
+
};
|
|
44
|
+
exports.isJpeg = isJpeg;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPdf = void 0;
|
|
4
|
+
const detect_file_type_1 = require("./detect-file-type");
|
|
5
|
+
const isPdf = (data) => {
|
|
6
|
+
if (data.length < 4) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const pdfPattern = new Uint8Array([0x25, 0x50, 0x44, 0x46]);
|
|
10
|
+
return (0, detect_file_type_1.matchesPattern)(pdfPattern)(data.subarray(0, 4)) ? { type: 'pdf' } : null;
|
|
11
|
+
};
|
|
12
|
+
exports.isPdf = isPdf;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Dimensions } from '../get-dimensions';
|
|
2
|
+
export declare function getPngDimensions(pngData: Uint8Array): {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
} | null;
|
|
6
|
+
export declare const isPng: (data: Uint8Array) => PngType | null;
|
|
7
|
+
export type PngType = {
|
|
8
|
+
type: 'png';
|
|
9
|
+
dimensions: Dimensions | null;
|
|
10
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPng = void 0;
|
|
4
|
+
exports.getPngDimensions = getPngDimensions;
|
|
5
|
+
const detect_file_type_1 = require("./detect-file-type");
|
|
6
|
+
function getPngDimensions(pngData) {
|
|
7
|
+
if (pngData.length < 24) {
|
|
8
|
+
// PNG header (8) + IHDR chunk (16) minimum
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const view = new DataView(pngData.buffer, pngData.byteOffset);
|
|
12
|
+
// Check PNG signature
|
|
13
|
+
const pngSignature = [137, 80, 78, 71, 13, 10, 26, 10];
|
|
14
|
+
for (let i = 0; i < 8; i++) {
|
|
15
|
+
if (pngData[i] !== pngSignature[i]) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
width: view.getUint32(16, false), // false = big-endian
|
|
21
|
+
height: view.getUint32(20, false), // false = big-endian
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const isPng = (data) => {
|
|
25
|
+
const pngPattern = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
26
|
+
if ((0, detect_file_type_1.matchesPattern)(pngPattern)(data.subarray(0, 4))) {
|
|
27
|
+
const png = getPngDimensions(data);
|
|
28
|
+
return { dimensions: png, type: 'png' };
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
};
|
|
32
|
+
exports.isPng = isPng;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isWebp = void 0;
|
|
4
|
+
const detect_file_type_1 = require("./detect-file-type");
|
|
5
|
+
function getWebPDimensions(bytes) {
|
|
6
|
+
// Check if we have enough bytes for a basic WebP header
|
|
7
|
+
if (bytes.length < 30) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
// Check WebP file signature
|
|
11
|
+
// "RIFF" signature (52 49 46 46) and "WEBP" signature (57 45 42 50)
|
|
12
|
+
if (bytes[0] !== 0x52 || // R
|
|
13
|
+
bytes[1] !== 0x49 || // I
|
|
14
|
+
bytes[2] !== 0x46 || // F
|
|
15
|
+
bytes[3] !== 0x46 || // F
|
|
16
|
+
bytes[8] !== 0x57 || // W
|
|
17
|
+
bytes[9] !== 0x45 || // E
|
|
18
|
+
bytes[10] !== 0x42 || // B
|
|
19
|
+
bytes[11] !== 0x50 // P
|
|
20
|
+
) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
// Check for VP8 bitstream
|
|
24
|
+
if (bytes[12] === 0x56 && bytes[13] === 0x50 && bytes[14] === 0x38) {
|
|
25
|
+
// VP8 format
|
|
26
|
+
if (bytes[15] === 0x20) {
|
|
27
|
+
// Simple VP8 format
|
|
28
|
+
return {
|
|
29
|
+
width: bytes[26] | ((bytes[27] << 8) & 0x3fff),
|
|
30
|
+
height: bytes[28] | ((bytes[29] << 8) & 0x3fff),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// Check for VP8L (lossless) bitstream
|
|
35
|
+
if (bytes[12] === 0x56 &&
|
|
36
|
+
bytes[13] === 0x50 &&
|
|
37
|
+
bytes[14] === 0x38 &&
|
|
38
|
+
bytes[15] === 0x4c) {
|
|
39
|
+
return {
|
|
40
|
+
width: 1 + (bytes[21] | ((bytes[22] & 0x3f) << 8)),
|
|
41
|
+
height: 1 +
|
|
42
|
+
(((bytes[22] & 0xc0) >> 6) |
|
|
43
|
+
(bytes[23] << 2) |
|
|
44
|
+
((bytes[24] & 0x0f) << 10)),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// Check for VP8X (extended) bitstream
|
|
48
|
+
if (bytes[12] === 0x56 &&
|
|
49
|
+
bytes[13] === 0x50 &&
|
|
50
|
+
bytes[14] === 0x38 &&
|
|
51
|
+
bytes[15] === 0x58) {
|
|
52
|
+
return {
|
|
53
|
+
width: 1 + (bytes[24] | (bytes[25] << 8) | (bytes[26] << 16)),
|
|
54
|
+
height: 1 + (bytes[27] | (bytes[28] << 8) | (bytes[29] << 16)),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const isWebp = (data) => {
|
|
60
|
+
const webpPattern = new Uint8Array([0x52, 0x49, 0x46, 0x46]);
|
|
61
|
+
if ((0, detect_file_type_1.matchesPattern)(webpPattern)(data.subarray(0, 4))) {
|
|
62
|
+
return {
|
|
63
|
+
type: 'webp',
|
|
64
|
+
dimensions: getWebPDimensions(data),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
};
|
|
69
|
+
exports.isWebp = isWebp;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const detectFileType: (data: Uint8Array) => "webp" | "riff" | "webm" | "iso-base-media" | "transport-stream" | "mp3" | "gif" | "png" | "bmp" | "jpeg" | "unknown";
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectFileType = void 0;
|
|
4
|
+
const make_header_1 = require("./boxes/webm/make-header");
|
|
5
|
+
const matchesPattern = (pattern) => {
|
|
6
|
+
return (data) => {
|
|
7
|
+
return pattern.every((value, index) => data[index] === value);
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
const isRiff = (data) => {
|
|
11
|
+
const riffPattern = new Uint8Array([0x52, 0x49, 0x46, 0x46]);
|
|
12
|
+
return matchesPattern(riffPattern)(data.subarray(0, 4));
|
|
13
|
+
};
|
|
14
|
+
const isWebm = (data) => {
|
|
15
|
+
return matchesPattern(make_header_1.webmPattern)(data.subarray(0, 4));
|
|
16
|
+
};
|
|
17
|
+
const isIsoBaseMedia = (data) => {
|
|
18
|
+
const isoBaseMediaMp4Pattern = new TextEncoder().encode('ftyp');
|
|
19
|
+
return matchesPattern(isoBaseMediaMp4Pattern)(data.subarray(4, 8));
|
|
20
|
+
};
|
|
21
|
+
const isTransportStream = (data) => {
|
|
22
|
+
return data[0] === 0x47 && data[188] === 0x47;
|
|
23
|
+
};
|
|
24
|
+
const isMp3 = (data) => {
|
|
25
|
+
const mpegPattern = new Uint8Array([0xff, 0xf3, 0xe4, 0x64]);
|
|
26
|
+
return matchesPattern(mpegPattern)(data.subarray(0, 4));
|
|
27
|
+
};
|
|
28
|
+
const isGif = (data) => {
|
|
29
|
+
const gifPattern = new Uint8Array([0x47, 0x49, 0x46, 0x38]);
|
|
30
|
+
return matchesPattern(gifPattern)(data.subarray(0, 4));
|
|
31
|
+
};
|
|
32
|
+
const isPng = (data) => {
|
|
33
|
+
const pngPattern = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
34
|
+
return matchesPattern(pngPattern)(data.subarray(0, 4));
|
|
35
|
+
};
|
|
36
|
+
const isBmp = (data) => {
|
|
37
|
+
const bmpPattern = new Uint8Array([0x42, 0x4d]);
|
|
38
|
+
return matchesPattern(bmpPattern)(data.subarray(0, 2));
|
|
39
|
+
};
|
|
40
|
+
const isJpeg = (data) => {
|
|
41
|
+
const jpegPattern = new Uint8Array([0xff, 0xd8]);
|
|
42
|
+
const jpeg = matchesPattern(jpegPattern)(data.subarray(0, 2));
|
|
43
|
+
if (!jpeg) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const width = data[6] * 256 + data[7];
|
|
47
|
+
const height = data[8] * 256 + data[9];
|
|
48
|
+
console.log(width, height);
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
const isWebp = (data) => {
|
|
52
|
+
const webpPattern = new Uint8Array([0x52, 0x49, 0x46, 0x46]);
|
|
53
|
+
return matchesPattern(webpPattern)(data.subarray(0, 4));
|
|
54
|
+
};
|
|
55
|
+
const detectFileType = (data) => {
|
|
56
|
+
if (isWebp(data)) {
|
|
57
|
+
return 'webp';
|
|
58
|
+
}
|
|
59
|
+
if (isRiff(data)) {
|
|
60
|
+
return 'riff';
|
|
61
|
+
}
|
|
62
|
+
if (isWebm(data)) {
|
|
63
|
+
return 'webm';
|
|
64
|
+
}
|
|
65
|
+
if (isIsoBaseMedia(data)) {
|
|
66
|
+
return 'iso-base-media';
|
|
67
|
+
}
|
|
68
|
+
if (isTransportStream(data)) {
|
|
69
|
+
return 'transport-stream';
|
|
70
|
+
}
|
|
71
|
+
if (isMp3(data)) {
|
|
72
|
+
return 'mp3';
|
|
73
|
+
}
|
|
74
|
+
if (isGif(data)) {
|
|
75
|
+
return 'gif';
|
|
76
|
+
}
|
|
77
|
+
if (isPng(data)) {
|
|
78
|
+
return 'png';
|
|
79
|
+
}
|
|
80
|
+
if (isBmp(data)) {
|
|
81
|
+
return 'bmp';
|
|
82
|
+
}
|
|
83
|
+
if (isJpeg(data)) {
|
|
84
|
+
return 'jpeg';
|
|
85
|
+
}
|
|
86
|
+
return 'unknown';
|
|
87
|
+
};
|
|
88
|
+
exports.detectFileType = detectFileType;
|
|
@@ -11,7 +11,7 @@ type AudioCodecInfo = {
|
|
|
11
11
|
secondarySpecificator: number | null;
|
|
12
12
|
description: Uint8Array | undefined;
|
|
13
13
|
};
|
|
14
|
-
export declare const getCodecPrivateFromTrak: (trakBox: TrakBox) => Uint8Array | null;
|
|
14
|
+
export declare const getCodecPrivateFromTrak: (trakBox: TrakBox) => Uint8Array<ArrayBufferLike> | null;
|
|
15
15
|
export declare const getNumberOfChannelsFromTrak: (trak: TrakBox) => number | null;
|
|
16
16
|
export declare const getSampleRate: (trak: TrakBox) => number | null;
|
|
17
17
|
export declare const getAudioCodecFromTrak: (trak: TrakBox) => AudioCodecInfo | null;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Options, ParseMediaCallbacks, ParseMediaFields } from './options';
|
|
2
|
+
export declare const getFieldsFromCallback: <F extends Options<ParseMediaFields>>({ fields, callbacks, }: {
|
|
3
|
+
fields: F;
|
|
4
|
+
callbacks: ParseMediaCallbacks;
|
|
5
|
+
}) => Options<ParseMediaFields>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFieldsFromCallback = void 0;
|
|
4
|
+
const getFieldsFromCallback = ({ fields, callbacks, }) => {
|
|
5
|
+
const newFields = {
|
|
6
|
+
audioCodec: Boolean(callbacks.onAudioCodec),
|
|
7
|
+
container: Boolean(callbacks.onContainer),
|
|
8
|
+
dimensions: Boolean(callbacks.onDimensions),
|
|
9
|
+
durationInSeconds: Boolean(callbacks.onDurationInSeconds),
|
|
10
|
+
fps: Boolean(callbacks.onFps),
|
|
11
|
+
internalStats: Boolean(callbacks.onInternalStats),
|
|
12
|
+
isHdr: Boolean(callbacks.onIsHdr),
|
|
13
|
+
location: Boolean(callbacks.onLocation),
|
|
14
|
+
metadata: Boolean(callbacks.onMetadata),
|
|
15
|
+
mimeType: Boolean(callbacks.onMimeType),
|
|
16
|
+
name: Boolean(callbacks.onName),
|
|
17
|
+
rotation: Boolean(callbacks.onRotation),
|
|
18
|
+
size: Boolean(callbacks.onSize),
|
|
19
|
+
structure: Boolean(callbacks.onStructure),
|
|
20
|
+
tracks: Boolean(callbacks.onTracks),
|
|
21
|
+
unrotatedDimensions: Boolean(callbacks.onUnrotatedDimensions),
|
|
22
|
+
videoCodec: Boolean(callbacks.onVideoCodec),
|
|
23
|
+
...fields,
|
|
24
|
+
};
|
|
25
|
+
return newFields;
|
|
26
|
+
};
|
|
27
|
+
exports.getFieldsFromCallback = getFieldsFromCallback;
|
package/dist/has-all-info.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { Options, ParseMediaFields } from './options';
|
|
2
2
|
import type { Structure } from './parse-result';
|
|
3
3
|
import type { ParserState } from './state/parser-state';
|
|
4
|
-
export declare const getAvailableInfo: (
|
|
4
|
+
export declare const getAvailableInfo: ({ fieldsToFetch, structure, state, }: {
|
|
5
|
+
fieldsToFetch: Options<ParseMediaFields>;
|
|
6
|
+
structure: Structure | null;
|
|
7
|
+
state: ParserState;
|
|
8
|
+
}) => Record<keyof Options<ParseMediaFields>, boolean>;
|
|
5
9
|
export declare const hasAllInfo: ({ fields, state, structure, }: {
|
|
6
10
|
structure: Structure | null;
|
|
7
11
|
fields: Options<ParseMediaFields>;
|
package/dist/has-all-info.js
CHANGED
|
@@ -9,8 +9,8 @@ const get_fps_1 = require("./get-fps");
|
|
|
9
9
|
const get_is_hdr_1 = require("./get-is-hdr");
|
|
10
10
|
const get_tracks_1 = require("./get-tracks");
|
|
11
11
|
const get_video_codec_1 = require("./get-video-codec");
|
|
12
|
-
const getAvailableInfo = (
|
|
13
|
-
const keys = Object.entries(
|
|
12
|
+
const getAvailableInfo = ({ fieldsToFetch, structure, state, }) => {
|
|
13
|
+
const keys = Object.entries(fieldsToFetch).filter(([, value]) => value);
|
|
14
14
|
const infos = keys.map(([_key]) => {
|
|
15
15
|
const key = _key;
|
|
16
16
|
if (key === 'structure') {
|
|
@@ -45,6 +45,9 @@ const getAvailableInfo = (options, structure, state) => {
|
|
|
45
45
|
if (key === 'size') {
|
|
46
46
|
return true;
|
|
47
47
|
}
|
|
48
|
+
if (key === 'mimeType') {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
48
51
|
if (key === 'name') {
|
|
49
52
|
return true;
|
|
50
53
|
}
|
|
@@ -65,7 +68,11 @@ const getAvailableInfo = (options, structure, state) => {
|
|
|
65
68
|
};
|
|
66
69
|
exports.getAvailableInfo = getAvailableInfo;
|
|
67
70
|
const hasAllInfo = ({ fields, state, structure, }) => {
|
|
68
|
-
const availableInfo = (0, exports.getAvailableInfo)(
|
|
71
|
+
const availableInfo = (0, exports.getAvailableInfo)({
|
|
72
|
+
fieldsToFetch: fields !== null && fields !== void 0 ? fields : {},
|
|
73
|
+
structure,
|
|
74
|
+
state,
|
|
75
|
+
});
|
|
69
76
|
return (Object.values(availableInfo).every(Boolean) &&
|
|
70
77
|
(state.maySkipVideoData() || state.canSkipTracksState.canSkipTracks()));
|
|
71
78
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IoEventEmitter } from './create/event-emitter';
|
|
2
2
|
import type { ProgressTracker } from './create/progress-tracker';
|
|
3
3
|
import type { LogLevel } from './log';
|
|
4
|
+
export { IsAGifError, IsAnImageError, IsAnUnsupportedAudioTypeError, IsAnUnsupportedFileTypeError, IsAPdfError, } from './errors';
|
|
4
5
|
export { MetadataEntry } from './metadata/get-metadata';
|
|
5
6
|
export { WriterInterface } from './writers/writer';
|
|
6
7
|
export { AudioTrack, MediaParserAudioCodec, MediaParserVideoCodec, OtherTrack, Track, VideoTrack, VideoTrackColorParams, } from './get-tracks';
|
|
@@ -45,7 +46,7 @@ export declare const MediaParserInternals: {
|
|
|
45
46
|
audioObjectType: number;
|
|
46
47
|
sampleRate: number;
|
|
47
48
|
channelConfiguration: number;
|
|
48
|
-
}) => Uint8Array
|
|
49
|
+
}) => Uint8Array<ArrayBuffer>;
|
|
49
50
|
};
|
|
50
51
|
export type { IoEventEmitter, LogLevel, ProgressTracker };
|
|
51
52
|
export { VERSION } from './version';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VERSION = exports.MediaParserInternals = exports.parseMedia = void 0;
|
|
3
|
+
exports.VERSION = exports.MediaParserInternals = exports.parseMedia = exports.IsAPdfError = exports.IsAnUnsupportedFileTypeError = exports.IsAnUnsupportedAudioTypeError = exports.IsAnImageError = exports.IsAGifError = void 0;
|
|
4
4
|
const aac_codecprivate_1 = require("./aac-codecprivate");
|
|
5
5
|
const event_emitter_1 = require("./create/event-emitter");
|
|
6
6
|
const create_iso_base_media_1 = require("./create/iso-base-media/create-iso-base-media");
|
|
@@ -9,6 +9,12 @@ const progress_tracker_1 = require("./create/progress-tracker");
|
|
|
9
9
|
const create_wav_1 = require("./create/wav/create-wav");
|
|
10
10
|
const with_resolvers_1 = require("./create/with-resolvers");
|
|
11
11
|
const log_1 = require("./log");
|
|
12
|
+
var errors_1 = require("./errors");
|
|
13
|
+
Object.defineProperty(exports, "IsAGifError", { enumerable: true, get: function () { return errors_1.IsAGifError; } });
|
|
14
|
+
Object.defineProperty(exports, "IsAnImageError", { enumerable: true, get: function () { return errors_1.IsAnImageError; } });
|
|
15
|
+
Object.defineProperty(exports, "IsAnUnsupportedAudioTypeError", { enumerable: true, get: function () { return errors_1.IsAnUnsupportedAudioTypeError; } });
|
|
16
|
+
Object.defineProperty(exports, "IsAnUnsupportedFileTypeError", { enumerable: true, get: function () { return errors_1.IsAnUnsupportedFileTypeError; } });
|
|
17
|
+
Object.defineProperty(exports, "IsAPdfError", { enumerable: true, get: function () { return errors_1.IsAPdfError; } });
|
|
12
18
|
var parse_media_1 = require("./parse-media");
|
|
13
19
|
Object.defineProperty(exports, "parseMedia", { enumerable: true, get: function () { return parse_media_1.parseMedia; } });
|
|
14
20
|
exports.MediaParserInternals = {
|