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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/video-parallel.js +24 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polotno-node",
3
- "version": "2.9.19",
3
+ "version": "2.9.20",
4
4
  "description": "Polotno workflow from NodeJS",
5
5
  "main": "index.js",
6
6
  "scripts": {
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(['-c:v libvpx', '-crf 30', '-b:v 1000k'])
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 destination = path.join(tempFolder.name, filename + '.mp4');
57
- await downloadVideo(url, destination);
58
- console.log('Converting video to webm: ' + shortUrl);
59
- const webmFile = destination.replace('.mp4', '.webm');
60
- await convertToWebM(destination, webmFile);
61
- fs.unlinkSync(destination);
62
- const dataURL = await fileToDataUrl(webmFile);
63
- console.log('Downloading video finished: ' + url.slice(0, 50) + '...');
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: webmFile,
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
  };