@soga/mediainfo 0.0.1 → 0.0.3
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/main.d.ts +2 -0
- package/dist/main.js +1 -1
- package/dist/mediainfo.d.ts +5 -5
- package/dist/mediainfo.js +1 -1
- package/dist/mediainfo.types.d.ts +1 -1
- package/dist/mp4box.d.ts +7 -0
- package/dist/mp4box.js +1 -0
- package/dist/mp4box.types.d.ts +75 -0
- package/dist/mp4box.types.js +1 -0
- package/package.json +3 -2
package/dist/main.d.ts
CHANGED
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,o)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./mediainfo"),exports),__exportStar(require("./mediainfo.types"),exports);
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,o)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./mediainfo"),exports),__exportStar(require("./mediainfo.types"),exports),__exportStar(require("./mp4box"),exports),__exportStar(require("./mp4box.types"),exports);
|
package/dist/mediainfo.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Mediainfo } from './mediainfo.types';
|
|
2
2
|
export declare function parseMediaRaw(media_path: string): Promise<any>;
|
|
3
|
-
export declare function parseMediaInfo(media_path: string): Promise<
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
3
|
+
export declare function parseMediaInfo(media_path: string): Promise<Mediainfo>;
|
|
4
|
+
export declare const isVideoSupport: (format: string) => boolean;
|
|
5
|
+
export declare const isAudioAdapt: (codec: string) => boolean;
|
|
6
|
+
export declare const isAudioHigh: (codec: string) => boolean;
|
package/dist/mediainfo.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.
|
|
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;const fs_1=require("fs"),promises_1=require("fs/promises"),mediainfo_js_1=__importDefault(require("mediainfo.js"));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('"Menu","":{}]}]}','"Menu","":{}}]}');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}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;
|
package/dist/mp4box.d.ts
ADDED
package/dist/mp4box.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
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(0,fs_extra_1.readFile)(e),r=new Uint8Array(t).buffer;r.fileStart=0;const o=await new Promise(((e,t)=>{const o=mp4box_1.default.createFile();o.onError=function(e){t(e)},o.onReady=function(t){e(t)},o.appendBuffer(r),o.flush()})),n=o.tracks.filter((e=>!!e.audio||"SoundHandler"==e.name)),a=o.tracks.filter((e=>!!e.video||"VideoHandler"==e.name));return{duration:o.duration,mime:o.mime,audios:n,videos:a}}
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soga/mediainfo",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"license": "ISC",
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"fs-extra": "^11.2.0",
|
|
47
|
-
"mediainfo.js": "^0.3.4"
|
|
47
|
+
"mediainfo.js": "^0.3.4",
|
|
48
|
+
"mp4box": "^0.5.3"
|
|
48
49
|
}
|
|
49
50
|
}
|