Procedurally generates a radio weather report
1import { spawn } from 'child_process';
2
3const ENCTOOL = process.env['ENCTOOL'] || 'ffmpeg';
4
5function ffmpeg(args: string[], files: number): Promise<void> {
6 return new Promise((resolve, reject) => {
7 console.log(`${ENCTOOL} ${args.join(' ')}`);
8 const process = spawn(ENCTOOL, args);
9 const to = setTimeout(async () => {
10 process.kill();
11 reject(new Error('timed out'));
12 }, 5000 * files);
13 process.on('exit', async (code) => {
14 clearTimeout(to);
15 if (code !== 0) {
16 reject(new Error(`exited with ${code}`));
17 }
18 else {
19 resolve();
20 }
21 });
22 });
23}
24
25async function Stitcher(files: string[]) {
26 const args: string[] = [];
27 files.forEach(f => args.push('-i', f));
28 args.push('-filter_complex', `[0:a][1:a][2:a]concat=n=${files.length}:v=0:a=1[out]`);
29 args.push('-map', '[out]', '-ar', '44100', '-ac', '2', '-c:a', 'pcm_s16le', 'output.wav', '-y');
30 await ffmpeg(args, files.length);
31}
32
33export default Stitcher;
34export { Stitcher };