From 7b6648506de5a5ad07e2f0b447ba9c35da3f6d7d Mon Sep 17 00:00:00 2001 From: Johnathan Amit-Kanarek Date: Sun, 21 Jun 2020 13:03:07 +0300 Subject: [PATCH 1/4] Expose ffmpeg command line and child process --- README.md | 5 +++++ index.js | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/README.md b/README.md index 57f8dab..9f95b10 100644 --- a/README.md +++ b/README.md @@ -286,6 +286,10 @@ The Node API is structured similarly to the command line options, but there are * `page` <[Page][]> The puppeteer instance of the page being captured. * `frameNumber` <[number][]> The current frame number (1 based). * `totalFrames` <[number][]> The total number of frames. + * # `ffmpegCommand` <[function][]([string][])> A callback function that will be called before ffmpeg execution containing the full ffmpeg command. + * `command` <[string][]> The ffmpeg command. + * # `ffmpegProcess` <[function][]([ChildProcess][])> A callback function that will be called after ffmpeg process spawned and return the ffmpeg child process that later could be used to cancel the execution or to listen to its events. + * `process` <[ChildProcess][]> The ffmpeg child process. * # returns: <[Promise][]> resolves after all the frames have been captured. ## # **timecut** Modes @@ -312,3 +316,4 @@ This work was inspired by [a talk by Noah Veltman](https://github.com/veltman/d3 [function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions [CSS selector]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors [Page]: https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-page +[ChildProcess]: https://nodejs.org/api/child_process.html#child_process_class_childprocess diff --git a/index.js b/index.js index 26511a3..f089aaa 100644 --- a/index.js +++ b/index.js @@ -132,7 +132,15 @@ module.exports = function (config) { } // -y writes over existing files ffmpegArgs = ffmpegArgs.concat(outputOptions).concat(['-y', output]); + if(config.ffmpegCommand && typeof config.ffmpegCommand === 'function') { + config.ffmpegCommand('ffmpeg ' + ffmpegArgs.join(' ')); + } + convertProcess = spawn('ffmpeg', ffmpegArgs); + if(config.ffmpegProcess && typeof config.ffmpegProcess === 'function') { + config.ffmpegProcess(convertProcess); + } + convertProcess.stderr.setEncoding('utf8'); convertProcess.stderr.on('data', function (data) { log(data); From c1007f8ee94aef13a7b05d1680a63c9642f92853 Mon Sep 17 00:00:00 2001 From: Johnathan Amit-Kanarek Date: Sun, 21 Jun 2020 13:22:50 +0300 Subject: [PATCH 2/4] do not push to stdin of killed process --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f089aaa..27bfc5d 100644 --- a/index.js +++ b/index.js @@ -166,7 +166,9 @@ module.exports = function (config) { if (processError) { throw processError; } - convertProcess.stdin.write(buffer); + if(!convertProcess.killed) { + convertProcess.stdin.write(buffer); + } }; } From fc10849c3fbcc1fa6d6b29b40045fcc3d6b93e61 Mon Sep 17 00:00:00 2001 From: Johnathan Amit-Kanarek Date: Sun, 21 Jun 2020 18:55:14 +0300 Subject: [PATCH 3/4] version update --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b441ca8..0f86505 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "timecut", - "version": "0.1.3-prerelease", + "version": "0.1.4-prerelease", "description": "Record smooth movies of web pages", "repository": { "type": "git", From f5417472fdbc6cde4f9aa5fd1416b9b548488b74 Mon Sep 17 00:00:00 2001 From: Johnathan Amit-Kanarek Date: Wed, 14 Oct 2020 09:21:44 +0300 Subject: [PATCH 4/4] Support ffmpeg child process options --- README.md | 1 + index.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9f95b10..ccc896b 100644 --- a/README.md +++ b/README.md @@ -275,6 +275,7 @@ The Node API is structured similarly to the command line options, but there are * # `headless` <[boolean][]> Runs puppeteer in headless (nonwindowed) mode (default: `true`). * # `inputOptions` <[Array][] <[string][]>> Extra arguments for ffmpeg input. Example: `['-framerate', '30']` * # `outputOptions` <[Array][] <[string][]>> Extra arguments for ffmpeg output. Example: `['-vf', 'scale=320:240']` + * # `ffmpegProcessOptions` <[Array][] <[string][]>> Extra arguments for ffmpeg process. Example: `{detached: true}` * # `pixFmt` <[string][]> Pixel format for output video (default: `yuv420p`). * # `startDelay` <[number][]> Waits `config.loadDelay` real seconds after loading before starting (default: `0`). * # `keepFrames` <[boolean][]> If set to true, doesn't delete frames after processing them. Doesn't do anything in pipe mode. diff --git a/index.js b/index.js index 27bfc5d..2b61405 100644 --- a/index.js +++ b/index.js @@ -73,6 +73,7 @@ module.exports = function (config) { var ffmpegArgs; var inputOptions = config.inputOptions || []; var outputOptions = config.outputOptions || []; + var ffmpegProcessOptions = config.ffmpegProcessOptions || null; var frameDirectory = config.tempDir || config.frameDir; var fps; var frameMode = config.frameCache || !config.pipeMode; @@ -136,7 +137,7 @@ module.exports = function (config) { config.ffmpegCommand('ffmpeg ' + ffmpegArgs.join(' ')); } - convertProcess = spawn('ffmpeg', ffmpegArgs); + convertProcess = spawn('ffmpeg', ffmpegArgs, ffmpegProcessOptions); if(config.ffmpegProcess && typeof config.ffmpegProcess === 'function') { config.ffmpegProcess(convertProcess); }