From c692dbd26ec8f885682e12c8c7c3cc33f2f7a10a Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Thu, 30 Apr 2020 23:01:22 +0800 Subject: [PATCH] improve error handling #24 --- index.js | 12 ++++++++++-- sources/videoFrameSource.js | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index f6dc25d..b86a54f 100644 --- a/index.js +++ b/index.js @@ -280,7 +280,7 @@ module.exports = async (config = {}) => { ]; const args = [ - ...(enableFfmpegLog ? [] : ['-hide_banner', '-loglevel', 'panic']), + ...(enableFfmpegLog ? [] : ['-hide_banner', '-loglevel', 'error']), '-f', 'rawvideo', '-vcodec', 'rawvideo', @@ -308,6 +308,13 @@ module.exports = async (config = {}) => { try { outProcess = startFfmpegWriterProcess(); + let outProcessError; + + // If we don't catch it here, the whole process will crash and we cannot process the error + outProcess.stdin.on('error', (err) => { + console.error('Output ffmpeg caught error', err); + outProcessError = err; + }); let totalFrameCount = 0; let fromClipFrameCount = 0; @@ -394,7 +401,8 @@ module.exports = async (config = {}) => { // If we don't await we get EINVAL when dealing with high resolution files (big writes) await new Promise((r) => outProcess.stdin.write(outFrameData, () => r())); - // outProcess.stdin.write(outFrameData); + + if (outProcessError) throw outProcessError; fromClipFrameCount += 1; } diff --git a/sources/videoFrameSource.js b/sources/videoFrameSource.js index c22f70a..e22ced9 100644 --- a/sources/videoFrameSource.js +++ b/sources/videoFrameSource.js @@ -29,7 +29,7 @@ module.exports = async ({ width, height, channels, framerateStr, verbose, enable // Testing: ffmpeg -i 'vid.mov' -t 1 -vcodec rawvideo -pix_fmt rgba -f image2pipe - | ffmpeg -f rawvideo -vcodec rawvideo -pix_fmt rgba -s 2166x1650 -i - -vf format=yuv420p -vcodec libx264 -y out.mp4 // https://trac.ffmpeg.org/wiki/ChangingFrameRate const args = [ - ...(enableFfmpegLog ? [] : ['-hide_banner', '-loglevel', 'panic']), + ...(enableFfmpegLog ? [] : ['-hide_banner', '-loglevel', 'error']), ...(cutFrom ? ['-ss', cutFrom] : []), '-i', path, ...(cutTo ? ['-t', (cutTo - cutFrom) * framePtsFactor] : []),