From 5ccc1af29165d7fa031f16faa7db1bf3eebfb087 Mon Sep 17 00:00:00 2001 From: Max Schmeling Date: Tue, 6 Dec 2016 09:32:51 -0600 Subject: [PATCH 1/2] Updated to PNG image stream and libvpx video codec. --- index.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index e18240f..ed6e29e 100644 --- a/index.js +++ b/index.js @@ -16,11 +16,11 @@ function createMovieRecorderStream (win, options_) { '-y', '-f', 'image2pipe', '-r', '' + (+fps), - // we use jpeg here because the most common version of ffmpeg (the one - // that ships with homebrew) is broken and crashes when you feed it PNG data - // https://trac.ffmpeg.org/ticket/1272 - '-vcodec', 'mjpeg', - '-i', '-' + '-i', '-', + '-c:v', 'libvpx', + '-auto-alt-ref', '0', + '-pix_fmt', 'yuva420p', + '-metadata:s:v:0', 'alpha_mode="1"' ] var outFile = options.output @@ -46,11 +46,12 @@ function createMovieRecorderStream (win, options_) { function tryCapture () { try { win.capturePage(function (image) { - var jpeg = image.toJpeg(100) - if (jpeg.length === 0) { + var png = image.toPNG() + + if (png.length === 0) { setTimeout(tryCapture, 10) } else { - ffmpeg.stdin.write(jpeg, function (err) { + ffmpeg.stdin.write(png, function (err) { next(err) }) } From 6ed94dfc25afc8bb9566ec4200faa64bd9005292 Mon Sep 17 00:00:00 2001 From: Max Schmeling Date: Tue, 6 Dec 2016 14:03:51 -0600 Subject: [PATCH 2/2] Returning Promise for FFmpeg process close from end method. --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index ed6e29e..aada920 100644 --- a/index.js +++ b/index.js @@ -38,6 +38,7 @@ function createMovieRecorderStream (win, options_) { } var ffmpeg = spawn(ffmpegPath, args) + var ffmpegClosePromise = new Promise(resolve => ffmpeg.on('close', resolve)) function appendFrame (next) { // This is dumb, but sometimes electron's capture fails silently and returns @@ -65,6 +66,7 @@ function createMovieRecorderStream (win, options_) { function endMovie () { ffmpeg.stdin.end() + return ffmpegClosePromise } var result = {