-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-poem.js
56 lines (45 loc) · 1.36 KB
/
generate-poem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const {exec} = require('child_process');
const basePath = 'poems/masnavi/';
const poemName = '01';
function renderPoem(poemName, layout, type) {
return new Promise((resolve, reject) => {
const poemBasePath = `${basePath}${poemName}/`;
const outputFileName = `upload/${poemName}-${layout}-${type}.mp4`;
console.log(
'Setting REMOTION_POEM_BASE_PATH to:',
poemBasePath,
layout,
type
);
const renderCommand = `REMOTION_POEM_BASE_PATH=${poemBasePath} REMOTION_LAYOUT=${layout} REMOTION_TYPE=${type} remotion render MyComp public/${poemBasePath}${outputFileName}`;
console.log(`Executing: ${renderCommand}`);
const child = exec(renderCommand, {
env: {
...process.env,
REMOTION_POEM_BASE_PATH: poemBasePath,
REMOTION_LAYOUT: layout,
},
});
child.stdout.on('data', (data) => {
console.log(data);
});
child.stderr.on('data', (data) => {
console.error(data);
});
child.on('exit', (code) => {
console.log(`Child process exited with code ${code}`);
resolve();
});
child.on('error', (error) => {
console.error(`Error: ${error.message}`);
reject(error);
});
});
}
async function processPoems() {
// await renderPoem(poemName, 'vertical', 'poem');
// console.log('Finished vertical poem layout');
await renderPoem(poemName, 'horizontal', 'poem');
console.log('Finished horizontal poem layout');
}
processPoems();