From a45f12b2e84061da510bc8ab28378df75ea9d5ac Mon Sep 17 00:00:00 2001 From: Roei Elisha Date: Wed, 8 Jan 2020 00:43:18 +0200 Subject: [PATCH] changed the merge from using mkvmerge to using ffmpeg when merge the subtitles with the video mkvmerge was sometimes throwing warnings, and when it throws a warning the exit code of the program is 1 and that throws an error eventhough the merge is totally ok I switched the merge to use ffmpeg, it feels much more suited for the job and it also removes the dependency on another executable --- src/video/merge.ts | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/video/merge.ts b/src/video/merge.ts index 9c59d25..a3c99b4 100644 --- a/src/video/merge.ts +++ b/src/video/merge.ts @@ -12,23 +12,14 @@ import subtitle from '../subtitle/index'; export default function(config: IConfig, isSubtitled: boolean, rtmpInputPath: string, filePath: string, streamMode: string, verbose: boolean, done: (err: Error) => void) { - const subtitlePath = filePath + '.' + (subtitle.formats[config.format] ? config.format : 'ass'); - let videoPath = filePath; - let cp; + const subtitleFormat = (subtitle.formats[config.format] ? config.format : 'ass'); + const subtitlePath = filePath + '.' + subtitleFormat; + const videoPath = filePath + (streamMode === 'RTMP' ? path.extname(rtmpInputPath) : '.mp4'); - if (streamMode === 'RTMP') - { - videoPath += path.extname(rtmpInputPath); - } - else - { - videoPath += '.mp4'; - } + const cmd = `${command()} -y -i "${videoPath}" ${(isSubtitled ? `-i "${subtitlePath}"` : '')} ` + + `-c copy -c:s ${subtitleFormat} -disposition:s:0 default "${filePath}.mkv"`; - cp = childProcess.exec(command() + ' ' + - '-o "' + filePath + '.mkv" ' + - '"' + videoPath + '" ' + - (isSubtitled ? '"' + subtitlePath + '"' : ''), { + const cp = childProcess.exec(cmd, { maxBuffer: Infinity, }, (err) => { @@ -48,9 +39,8 @@ export default function(config: IConfig, isSubtitled: boolean, rtmpInputPath: st }); }); - if (verbose === true) + if (verbose) { - cp.stdin.pipe(process.stdin); cp.stdout.pipe(process.stdout); cp.stderr.pipe(process.stderr); } @@ -63,10 +53,10 @@ function command(): string { if (os.platform() !== 'win32') { - return 'mkvmerge'; + return 'ffmpeg'; } - return '"' + path.join(__dirname, '../../bin/mkvmerge.exe') + '"'; + return '"' + path.join(__dirname, '../../bin/ffmpeg.exe') + '"'; } /** @@ -101,4 +91,4 @@ function unlinkTimeout(videoPath: string, subtitlePath: string, timeout: number) } }); }, timeout); -} +} \ No newline at end of file