@soga/mediainfo 0.3.0 → 0.4.0
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/package.json +12 -20
- package/src/index.ts +238 -0
- package/tsconfig.json +8 -0
- package/README.md +0 -5
- package/dist/m3u8.d.ts +0 -6
- package/dist/m3u8.js +0 -1
- package/dist/m3u8.types.d.ts +0 -35
- package/dist/m3u8.types.js +0 -1
- package/dist/main.d.ts +0 -8
- package/dist/main.js +0 -1
- package/dist/mediainfo.d.ts +0 -8
- package/dist/mediainfo.js +0 -1
- package/dist/mediainfo.types.d.ts +0 -52
- package/dist/mediainfo.types.js +0 -1
- package/dist/mp4box.d.ts +0 -7
- package/dist/mp4box.js +0 -1
- package/dist/mp4box.types.d.ts +0 -75
- package/dist/mp4box.types.js +0 -1
- package/dist/resolution.d.ts +0 -6
- package/dist/resolution.js +0 -1
- package/dist/resolution.types.d.ts +0 -11
- package/dist/resolution.types.js +0 -1
package/package.json
CHANGED
|
@@ -1,31 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soga/mediainfo",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
9
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch"
|
|
6
10
|
},
|
|
7
|
-
"description": "",
|
|
8
|
-
"main": "dist/main.js",
|
|
9
|
-
"types": "dist/main.d.ts",
|
|
10
|
-
"files": [
|
|
11
|
-
"dist"
|
|
12
|
-
],
|
|
13
11
|
"keywords": [],
|
|
14
12
|
"author": "",
|
|
15
13
|
"license": "ISC",
|
|
14
|
+
"description": "",
|
|
16
15
|
"dependencies": {
|
|
17
|
-
"@soga/types": "^0.3.0",
|
|
18
16
|
"fs-extra": "^11.3.0",
|
|
19
|
-
"m3u8-parser": "^7.2.0",
|
|
20
17
|
"mediainfo.js": "^0.3.5",
|
|
21
|
-
"
|
|
18
|
+
"tsup": "^8.5.0"
|
|
22
19
|
},
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"minify": "ts-node ./scripts/minify",
|
|
26
|
-
"demo": "ts-node ./demo/demo.ts",
|
|
27
|
-
"test": "jest",
|
|
28
|
-
"dev": "ts-node ./src/main.ts",
|
|
29
|
-
"lint": "eslint . --ext .ts"
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/fs-extra": "^11.0.4"
|
|
30
22
|
}
|
|
31
|
-
}
|
|
23
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { createReadStream } from "fs-extra";
|
|
2
|
+
import { stat } from "fs/promises";
|
|
3
|
+
import getMediainfo, { FormatType, MediaInfo } from "mediainfo.js";
|
|
4
|
+
|
|
5
|
+
export async function parseMediaRaw(media_path: string) {
|
|
6
|
+
const mediainfo: MediaInfo<FormatType> = await getMediainfo({
|
|
7
|
+
format: "JSON" as FormatType,
|
|
8
|
+
});
|
|
9
|
+
const fileList = typeof media_path === "string" ? [media_path] : media_path;
|
|
10
|
+
let total = 0;
|
|
11
|
+
const arr = [] as {
|
|
12
|
+
index: number;
|
|
13
|
+
start: number;
|
|
14
|
+
end: number;
|
|
15
|
+
size: number;
|
|
16
|
+
file_path: string;
|
|
17
|
+
}[];
|
|
18
|
+
for await (const [index, file_path] of fileList.entries()) {
|
|
19
|
+
const { size } = await stat(file_path);
|
|
20
|
+
arr.push({
|
|
21
|
+
index,
|
|
22
|
+
start: total,
|
|
23
|
+
end: total + size - 1,
|
|
24
|
+
size,
|
|
25
|
+
file_path,
|
|
26
|
+
});
|
|
27
|
+
total += size;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const getBuffer = async (size: number, offset: number) => {
|
|
31
|
+
if (!size) {
|
|
32
|
+
return new Uint8Array(0);
|
|
33
|
+
}
|
|
34
|
+
const start = offset;
|
|
35
|
+
const end = offset + size - 1;
|
|
36
|
+
const first = arr.find((item) => item.start <= start && item.end >= start);
|
|
37
|
+
const last = arr.find((item) => item.start <= end && item.end >= end);
|
|
38
|
+
if (!first || !last) {
|
|
39
|
+
return new Uint8Array(0);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const list = [] as {
|
|
43
|
+
index: number;
|
|
44
|
+
file_path: string;
|
|
45
|
+
from: number;
|
|
46
|
+
to: number;
|
|
47
|
+
}[];
|
|
48
|
+
if (first.index === last.index) {
|
|
49
|
+
list.push({
|
|
50
|
+
index: first.index,
|
|
51
|
+
file_path: first.file_path,
|
|
52
|
+
from: start - first.start,
|
|
53
|
+
to: end - first.start,
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
list.push({
|
|
57
|
+
index: first.index,
|
|
58
|
+
file_path: first.file_path,
|
|
59
|
+
from: start - first.start,
|
|
60
|
+
to: first.end,
|
|
61
|
+
});
|
|
62
|
+
for (let i = first.index + 1; i < last.index; i++) {
|
|
63
|
+
const item = arr[i];
|
|
64
|
+
if (item) {
|
|
65
|
+
list.push({
|
|
66
|
+
index: item.index,
|
|
67
|
+
file_path: item.file_path,
|
|
68
|
+
from: 0,
|
|
69
|
+
to: item.size - 1,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
list.push({
|
|
74
|
+
index: last.index,
|
|
75
|
+
file_path: last.file_path,
|
|
76
|
+
from: 0,
|
|
77
|
+
to: end - last.start,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const buffers = [] as Buffer[];
|
|
81
|
+
for await (const item of list) {
|
|
82
|
+
const { file_path, from, to } = item;
|
|
83
|
+
const stream = createReadStream(file_path, { start: from, end: to });
|
|
84
|
+
for await (const data of stream) {
|
|
85
|
+
buffers.push(data);
|
|
86
|
+
}
|
|
87
|
+
stream.close();
|
|
88
|
+
}
|
|
89
|
+
const buffer = Buffer.concat(buffers);
|
|
90
|
+
return buffer;
|
|
91
|
+
};
|
|
92
|
+
const data = await mediainfo.analyzeData(() => total, getBuffer);
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const rawJson = JSON.parse(data as string);
|
|
96
|
+
return rawJson;
|
|
97
|
+
} catch (err) {
|
|
98
|
+
// const text = (data as string).replace(
|
|
99
|
+
// '"Menu","":{}]}]}',
|
|
100
|
+
// '"Menu","":{}}]}',
|
|
101
|
+
// );
|
|
102
|
+
const text = (data as string).replace(',"":{}]}]}', ',"":{}}]}');
|
|
103
|
+
const rawJson = JSON.parse(text);
|
|
104
|
+
return rawJson;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export async function parseMediaInfo(media_path: string) {
|
|
109
|
+
const raw = await parseMediaRaw(media_path);
|
|
110
|
+
const rawMediainfo = raw.media;
|
|
111
|
+
const list = rawMediainfo.track;
|
|
112
|
+
const info = {
|
|
113
|
+
audio: [] as AudioTrackInfo[],
|
|
114
|
+
video: [] as VideoTrackInfo[],
|
|
115
|
+
text: [] as TextTrackInfo[],
|
|
116
|
+
general: {} as GeneralInfo,
|
|
117
|
+
};
|
|
118
|
+
let audioOrder = 0;
|
|
119
|
+
let videoOrder = 0;
|
|
120
|
+
let textOrder = 0;
|
|
121
|
+
list.forEach((item: any) => {
|
|
122
|
+
const type = item["@type"];
|
|
123
|
+
if (type === "Audio") {
|
|
124
|
+
info.audio.push({
|
|
125
|
+
is_default: item.Default === "Yes",
|
|
126
|
+
codec: item.Format.toLowerCase(),
|
|
127
|
+
// order: Number(item.StreamOrder),
|
|
128
|
+
order: audioOrder++,
|
|
129
|
+
// size: Number(item.StreamSize),
|
|
130
|
+
bitrate: Number(item.BitRate),
|
|
131
|
+
framerate: Number(item.FrameRate),
|
|
132
|
+
sample_rate: Number(item.SamplingRate),
|
|
133
|
+
duration: Number(item.Duration),
|
|
134
|
+
channels: Number(item.Channels),
|
|
135
|
+
lossless: item.Compression_Mode === "Lossless",
|
|
136
|
+
});
|
|
137
|
+
} else if (type === "Text") {
|
|
138
|
+
info.text.push({
|
|
139
|
+
is_default: item.Default === "Yes",
|
|
140
|
+
codec: item.Format.toLowerCase(),
|
|
141
|
+
// order: Number(item.StreamOrder),
|
|
142
|
+
order: textOrder++,
|
|
143
|
+
duration: Number(item.Duration),
|
|
144
|
+
title: item.Title || item.Language,
|
|
145
|
+
language: item.Language,
|
|
146
|
+
});
|
|
147
|
+
} else if (type === "Video") {
|
|
148
|
+
info.video.push({
|
|
149
|
+
is_default: item.Default === "Yes",
|
|
150
|
+
codec: item.Format.toLowerCase(),
|
|
151
|
+
order: videoOrder++,
|
|
152
|
+
width: Number(item.Width),
|
|
153
|
+
height: Number(item.Height),
|
|
154
|
+
profile: item.Format_Profile,
|
|
155
|
+
bitrate: Number(item.BitRate),
|
|
156
|
+
framerate: Number(item.FrameRate)
|
|
157
|
+
? Math.round(Number(item.FrameRate))
|
|
158
|
+
: 0,
|
|
159
|
+
// sample_rate: Number(item.SamplingRate),
|
|
160
|
+
duration: Number(item.Duration),
|
|
161
|
+
bitdepth: Number(item.BitDepth),
|
|
162
|
+
format_profile: item.Format_Profile,
|
|
163
|
+
format_tier: item.Format_Tier,
|
|
164
|
+
});
|
|
165
|
+
} else if (type === "General") {
|
|
166
|
+
info.general = {
|
|
167
|
+
audioCount: Number(item.AudioCount),
|
|
168
|
+
textCount: Number(item.TextCount) || 0,
|
|
169
|
+
videoCount: Number(item.VideoCount),
|
|
170
|
+
fileSize: Number(item.FileSize),
|
|
171
|
+
title: item.Title || "",
|
|
172
|
+
duration: Number(item.Duration),
|
|
173
|
+
codec: item.Format,
|
|
174
|
+
};
|
|
175
|
+
if (!info.general.duration && item.extra?.duration) {
|
|
176
|
+
info.general.duration = Number(item.extra.duration);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
return info;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export type GeneralInfo = {
|
|
185
|
+
audioCount: number;
|
|
186
|
+
videoCount: number;
|
|
187
|
+
textCount: number;
|
|
188
|
+
fileSize: number;
|
|
189
|
+
codec: string;
|
|
190
|
+
title: string;
|
|
191
|
+
duration: number;
|
|
192
|
+
extra?: {
|
|
193
|
+
duration: string;
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
export type AudioTrackInfo = {
|
|
197
|
+
is_default: boolean;
|
|
198
|
+
order: number;
|
|
199
|
+
codec: string;
|
|
200
|
+
bitrate: number;
|
|
201
|
+
framerate: number;
|
|
202
|
+
sample_rate: number;
|
|
203
|
+
channels: number;
|
|
204
|
+
duration: number;
|
|
205
|
+
lossless: boolean;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
export type VideoTrackInfo = {
|
|
209
|
+
is_default: boolean;
|
|
210
|
+
order: number;
|
|
211
|
+
width: number;
|
|
212
|
+
height: number;
|
|
213
|
+
codec: string;
|
|
214
|
+
profile: string;
|
|
215
|
+
framerate: number;
|
|
216
|
+
bitrate: number;
|
|
217
|
+
duration: number;
|
|
218
|
+
bitdepth: number;
|
|
219
|
+
format_profile: string;
|
|
220
|
+
format_tier: string;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export type TextTrackInfo = {
|
|
224
|
+
is_default: boolean;
|
|
225
|
+
codec: string;
|
|
226
|
+
order: number;
|
|
227
|
+
duration: number;
|
|
228
|
+
language?: string;
|
|
229
|
+
title?: string;
|
|
230
|
+
is_vtt?: boolean;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
export type Mediainfo = {
|
|
234
|
+
general?: GeneralInfo;
|
|
235
|
+
audio?: AudioTrackInfo[];
|
|
236
|
+
video?: VideoTrackInfo[];
|
|
237
|
+
text?: TextTrackInfo[];
|
|
238
|
+
};
|
package/tsconfig.json
ADDED
package/README.md
DELETED
package/dist/m3u8.d.ts
DELETED
package/dist/m3u8.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.parseM3U8=parseM3U8;const fs_extra_1=require("fs-extra"),m3u8_parser_1=require("m3u8-parser"),path_1=require("path");async function parseM3U8(e){const t=Date.now(),r=new m3u8_parser_1.Parser,s=await(0,fs_extra_1.readFile)(e,"utf8");r.push(s),r.end();const a=r.manifest,i=(0,path_1.dirname)(e),n=a.segments[0].map.uri,u=(0,path_1.resolve)(i,n),_={uri:n,folder:i,file_path:u,size:(await(0,fs_extra_1.stat)(u)).size};let o=0;const p=1e6,d=[],{length:f}=a.segments;for(let e=0;e<f;e++){const t=a.segments[e],r=(0,path_1.resolve)(i,t.uri),s=await(0,fs_extra_1.stat)(r),u=t.duration*p,_=o/p,f=(o+u)/p;d.push({index:e,duration:t.duration,init_uri:n,uri:t.uri,file_path:r,size:s.size,start_time:_,end_time:f,folder:i}),o+=u}const l={init:_,...a,segments:d};return{duration:Date.now()-t,data:l,input:e}}
|
package/dist/m3u8.types.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
type CommonManifest = {
|
|
2
|
-
version: number;
|
|
3
|
-
targetDuration: number;
|
|
4
|
-
mediaSequence: number;
|
|
5
|
-
endList: boolean;
|
|
6
|
-
};
|
|
7
|
-
export type M3U8RawManifest = CommonManifest & {
|
|
8
|
-
segments: {
|
|
9
|
-
duration: number;
|
|
10
|
-
uri: string;
|
|
11
|
-
map: {
|
|
12
|
-
uri: string;
|
|
13
|
-
};
|
|
14
|
-
}[];
|
|
15
|
-
};
|
|
16
|
-
export type M3U8SegmentInfo = {
|
|
17
|
-
index: number;
|
|
18
|
-
duration: number;
|
|
19
|
-
init_uri: string;
|
|
20
|
-
uri: string;
|
|
21
|
-
file_path: string;
|
|
22
|
-
folder: string;
|
|
23
|
-
size: number;
|
|
24
|
-
start_time: number;
|
|
25
|
-
end_time: number;
|
|
26
|
-
};
|
|
27
|
-
export type M3U8Manifest = CommonManifest & {
|
|
28
|
-
init: {
|
|
29
|
-
uri: string;
|
|
30
|
-
file_path: string;
|
|
31
|
-
size: number;
|
|
32
|
-
};
|
|
33
|
-
segments: M3U8SegmentInfo[];
|
|
34
|
-
};
|
|
35
|
-
export {};
|
package/dist/m3u8.types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/main.d.ts
DELETED
package/dist/main.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var i=Object.getOwnPropertyDescriptor(r,t);i&&!("get"in i?!r.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,i)}:function(e,r,t,o){void 0===o&&(o=t),e[o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./mediainfo"),exports),__exportStar(require("./mediainfo.types"),exports),__exportStar(require("./mp4box"),exports),__exportStar(require("./mp4box.types"),exports),__exportStar(require("./resolution"),exports),__exportStar(require("./resolution.types"),exports),__exportStar(require("./m3u8"),exports),__exportStar(require("./m3u8.types"),exports);
|
package/dist/mediainfo.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Mediainfo } from './mediainfo.types';
|
|
2
|
-
import { RecordType } from '@soga/types';
|
|
3
|
-
export declare function parseMediaRaw(media_path: string): Promise<any>;
|
|
4
|
-
export declare function parseMediaInfo(media_path: string): Promise<Mediainfo>;
|
|
5
|
-
export declare function judgeMediaType(filepath: string): Promise<RecordType.VIDEO | RecordType.AUDIO>;
|
|
6
|
-
export declare const isVideoSupport: (format: string) => boolean;
|
|
7
|
-
export declare const isAudioAdapt: (codec: string) => boolean;
|
|
8
|
-
export declare const isAudioHigh: (codec: string) => boolean;
|
package/dist/mediainfo.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.isAudioHigh=exports.isAudioAdapt=exports.isVideoSupport=void 0,exports.parseMediaRaw=parseMediaRaw,exports.parseMediaInfo=parseMediaInfo,exports.judgeMediaType=judgeMediaType;const fs_1=require("fs"),promises_1=require("fs/promises"),mediainfo_js_1=__importDefault(require("mediainfo.js")),types_1=require("@soga/types");async function parseMediaRaw(e){const t=await(0,mediainfo_js_1.default)({format:"JSON"}),a="string"==typeof e?[e]:e;let r=0;const i=[];for await(const[e,t]of a.entries()){const a=(await(0,promises_1.stat)(t)).size;i.push({index:e,start:r,end:r+a-1,size:a,file_path:t}),r+=a}const o=await t.analyzeData((()=>r),(async(e,t)=>{if(!e)return new Uint8Array(0);const a=t,r=t+e-1,o=i.find((e=>e.start<=a&&e.end>=a)),s=i.find((e=>e.start<=r&&e.end>=r));if(!o||!s)return new Uint8Array(0);const n=[];if(o.index===s.index)n.push({index:o.index,file_path:o.file_path,from:a-o.start,to:r-o.start});else{n.push({index:o.index,file_path:o.file_path,from:a-o.start,to:o.end});for(let e=o.index+1;e<s.index;e++){const t=i[e];n.push({index:t.index,file_path:t.file_path,from:0,to:t.size-1})}n.push({index:s.index,file_path:s.file_path,from:0,to:r-s.start})}const u=[];for await(const e of n){const{file_path:t,from:a,to:r}=e,i=(0,fs_1.createReadStream)(t,{start:a,end:r});for await(const e of i)u.push(e);i.close()}return Buffer.concat(u)}));try{return JSON.parse(o)}catch(e){const t=o.replace(',"":{}]}]}',',"":{}}]}');return JSON.parse(t)}}async function parseMediaInfo(e){const t=(await parseMediaRaw(e)).media.track,a={audio:[],video:[],text:[],general:{}};let r=0,i=0,o=0;return t.forEach((e=>{const t=e["@type"];"Audio"===t?a.audio.push({is_default:"Yes"===e.Default,codec:e.Format.toLowerCase(),order:r++,bitrate:Number(e.BitRate),framerate:Number(e.FrameRate),sample_rate:Number(e.SamplingRate),duration:Number(e.Duration),channels:Number(e.Channels),lossless:"Lossless"===e.Compression_Mode}):"Text"===t?a.text.push({is_default:"Yes"===e.Default,codec:e.Format.toLowerCase(),order:o++,duration:Number(e.Duration),title:e.Title||e.Language,language:e.Language}):"Video"===t?a.video.push({is_default:"Yes"===e.Default,codec:e.Format.toLowerCase(),order:i++,width:Number(e.Width),height:Number(e.Height),profile:e.Format_Profile,bitrate:Number(e.BitRate),framerate:Number(e.FrameRate)?Math.round(Number(e.FrameRate)):void 0,duration:Number(e.Duration),bitdepth:Number(e.BitDepth),format_profile:e.Format_Profile,format_tier:e.Format_Tier}):"General"===t&&(a.general={audioCount:Number(e.AudioCount),textCount:Number(e.TextCount)||0,videoCount:Number(e.VideoCount),fileSize:Number(e.FileSize),title:e.Title||"",duration:Number(e.Duration),codec:e.Format},!a.general.duration&&e.extra?.duration&&(a.general.duration=Number(e.extra.duration)))})),a}async function judgeMediaType(e){const t=await parseMediaInfo(e);return t?.video?.length?types_1.RecordType.VIDEO:types_1.RecordType.AUDIO}const isVideoSupport=e=>["avc","h264","avc1","hevc","h265"].includes(e);exports.isVideoSupport=isVideoSupport;const isAudioAdapt=e=>["aac","mp3"].includes(e);exports.isAudioAdapt=isAudioAdapt;const isAudioHigh=e=>["flac"].includes(e);exports.isAudioHigh=isAudioHigh;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export type GeneralInfo = {
|
|
2
|
-
audioCount: number;
|
|
3
|
-
videoCount: number;
|
|
4
|
-
textCount: number;
|
|
5
|
-
fileSize: number;
|
|
6
|
-
codec: string;
|
|
7
|
-
title: string;
|
|
8
|
-
duration: number;
|
|
9
|
-
extra?: {
|
|
10
|
-
duration: string;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
export type AudioTrackInfo = {
|
|
14
|
-
is_default: boolean;
|
|
15
|
-
order: number;
|
|
16
|
-
codec: string;
|
|
17
|
-
bitrate: number;
|
|
18
|
-
framerate: number;
|
|
19
|
-
sample_rate: number;
|
|
20
|
-
channels: number;
|
|
21
|
-
duration: number;
|
|
22
|
-
lossless: boolean;
|
|
23
|
-
};
|
|
24
|
-
export type VideoTrackInfo = {
|
|
25
|
-
is_default: boolean;
|
|
26
|
-
order: number;
|
|
27
|
-
width: number;
|
|
28
|
-
height: number;
|
|
29
|
-
codec: string;
|
|
30
|
-
profile: string;
|
|
31
|
-
framerate: number;
|
|
32
|
-
bitrate: number;
|
|
33
|
-
duration: number;
|
|
34
|
-
bitdepth: number;
|
|
35
|
-
format_profile: string;
|
|
36
|
-
format_tier: string;
|
|
37
|
-
};
|
|
38
|
-
export type TextTrackInfo = {
|
|
39
|
-
is_default: boolean;
|
|
40
|
-
codec: string;
|
|
41
|
-
order: number;
|
|
42
|
-
duration: number;
|
|
43
|
-
language?: string;
|
|
44
|
-
title?: string;
|
|
45
|
-
is_vtt?: boolean;
|
|
46
|
-
};
|
|
47
|
-
export type Mediainfo = {
|
|
48
|
-
general?: GeneralInfo;
|
|
49
|
-
audio?: AudioTrackInfo[];
|
|
50
|
-
video?: VideoTrackInfo[];
|
|
51
|
-
text?: TextTrackInfo[];
|
|
52
|
-
};
|
package/dist/mediainfo.types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/mp4box.d.ts
DELETED
package/dist/mp4box.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getMp4boxInfo=getMp4boxInfo;const fs_extra_1=require("fs-extra"),mp4box_1=__importDefault(require("mp4box"));async function getMp4boxInfo(e){const t=await new Promise(((t,r)=>{const o=mp4box_1.default.createFile();let n=0;const a=(0,fs_extra_1.createReadStream)(e,{highWaterMark:41943040});a.on("data",(e=>{const t=new Uint8Array(e).buffer;t.fileStart=n,n+=e.byteLength,o.appendBuffer(t)})),a.on("end",(()=>{o.flush()})),a.on("error",(e=>{r(e)})),o.onError=function(e){a.destroy(),o.flush(),r(e)},o.onReady=function(e){a.destroy(),o.flush(),t(e)}})),r=t.tracks.filter((e=>!!e.audio||"SoundHandler"==e.name)),o=t.tracks.filter((e=>!!e.video||"VideoHandler"==e.name));return{duration:t.duration,mime:t.mime,audios:r,videos:o}}
|
package/dist/mp4box.types.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
export type Mp4boxVideoInfo = {
|
|
2
|
-
id: number;
|
|
3
|
-
name?: 'VideoHandler';
|
|
4
|
-
references: any[];
|
|
5
|
-
edits: {
|
|
6
|
-
segment_duration: number;
|
|
7
|
-
media_time: number;
|
|
8
|
-
media_rate_integer: number;
|
|
9
|
-
media_rate_fraction: number;
|
|
10
|
-
}[];
|
|
11
|
-
created: string;
|
|
12
|
-
modified: string;
|
|
13
|
-
movie_duration: number;
|
|
14
|
-
movie_timescale: number;
|
|
15
|
-
layer: number;
|
|
16
|
-
alternate_group: number;
|
|
17
|
-
volume: number;
|
|
18
|
-
track_width: number;
|
|
19
|
-
track_height: number;
|
|
20
|
-
timescale: number;
|
|
21
|
-
duration: number;
|
|
22
|
-
samples_duration: number;
|
|
23
|
-
codec: string;
|
|
24
|
-
kind: {
|
|
25
|
-
schemeURI: string;
|
|
26
|
-
value: string;
|
|
27
|
-
};
|
|
28
|
-
language: string;
|
|
29
|
-
nb_samples: number;
|
|
30
|
-
size: number;
|
|
31
|
-
bitrate: number;
|
|
32
|
-
type: 'video';
|
|
33
|
-
video: {
|
|
34
|
-
width: number;
|
|
35
|
-
height: number;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
export type Mp4boxAudioInfo = {
|
|
39
|
-
id: number;
|
|
40
|
-
name?: 'SoundHandler';
|
|
41
|
-
references: any[];
|
|
42
|
-
edits: {
|
|
43
|
-
segment_duration: number;
|
|
44
|
-
media_time: number;
|
|
45
|
-
media_rate_integer: number;
|
|
46
|
-
media_rate_fraction: number;
|
|
47
|
-
}[];
|
|
48
|
-
created: string;
|
|
49
|
-
modified: string;
|
|
50
|
-
movie_duration: number;
|
|
51
|
-
movie_timescale: number;
|
|
52
|
-
layer: number;
|
|
53
|
-
alternate_group: number;
|
|
54
|
-
volume: number;
|
|
55
|
-
track_width: number;
|
|
56
|
-
track_height: number;
|
|
57
|
-
timescale: number;
|
|
58
|
-
duration: number;
|
|
59
|
-
samples_duration: number;
|
|
60
|
-
codec: string;
|
|
61
|
-
kind: {
|
|
62
|
-
schemeURI: string;
|
|
63
|
-
value: string;
|
|
64
|
-
};
|
|
65
|
-
language: string;
|
|
66
|
-
nb_samples: number;
|
|
67
|
-
size: number;
|
|
68
|
-
bitrate: number;
|
|
69
|
-
type: 'audio';
|
|
70
|
-
audio: {
|
|
71
|
-
sample_rate: number;
|
|
72
|
-
channel_count: number;
|
|
73
|
-
sample_size: number;
|
|
74
|
-
};
|
|
75
|
-
};
|
package/dist/mp4box.types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/resolution.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { StandardItem } from './resolution.types';
|
|
2
|
-
export declare function getVideoStandard(width: number, height: number): {
|
|
3
|
-
standard: StandardItem;
|
|
4
|
-
adapts: StandardItem[];
|
|
5
|
-
};
|
|
6
|
-
export declare const getStandardInfo: (width: number, height: number) => StandardItem;
|
package/dist/resolution.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getStandardInfo=void 0,exports.getVideoStandard=getVideoStandard;const resolutionMap=new Map,horizontal_resolutions=[{key:"h_p360",is_horizontal:!0,width:640,height:360,label:"360p",tag:"",edge:"width",codec:"libx264"},{key:"h_p540",is_horizontal:!0,width:960,height:540,label:"540p",tag:"",edge:"width",codec:"libx264"},{key:"h_p720",is_horizontal:!0,width:1280,height:720,label:"720p",tag:"",edge:"width",codec:"libx264"},{key:"h_p1080",is_horizontal:!0,width:1920,height:1080,label:"1080p",tag:"HD",edge:"width",codec:"libx264"},{key:"h_p1440",is_horizontal:!0,width:2560,height:1440,label:"1440p",tag:"HD",edge:"width",codec:"libx265"},{key:"h_k4",is_horizontal:!0,width:3840,height:2160,label:"2160p",tag:"4K",edge:"width",codec:"libx265"},{key:"h_k8",is_horizontal:!0,width:7680,height:4320,label:"4320p",tag:"8K",edge:"width",codec:"libx265"},{key:"h_k16",is_horizontal:!0,width:15360,height:8640,label:"16K",tag:"",edge:"width",codec:"libx265"},{key:"h_k32",is_horizontal:!0,width:30720,height:17280,label:"32K",tag:"32K",edge:"width",codec:"libx265"},{key:"h_k32plus",is_horizontal:!0,width:61440,height:34560,label:"64K",tag:"",edge:"width",codec:"libx265"}],vertical_resolutions=[{key:"v_p360",is_horizontal:!1,height:640,width:360,label:"360p",tag:"",edge:"height",codec:"libx264"},{key:"v_p540",is_horizontal:!1,height:960,width:540,label:"540p",tag:"",edge:"height",codec:"libx264"},{key:"v_p720",is_horizontal:!1,height:1280,width:720,label:"720p",tag:"",edge:"height",codec:"libx264"},{key:"v_p1080",is_horizontal:!1,height:1920,width:1080,label:"1080p",tag:"HD",edge:"height",codec:"libx264"},{key:"v_p1440",is_horizontal:!1,height:2560,width:1440,label:"1440p",tag:"HD",edge:"height",codec:"libx265"},{key:"v_k4",is_horizontal:!1,height:3840,width:2160,label:"2160p",tag:"4K",edge:"height",codec:"libx265"},{key:"v_k8",is_horizontal:!1,height:7680,width:4320,label:"4320p",tag:"8K",edge:"height",codec:"libx265"},{key:"v_k16",is_horizontal:!1,height:15360,width:8640,label:"16K",tag:"",edge:"height",codec:"libx265"},{key:"v_k32",is_horizontal:!1,height:30720,width:17280,label:"32K",tag:"32K",edge:"height",codec:"libx265"},{key:"v_k32plus",is_horizontal:!1,height:61440,width:34560,label:"64K",tag:"",edge:"height",codec:"libx265"}];function getVideoStandard(e,t){if(e<t){const i=[],h=[],{length:o}=vertical_resolutions;for(let l=0;l<o;l++){const o=vertical_resolutions[l],a=t>=.9*vertical_resolutions[l].height,d=e>=.9*vertical_resolutions[l].width;if(a&&i.unshift({...o,edge:"height"}),d&&h.unshift({...o,edge:"width"}),!a&&!d)break}const l=i.shift()??vertical_resolutions[0],a=h.shift()??vertical_resolutions[0],d=l.height>a.height;return{standard:d?l:a,adapts:d?i:h}}{const i=[],h=[],{length:o}=horizontal_resolutions;for(let l=0;l<o;l++){const o=horizontal_resolutions[l],a=e>=.9*horizontal_resolutions[l].width,d=t>=.9*horizontal_resolutions[l].height;if(a&&i.unshift({...o,edge:"width"}),d&&h.unshift({...o,edge:"height"}),!a&&!d)break}const l=i.shift()??horizontal_resolutions[0],a=h.shift()??horizontal_resolutions[0],d=l.width>a.width;return{standard:d?l:a,adapts:d?i:h}}}horizontal_resolutions.forEach((e=>{resolutionMap.set(`horizontal_${e.width}`,e)})),vertical_resolutions.forEach((e=>{resolutionMap.set(`vertical_${e.height}`,e)}));const getStandardInfo=(e,t)=>{const{standard:i}=getVideoStandard(e,t);return i};exports.getStandardInfo=getStandardInfo;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type StandardKey = 'h_p360' | 'h_p540' | 'h_p720' | 'h_p1080' | 'h_p1440' | 'h_k4' | 'h_k8' | 'h_k16' | 'h_k32' | 'h_k32plus' | 'v_p360' | 'v_p540' | 'v_p720' | 'v_p1080' | 'v_p1440' | 'v_k4' | 'v_k8' | 'v_k16' | 'v_k32' | 'v_k32plus';
|
|
2
|
-
export type StandardItem = {
|
|
3
|
-
key: StandardKey;
|
|
4
|
-
is_horizontal: boolean;
|
|
5
|
-
width: number;
|
|
6
|
-
height: number;
|
|
7
|
-
label: string;
|
|
8
|
-
tag: string;
|
|
9
|
-
edge: 'width' | 'height';
|
|
10
|
-
codec: string;
|
|
11
|
-
};
|
package/dist/resolution.types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|