polotno-node 2.7.1 → 2.7.2
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 +3 -2
- package/video-parallel.js +15 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polotno-node",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.2",
|
|
4
4
|
"description": "Polotno workflow from NodeJS",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@sparticuz/chromium": "118.0.0",
|
|
39
39
|
"puppeteer": "^20.9.0",
|
|
40
|
-
"puppeteer-core": "^20.9.0"
|
|
40
|
+
"puppeteer-core": "^20.9.0",
|
|
41
|
+
"tmp": "^0.2.1"
|
|
41
42
|
},
|
|
42
43
|
"bugs": {
|
|
43
44
|
"url": "https://github.com/polotno-project/polotno-node/issues"
|
package/video-parallel.js
CHANGED
|
@@ -3,6 +3,10 @@ const ffmpeg = require('fluent-ffmpeg');
|
|
|
3
3
|
const axios = require('axios');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
|
|
6
|
+
const tmp = require('tmp');
|
|
7
|
+
|
|
8
|
+
tmp.setGracefulCleanup();
|
|
9
|
+
|
|
6
10
|
const downloadVideo = async (url, destination) => {
|
|
7
11
|
const response = await axios({
|
|
8
12
|
method: 'GET',
|
|
@@ -51,12 +55,14 @@ const fileToDataUrl = (filename) => {
|
|
|
51
55
|
const videoToDataURL = async (url) => {
|
|
52
56
|
console.log('downloading', url);
|
|
53
57
|
const filename = Math.random().toString(36).substring(7);
|
|
54
|
-
const
|
|
58
|
+
const tempFolder = tmp.dirSync();
|
|
59
|
+
const destination = path.join(tempFolder.name, filename + '.mp4');
|
|
55
60
|
await downloadVideo(url, destination);
|
|
56
61
|
const webmFile = destination.replace('.mp4', '.webm');
|
|
57
62
|
console.log('converting to webm', url);
|
|
58
63
|
await convertToWebM(destination, webmFile);
|
|
59
64
|
const dataUrl = await fileToDataUrl(webmFile);
|
|
65
|
+
fs.rmSync(tempFolder.name, { recursive: true });
|
|
60
66
|
return dataUrl;
|
|
61
67
|
};
|
|
62
68
|
|
|
@@ -71,11 +77,7 @@ module.exports.jsonToVideo = async function jsonToVideo(
|
|
|
71
77
|
json,
|
|
72
78
|
attrs
|
|
73
79
|
) {
|
|
74
|
-
|
|
75
|
-
fs.rmSync('./tmp', { recursive: true });
|
|
76
|
-
} catch (e) {}
|
|
77
|
-
|
|
78
|
-
fs.mkdirSync('./tmp', { recursive: true });
|
|
80
|
+
const tempFolder = tmp.dirSync();
|
|
79
81
|
|
|
80
82
|
for (const page of json.pages) {
|
|
81
83
|
for (const el of page.children) {
|
|
@@ -169,7 +171,6 @@ module.exports.jsonToVideo = async function jsonToVideo(
|
|
|
169
171
|
);
|
|
170
172
|
});
|
|
171
173
|
const url = await store.toDataURL({
|
|
172
|
-
pixelRatio: 0.5,
|
|
173
174
|
...attrs,
|
|
174
175
|
pageId: currentPage?.id,
|
|
175
176
|
});
|
|
@@ -179,9 +180,8 @@ module.exports.jsonToVideo = async function jsonToVideo(
|
|
|
179
180
|
attrs || {},
|
|
180
181
|
currentTime
|
|
181
182
|
);
|
|
182
|
-
fs.mkdirSync('./tmp', { recursive: true });
|
|
183
183
|
fs.writeFileSync(
|
|
184
|
-
|
|
184
|
+
`${tempFolder.name}/${frameIndex}.png`,
|
|
185
185
|
dataURL.split(',')[1],
|
|
186
186
|
'base64'
|
|
187
187
|
);
|
|
@@ -240,19 +240,19 @@ module.exports.jsonToVideo = async function jsonToVideo(
|
|
|
240
240
|
// fs.writeFileSync(`./tmp/${i}.png`, dataURL.split(',')[1], 'base64');
|
|
241
241
|
// }
|
|
242
242
|
|
|
243
|
-
|
|
243
|
+
const format = attrs.out.split('.').pop() || 'mp4';
|
|
244
244
|
|
|
245
245
|
await new Promise((resolve, reject) => {
|
|
246
246
|
ffmpeg()
|
|
247
|
-
.input(
|
|
247
|
+
.input(`${tempFolder.name}/%d.png`) // Make sure your images are named with numbers, e.g. 1.jpg, 2.jpg, etc.
|
|
248
248
|
.inputFPS(fps)
|
|
249
|
-
.videoCodec('
|
|
250
|
-
.outputOptions('-pix_fmt
|
|
251
|
-
.format(
|
|
249
|
+
// .videoCodec('libx265')
|
|
250
|
+
.outputOptions('-pix_fmt yuva420p')
|
|
251
|
+
.format(format)
|
|
252
252
|
.on('end', () => resolve())
|
|
253
253
|
.on('error', (err) => reject(err))
|
|
254
254
|
.save(attrs.out);
|
|
255
255
|
});
|
|
256
256
|
|
|
257
|
-
fs.rmSync(
|
|
257
|
+
fs.rmSync(tempFolder.name, { recursive: true });
|
|
258
258
|
};
|