polotno-node 2.9.19 → 2.9.21
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 +28 -12
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
|
-
|
|
62
|
-
|
|
63
|
-
console.log('
|
|
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
|
+
const dataURL = await fileToDataUrl(webmDestination);
|
|
69
|
+
|
|
70
|
+
console.log('Converting video finished: ' + webmDestination);
|
|
64
71
|
return {
|
|
65
72
|
dataURL,
|
|
66
|
-
file:
|
|
73
|
+
file: webmDestination,
|
|
74
|
+
mp4File: mp4Destination,
|
|
67
75
|
};
|
|
68
76
|
};
|
|
69
77
|
|
|
@@ -94,12 +102,13 @@ module.exports.jsonToVideo = async function jsonToVideo(inst, json, attrs) {
|
|
|
94
102
|
|
|
95
103
|
await Promise.all(
|
|
96
104
|
videoEls.map(async (el) => {
|
|
97
|
-
const { dataURL, file } = await cachedVideoToDataURL(
|
|
105
|
+
const { dataURL, file, mp4File } = await cachedVideoToDataURL(
|
|
98
106
|
el.src,
|
|
99
107
|
tempFolder
|
|
100
108
|
);
|
|
101
109
|
el.src = dataURL;
|
|
102
110
|
el.file = file;
|
|
111
|
+
el.mp4File = mp4File;
|
|
103
112
|
})
|
|
104
113
|
);
|
|
105
114
|
|
|
@@ -232,6 +241,7 @@ module.exports.jsonToVideo = async function jsonToVideo(inst, json, attrs) {
|
|
|
232
241
|
const elEndTime = elStartTime + elDuration;
|
|
233
242
|
inputs.push({
|
|
234
243
|
file: el.file,
|
|
244
|
+
mp4File: el.mp4File,
|
|
235
245
|
inputStartTime: elStartTime,
|
|
236
246
|
inputEndTime: elEndTime,
|
|
237
247
|
outputStartTime: pageStartTime,
|
|
@@ -244,6 +254,11 @@ module.exports.jsonToVideo = async function jsonToVideo(inst, json, attrs) {
|
|
|
244
254
|
|
|
245
255
|
const format = attrs.out.split('.').pop() || 'mp4';
|
|
246
256
|
|
|
257
|
+
// print all files in temp folder
|
|
258
|
+
fs.readdirSync(tempFolder.name).forEach((file) => {
|
|
259
|
+
console.log(file);
|
|
260
|
+
});
|
|
261
|
+
console.time('ffmpeg');
|
|
247
262
|
await new Promise((resolve, reject) => {
|
|
248
263
|
const ffmpegCmd = ffmpeg()
|
|
249
264
|
.input(`${tempFolder.name}/%d.jpeg`)
|
|
@@ -264,7 +279,7 @@ module.exports.jsonToVideo = async function jsonToVideo(inst, json, attrs) {
|
|
|
264
279
|
// Apply `-itsoffset` before each input file to shift its audio stream
|
|
265
280
|
ffmpegCmd
|
|
266
281
|
.inputOptions([`-itsoffset ${outputOffsetSec}`]) // Shift the input time
|
|
267
|
-
.input(input.
|
|
282
|
+
.input(input.mp4File) // Add the actual input file
|
|
268
283
|
.inputOptions([`-ss ${inputStartSec}`, `-t ${inputDurationSec}`]); // Specify the timing to cut the audio
|
|
269
284
|
});
|
|
270
285
|
|
|
@@ -290,6 +305,7 @@ module.exports.jsonToVideo = async function jsonToVideo(inst, json, attrs) {
|
|
|
290
305
|
} catch (e) {
|
|
291
306
|
throw e;
|
|
292
307
|
} finally {
|
|
308
|
+
console.timeEnd('ffmpeg');
|
|
293
309
|
fs.rmSync(tempFolder.name, { recursive: true });
|
|
294
310
|
}
|
|
295
311
|
};
|