polotno-node 2.9.19 → 2.9.20
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 +1 -1
- package/video-parallel.js +24 -10
package/package.json
CHANGED
package/video-parallel.js
CHANGED
|
@@ -25,7 +25,14 @@ const downloadVideo = async (url, destination) => {
|
|
|
25
25
|
const convertToWebM = (input, output) => {
|
|
26
26
|
return new Promise((resolve, reject) => {
|
|
27
27
|
ffmpeg(input)
|
|
28
|
-
.outputOptions([
|
|
28
|
+
.outputOptions([
|
|
29
|
+
'-c:v libvpx',
|
|
30
|
+
'-crf 30',
|
|
31
|
+
'-b:v 1000k',
|
|
32
|
+
'-quality realtime',
|
|
33
|
+
'-speed 4',
|
|
34
|
+
'-threads 4',
|
|
35
|
+
])
|
|
29
36
|
.output(output)
|
|
30
37
|
.on('start', () => {})
|
|
31
38
|
.on('end', () => {
|
|
@@ -53,17 +60,18 @@ const videoToDataURL = async (url, tempFolder) => {
|
|
|
53
60
|
const shortUrl = url.slice(0, 50) + '...';
|
|
54
61
|
console.log('Downloading video: ' + shortUrl);
|
|
55
62
|
const filename = Math.random().toString(36).substring(7);
|
|
56
|
-
const
|
|
57
|
-
await downloadVideo(url,
|
|
58
|
-
console.log('Converting video to webm: ' +
|
|
59
|
-
const
|
|
60
|
-
await convertToWebM(
|
|
61
|
-
fs.unlinkSync(
|
|
62
|
-
const dataURL = await fileToDataUrl(
|
|
63
|
-
|
|
63
|
+
const mp4Destination = path.join(tempFolder.name, filename + '.mp4');
|
|
64
|
+
await downloadVideo(url, mp4Destination);
|
|
65
|
+
console.log('Converting video to webm: ' + mp4Destination);
|
|
66
|
+
const webmDestination = mp4Destination.replace('.mp4', '.webm');
|
|
67
|
+
await convertToWebM(mp4Destination, webmDestination);
|
|
68
|
+
fs.unlinkSync(mp4Destination);
|
|
69
|
+
const dataURL = await fileToDataUrl(webmDestination);
|
|
70
|
+
|
|
71
|
+
console.log('Converting video finished: ' + webmDestination);
|
|
64
72
|
return {
|
|
65
73
|
dataURL,
|
|
66
|
-
file:
|
|
74
|
+
file: webmDestination,
|
|
67
75
|
};
|
|
68
76
|
};
|
|
69
77
|
|
|
@@ -244,6 +252,11 @@ module.exports.jsonToVideo = async function jsonToVideo(inst, json, attrs) {
|
|
|
244
252
|
|
|
245
253
|
const format = attrs.out.split('.').pop() || 'mp4';
|
|
246
254
|
|
|
255
|
+
// print all files in temp folder
|
|
256
|
+
fs.readdirSync(tempFolder.name).forEach((file) => {
|
|
257
|
+
console.log(file);
|
|
258
|
+
});
|
|
259
|
+
console.time('ffmpeg');
|
|
247
260
|
await new Promise((resolve, reject) => {
|
|
248
261
|
const ffmpegCmd = ffmpeg()
|
|
249
262
|
.input(`${tempFolder.name}/%d.jpeg`)
|
|
@@ -290,6 +303,7 @@ module.exports.jsonToVideo = async function jsonToVideo(inst, json, attrs) {
|
|
|
290
303
|
} catch (e) {
|
|
291
304
|
throw e;
|
|
292
305
|
} finally {
|
|
306
|
+
console.timeEnd('ffmpeg');
|
|
293
307
|
fs.rmSync(tempFolder.name, { recursive: true });
|
|
294
308
|
}
|
|
295
309
|
};
|