polotno-node 2.9.24 → 2.9.26
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/assets/index-K6bexdEY.js +281 -0
- package/dist/index.html +1 -1
- package/package.json +2 -2
- package/video-parallel.js +13 -18
- package/dist/assets/index-B_ojGXHf.js +0 -279
package/dist/index.html
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
}
|
|
9
9
|
</style>
|
|
10
10
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
11
|
-
<script type="module" crossorigin src="./assets/index-
|
|
11
|
+
<script type="module" crossorigin src="./assets/index-K6bexdEY.js"></script>
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
|
14
14
|
<div id="root"></div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polotno-node",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.26",
|
|
4
4
|
"description": "Polotno workflow from NodeJS",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"gifencoder": "^2.0.1",
|
|
27
27
|
"pixelmatch": "^5.3.0",
|
|
28
28
|
"pngjs": "^7.0.0",
|
|
29
|
-
"polotno": "^2.
|
|
29
|
+
"polotno": "^2.8.3",
|
|
30
30
|
"react": "^18.3.1",
|
|
31
31
|
"react-dom": "^18.3.1",
|
|
32
32
|
"vite": "^5.2.11"
|
package/video-parallel.js
CHANGED
|
@@ -56,7 +56,7 @@ const fileToDataUrl = (filename) => {
|
|
|
56
56
|
});
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
const
|
|
59
|
+
const convertVideo = async (url, tempFolder) => {
|
|
60
60
|
const shortUrl = url.slice(0, 50) + '...';
|
|
61
61
|
console.log('Downloading video: ' + shortUrl);
|
|
62
62
|
const filename = Math.random().toString(36).substring(7);
|
|
@@ -75,14 +75,6 @@ const videoToDataURL = async (url, tempFolder) => {
|
|
|
75
75
|
};
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
const urlCache = {};
|
|
79
|
-
const cachedVideoToDataURL = async (url, tempFolder) => {
|
|
80
|
-
if (!urlCache[url]) {
|
|
81
|
-
urlCache[url] = videoToDataURL(url, tempFolder);
|
|
82
|
-
}
|
|
83
|
-
return urlCache[url];
|
|
84
|
-
};
|
|
85
|
-
|
|
86
78
|
module.exports.jsonToVideo = async function jsonToVideo(
|
|
87
79
|
inst,
|
|
88
80
|
json,
|
|
@@ -108,7 +100,7 @@ module.exports.jsonToVideo = async function jsonToVideo(
|
|
|
108
100
|
|
|
109
101
|
await Promise.all(
|
|
110
102
|
videoEls.map(async (el) => {
|
|
111
|
-
const { dataURL, file, mp4File } = await
|
|
103
|
+
const { dataURL, file, mp4File } = await convertVideo(
|
|
112
104
|
el.src,
|
|
113
105
|
tempFolder
|
|
114
106
|
);
|
|
@@ -127,7 +119,7 @@ module.exports.jsonToVideo = async function jsonToVideo(
|
|
|
127
119
|
const timePerFrame = 1000 / fps;
|
|
128
120
|
|
|
129
121
|
// loop through the images and add each to the animation
|
|
130
|
-
const framesNumber = Math.floor((duration / 1000) * fps);
|
|
122
|
+
const framesNumber = Math.floor((duration / 1000) * fps) || 1;
|
|
131
123
|
const frames = Array.from(Array(framesNumber).keys());
|
|
132
124
|
|
|
133
125
|
// split frames into parallel chunks
|
|
@@ -237,12 +229,17 @@ module.exports.jsonToVideo = async function jsonToVideo(
|
|
|
237
229
|
const inputs = [];
|
|
238
230
|
let pageStartTime = 0;
|
|
239
231
|
for (const page of json.pages) {
|
|
232
|
+
const pageDuration = page.duration || 5000;
|
|
240
233
|
for (const el of page.children) {
|
|
241
234
|
if (el.type === 'video') {
|
|
242
|
-
const
|
|
235
|
+
const startTime = el.startTime || 0;
|
|
236
|
+
const endTime = el.endTime || 1;
|
|
237
|
+
const dur = el.duration || 5000;
|
|
238
|
+
const elStartTime = startTime * dur;
|
|
239
|
+
|
|
243
240
|
const elDuration = Math.min(
|
|
244
|
-
|
|
245
|
-
|
|
241
|
+
pageDuration,
|
|
242
|
+
dur * (endTime - startTime)
|
|
246
243
|
);
|
|
247
244
|
const elEndTime = elStartTime + elDuration;
|
|
248
245
|
inputs.push({
|
|
@@ -251,16 +248,15 @@ module.exports.jsonToVideo = async function jsonToVideo(
|
|
|
251
248
|
inputStartTime: elStartTime,
|
|
252
249
|
inputEndTime: elEndTime,
|
|
253
250
|
outputStartTime: pageStartTime,
|
|
254
|
-
outputEndTime: pageStartTime +
|
|
251
|
+
outputEndTime: pageStartTime + pageDuration,
|
|
255
252
|
});
|
|
256
253
|
}
|
|
257
254
|
}
|
|
258
|
-
pageStartTime +=
|
|
255
|
+
pageStartTime += pageDuration;
|
|
259
256
|
}
|
|
260
257
|
|
|
261
258
|
const format = attrs.out.split('.').pop() || 'mp4';
|
|
262
259
|
|
|
263
|
-
console.time('ffmpeg');
|
|
264
260
|
await new Promise((resolve, reject) => {
|
|
265
261
|
const ffmpegCmd = ffmpeg()
|
|
266
262
|
.input(`${tempFolder.name}/%d.jpeg`)
|
|
@@ -307,7 +303,6 @@ module.exports.jsonToVideo = async function jsonToVideo(
|
|
|
307
303
|
} catch (e) {
|
|
308
304
|
throw e;
|
|
309
305
|
} finally {
|
|
310
|
-
console.timeEnd('ffmpeg');
|
|
311
306
|
fs.rmSync(tempFolder.name, { recursive: true });
|
|
312
307
|
}
|
|
313
308
|
};
|