@mce/mp4 0.17.9 → 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.
Files changed (2) hide show
  1. package/dist/index.js +60 -71
  2. 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
- return definePlugin((editor) => {
6
- const {
7
- fonts,
8
- to
9
- } = editor;
10
- return {
11
- name: "mce:mp4",
12
- exporters: [
13
- {
14
- name: "mp4",
15
- saveAs: true,
16
- handle: async (options) => {
17
- const { onProgress, ...restOptions } = options;
18
- const data = to("json", restOptions);
19
- const { startTime, endTime } = data.meta;
20
- const width = Math.floor(data.style.width / 2) * 2;
21
- const height = Math.floor(data.style.height / 2) * 2;
22
- const framerate = 30;
23
- const encoderOptions = {
24
- width,
25
- height,
26
- framerate,
27
- audio: false
28
- };
29
- const spf = 1e3 / framerate;
30
- const baseBitrateMap = {
31
- "720p": 3e6,
32
- // 3 Mbps
33
- "1080p": 6e6,
34
- // 6 Mbps
35
- "1440p": 12e6,
36
- // 12 Mbps
37
- "2160p": 2e7
38
- // 20 Mbps
39
- };
40
- const resolutionLabel = width <= 1280 && height <= 720 ? "720p" : width <= 1920 && height <= 1080 ? "1080p" : width <= 2560 && height <= 1440 ? "1440p" : "2160p";
41
- const baseBitrate = baseBitrateMap[resolutionLabel];
42
- encoderOptions.videoBitrate = Math.round(baseBitrate * (framerate / 30));
43
- if (!await MP4Encoder.isConfigSupported(encoderOptions)) {
44
- throw new Error("Failed to parse encoding configuration");
45
- }
46
- const encoder = new MP4Encoder(encoderOptions);
47
- let timestamp = 1;
48
- await render({
49
- data,
50
- width,
51
- height,
52
- fonts,
53
- keyframes: Array.from({ length: ~~((endTime - startTime) / spf) }, (_, i) => startTime + i * spf),
54
- onKeyframe: async (data2, { duration, progress }) => {
55
- const bitmap = await createImageBitmap(new ImageData(data2, width, height));
56
- await encoder.encode({
57
- data: bitmap,
58
- timestamp,
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
- export {
74
- plugin as default,
75
- plugin
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.9",
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.9"
52
+ "mce": "0.17.12"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "mce": "^0"