@mce/mp4 0.17.10 → 0.17.12
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 +60 -71
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,76 +1,65 @@
|
|
|
1
1
|
import { definePlugin } from "mce";
|
|
2
2
|
import { render } from "modern-canvas";
|
|
3
3
|
import { MP4Encoder } from "modern-mp4";
|
|
4
|
+
//#region src/plugin.ts
|
|
4
5
|
function plugin() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
duration
|
|
60
|
-
});
|
|
61
|
-
bitmap.close();
|
|
62
|
-
timestamp += duration;
|
|
63
|
-
onProgress?.(progress);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
return await encoder.flush();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
]
|
|
70
|
-
};
|
|
71
|
-
});
|
|
6
|
+
return definePlugin((editor) => {
|
|
7
|
+
const { fonts, to } = editor;
|
|
8
|
+
return {
|
|
9
|
+
name: "mce:mp4",
|
|
10
|
+
exporters: [{
|
|
11
|
+
name: "mp4",
|
|
12
|
+
saveAs: true,
|
|
13
|
+
handle: async (options) => {
|
|
14
|
+
const { onProgress, ...restOptions } = options;
|
|
15
|
+
const data = to("json", restOptions);
|
|
16
|
+
const { startTime, endTime } = data.meta;
|
|
17
|
+
const width = Math.floor(data.style.width / 2) * 2;
|
|
18
|
+
const height = Math.floor(data.style.height / 2) * 2;
|
|
19
|
+
const framerate = 30;
|
|
20
|
+
const encoderOptions = {
|
|
21
|
+
width,
|
|
22
|
+
height,
|
|
23
|
+
framerate,
|
|
24
|
+
audio: false
|
|
25
|
+
};
|
|
26
|
+
const spf = 1e3 / framerate;
|
|
27
|
+
const baseBitrate = {
|
|
28
|
+
"720p": 3e6,
|
|
29
|
+
"1080p": 6e6,
|
|
30
|
+
"1440p": 12e6,
|
|
31
|
+
"2160p": 2e7
|
|
32
|
+
}[width <= 1280 && height <= 720 ? "720p" : width <= 1920 && height <= 1080 ? "1080p" : width <= 2560 && height <= 1440 ? "1440p" : "2160p"];
|
|
33
|
+
encoderOptions.videoBitrate = Math.round(baseBitrate * (framerate / 30));
|
|
34
|
+
if (!await MP4Encoder.isConfigSupported(encoderOptions)) throw new Error("Failed to parse encoding configuration");
|
|
35
|
+
const encoder = new MP4Encoder(encoderOptions);
|
|
36
|
+
let timestamp = 1;
|
|
37
|
+
await render({
|
|
38
|
+
data,
|
|
39
|
+
width,
|
|
40
|
+
height,
|
|
41
|
+
fonts,
|
|
42
|
+
keyframes: Array.from({ length: ~~((endTime - startTime) / spf) }, (_, i) => startTime + i * spf),
|
|
43
|
+
onKeyframe: async (data, { duration, progress }) => {
|
|
44
|
+
const bitmap = await createImageBitmap(new ImageData(data, width, height));
|
|
45
|
+
await encoder.encode({
|
|
46
|
+
data: bitmap,
|
|
47
|
+
timestamp,
|
|
48
|
+
duration
|
|
49
|
+
});
|
|
50
|
+
bitmap.close();
|
|
51
|
+
timestamp += duration;
|
|
52
|
+
onProgress?.(progress);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return await encoder.flush();
|
|
56
|
+
}
|
|
57
|
+
}]
|
|
58
|
+
};
|
|
59
|
+
});
|
|
72
60
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/index.ts
|
|
63
|
+
var src_default = plugin;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { src_default as default, plugin };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mce/mp4",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.17.
|
|
4
|
+
"version": "0.17.12",
|
|
5
5
|
"description": "MP4 plugin for mce",
|
|
6
6
|
"author": "wxm",
|
|
7
7
|
"license": "MIT",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"modern-mp4": "^0.2.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"mce": "0.17.
|
|
52
|
+
"mce": "0.17.12"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"mce": "^0"
|