@soga/mp4box 0.5.0 → 1.0.1
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/index.js +1 -88
- package/dist/index.mjs +1 -53
- package/package.json +8 -7
package/dist/index.js
CHANGED
|
@@ -1,88 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
getMp4boxInfo: () => getMp4boxInfo
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(index_exports);
|
|
36
|
-
var import_fs_extra = require("fs-extra");
|
|
37
|
-
var import_mp4box = __toESM(require("mp4box"));
|
|
38
|
-
async function getMp4boxInfo(file_path) {
|
|
39
|
-
const rawInfo = await new Promise((resolve, reject) => {
|
|
40
|
-
try {
|
|
41
|
-
const mp4box = import_mp4box.default.createFile();
|
|
42
|
-
let fileStart = 0;
|
|
43
|
-
const stream = (0, import_fs_extra.createReadStream)(file_path, {
|
|
44
|
-
highWaterMark: 40 * 1024 * 1024
|
|
45
|
-
});
|
|
46
|
-
stream.on("data", (buf) => {
|
|
47
|
-
const arrayBuffer = new Uint8Array(buf).buffer;
|
|
48
|
-
arrayBuffer.fileStart = fileStart;
|
|
49
|
-
fileStart += buf.byteLength;
|
|
50
|
-
mp4box.appendBuffer(arrayBuffer);
|
|
51
|
-
});
|
|
52
|
-
stream.on("end", () => {
|
|
53
|
-
mp4box.flush();
|
|
54
|
-
});
|
|
55
|
-
stream.on("error", (error) => {
|
|
56
|
-
reject(error);
|
|
57
|
-
});
|
|
58
|
-
mp4box.onError = function(e) {
|
|
59
|
-
stream.destroy();
|
|
60
|
-
mp4box.flush();
|
|
61
|
-
reject(e);
|
|
62
|
-
};
|
|
63
|
-
mp4box.onReady = function(info) {
|
|
64
|
-
stream.destroy();
|
|
65
|
-
mp4box.flush();
|
|
66
|
-
resolve(info);
|
|
67
|
-
};
|
|
68
|
-
} catch (error) {
|
|
69
|
-
reject(error);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
const audios = rawInfo.tracks.filter(
|
|
73
|
-
(track) => !!track.audio || track.name == "SoundHandler"
|
|
74
|
-
);
|
|
75
|
-
const videos = rawInfo.tracks.filter(
|
|
76
|
-
(track) => !!track.video || track.name == "VideoHandler"
|
|
77
|
-
);
|
|
78
|
-
return {
|
|
79
|
-
duration: rawInfo.duration,
|
|
80
|
-
mime: rawInfo.mime,
|
|
81
|
-
audios,
|
|
82
|
-
videos
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
-
0 && (module.exports = {
|
|
87
|
-
getMp4boxInfo
|
|
88
|
-
});
|
|
1
|
+
"use strict";var e,r=Object.create,t=Object.defineProperty,o=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,a=Object.getPrototypeOf,i=Object.prototype.hasOwnProperty,u=(e,r,a,u)=>{if(r&&"object"==typeof r||"function"==typeof r)for(let l of n(r))i.call(e,l)||l===a||t(e,l,{get:()=>r[l],enumerable:!(u=o(r,l))||u.enumerable});return e},l={};((e,r)=>{for(var o in r)t(e,o,{get:r[o],enumerable:!0})})(l,{getMp4boxInfo:()=>d}),module.exports=(e=l,u(t({},"__esModule",{value:!0}),e));var s=require("@soga/error"),c=require("fs-extra"),f=((e,o,n)=>(n=null!=e?r(a(e)):{},u(!o&&e&&e.__esModule?n:t(n,"default",{value:e,enumerable:!0}),e)))(require("mp4box"));async function d(e){try{const r=await new Promise((r,t)=>{const o=f.createFile();let n=0;const a=(0,c.createReadStream)(e,{highWaterMark:41943040});a.on("data",e=>{const r=new Uint8Array(e).buffer;r.fileStart=n,n+=e.byteLength,o.appendBuffer(r)}),a.on("end",()=>{o.flush()}),a.on("error",e=>{t(e)}),o.onError=function(e,r){a.destroy(),o.flush(),t(new Error(r))},o.onReady=function(e){a.destroy(),o.flush(),r(e)}}),t=r.tracks.filter(e=>!!e.audio||"SoundHandler"==e.name),o=r.tracks.filter(e=>!!e.video||"VideoHandler"==e.name);return{duration:r.duration,mime:r.mime,audios:t,videos:o}}catch(r){throw(0,s.buildDError)(r,{message:"Failed to get MP4 box info",detail:`Error while processing file: ${e}`})}}
|
package/dist/index.mjs
CHANGED
|
@@ -1,53 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { createReadStream } from "fs-extra";
|
|
3
|
-
import MP4Box from "mp4box";
|
|
4
|
-
async function getMp4boxInfo(file_path) {
|
|
5
|
-
const rawInfo = await new Promise((resolve, reject) => {
|
|
6
|
-
try {
|
|
7
|
-
const mp4box = MP4Box.createFile();
|
|
8
|
-
let fileStart = 0;
|
|
9
|
-
const stream = createReadStream(file_path, {
|
|
10
|
-
highWaterMark: 40 * 1024 * 1024
|
|
11
|
-
});
|
|
12
|
-
stream.on("data", (buf) => {
|
|
13
|
-
const arrayBuffer = new Uint8Array(buf).buffer;
|
|
14
|
-
arrayBuffer.fileStart = fileStart;
|
|
15
|
-
fileStart += buf.byteLength;
|
|
16
|
-
mp4box.appendBuffer(arrayBuffer);
|
|
17
|
-
});
|
|
18
|
-
stream.on("end", () => {
|
|
19
|
-
mp4box.flush();
|
|
20
|
-
});
|
|
21
|
-
stream.on("error", (error) => {
|
|
22
|
-
reject(error);
|
|
23
|
-
});
|
|
24
|
-
mp4box.onError = function(e) {
|
|
25
|
-
stream.destroy();
|
|
26
|
-
mp4box.flush();
|
|
27
|
-
reject(e);
|
|
28
|
-
};
|
|
29
|
-
mp4box.onReady = function(info) {
|
|
30
|
-
stream.destroy();
|
|
31
|
-
mp4box.flush();
|
|
32
|
-
resolve(info);
|
|
33
|
-
};
|
|
34
|
-
} catch (error) {
|
|
35
|
-
reject(error);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
const audios = rawInfo.tracks.filter(
|
|
39
|
-
(track) => !!track.audio || track.name == "SoundHandler"
|
|
40
|
-
);
|
|
41
|
-
const videos = rawInfo.tracks.filter(
|
|
42
|
-
(track) => !!track.video || track.name == "VideoHandler"
|
|
43
|
-
);
|
|
44
|
-
return {
|
|
45
|
-
duration: rawInfo.duration,
|
|
46
|
-
mime: rawInfo.mime,
|
|
47
|
-
audios,
|
|
48
|
-
videos
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
export {
|
|
52
|
-
getMp4boxInfo
|
|
53
|
-
};
|
|
1
|
+
import{buildDError as r}from"@soga/error";import{createReadStream as e}from"fs-extra";import*as o from"mp4box";async function t(t){try{const r=await new Promise((r,n)=>{const a=o.createFile();let i=0;const s=e(t,{highWaterMark:41943040});s.on("data",r=>{const e=new Uint8Array(r).buffer;e.fileStart=i,i+=r.byteLength,a.appendBuffer(e)}),s.on("end",()=>{a.flush()}),s.on("error",r=>{n(r)}),a.onError=function(r,e){s.destroy(),a.flush(),n(new Error(e))},a.onReady=function(e){s.destroy(),a.flush(),r(e)}}),n=r.tracks.filter(r=>!!r.audio||"SoundHandler"==r.name),a=r.tracks.filter(r=>!!r.video||"VideoHandler"==r.name);return{duration:r.duration,mime:r.mime,audios:n,videos:a}}catch(e){throw r(e,{message:"Failed to get MP4 box info",detail:`Error while processing file: ${t}`})}}export{t as getMp4boxInfo};
|
package/package.json
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "1.0.1",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"module": "./dist/index.mjs",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"scripts": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
11
|
+
"demo": "tsx ./demo/demo.ts",
|
|
12
|
+
"build": "rimraf dist && tsup src/index.ts --format cjs,esm --dts --minify terser",
|
|
13
|
+
"prepublishOnly": "npm run build"
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
15
16
|
"dist"
|
|
@@ -19,13 +20,13 @@
|
|
|
19
20
|
"license": "ISC",
|
|
20
21
|
"description": "",
|
|
21
22
|
"dependencies": {
|
|
23
|
+
"@soga/error": "^1.0.0",
|
|
22
24
|
"fs-extra": "^11.3.0",
|
|
23
|
-
"mp4box": "^
|
|
24
|
-
"
|
|
25
|
+
"mp4box": "^1.4.4",
|
|
26
|
+
"glob": "^11.0.3"
|
|
25
27
|
},
|
|
26
28
|
"devDependencies": {
|
|
27
29
|
"@types/fs-extra": "^11.0.4",
|
|
28
30
|
"rimraf": "^6.0.1"
|
|
29
|
-
}
|
|
30
|
-
"prepublishOnly": "npm run build"
|
|
31
|
+
}
|
|
31
32
|
}
|