// Used to concatinate audio files with ffmpeg and retunrs the path to the concatinated file function concatAudioFiles(filePaths, cb) { if (filePaths.length == 1) { cb(null, filePaths[0]); } else { var ffmpegCmd = ffmpeg(); const singleFilePath = path.join(workingDir, 'article.mp3'); filePaths.forEach((x) => { ffmpegCmd.input(x); }); ffmpegCmd .setFfmpegPath(ffmpegStatic.path) .setFfprobePath(ffprobeStatic.path) .on('error', (err) => { cb(err, null); }) .on('end', () => { cb(null, singleFilePath); }) .mergeToFile(singleFilePath, workingDir); } }
let addLoopedImage = (input, output, image, duration) => { return new Promise((resolve, reject) => { ffmpeg(input) .input(image) .inputOptions(['-r 1', '-loop 1']) .audioCodec('copy') .outputOptions(['-shortest']) .output(output) .on('end', () => { console.log('') // fix stdout resolve() }) .on('error', (err) => { console.log('') // fix stdout reject(err) }) .on('start', (cmd) => { logger.log('debug', cmd) }) .on('progress', (msg) => { process.stdout.write(`Adding looped cover image to Audiobook ... ${currentTimemarkToPercent(msg.timemark, duration)}%` + '\r') }) .run() }) }
ffmpeg(infile) .input(overlay) .outputOptions(['-map 0:a']) .applyAutoPadding(true) .complexFilter( [ 'scale=-2:720[rescaled]', { filter: 'crop', options: 'ih:ih:iw/4:0', inputs: 'rescaled', outputs: 'crop' }, { filter: 'overlay', options: { x: '(main_w-overlay_w)/2', y: '(main_h-overlay_h)/2', }, inputs: 'crop', outputs: 'output', }, ], 'output' ) .output(output) .on('error', error => console.log('Error: ' + error.message)) .on('end', () => console.log('Success!')) .run();