Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ The Node API is structured similarly to the command line options, but there are
* <a name="js-config-headless" href="#js-config-headless">#</a> `headless` &lt;[boolean][]&gt; Runs puppeteer in headless (nonwindowed) mode (default: `true`).
* <a name="js-config-input-options" href="#js-config-input-options">#</a> `inputOptions` &lt;[Array][] &lt;[string][]&gt;&gt; Extra arguments for ffmpeg input. Example: `['-framerate', '30']`
* <a name="js-config-output-options" href="#js-config-output-options">#</a> `outputOptions` &lt;[Array][] &lt;[string][]&gt;&gt; Extra arguments for ffmpeg output. Example: `['-vf', 'scale=320:240']`
* <a name="js-config-ffmpeg-process-options" href="#js-config-ffmpeg-process-options">#</a> `ffmpegProcessOptions` &lt;[Array][] &lt;[string][]&gt;&gt; Extra arguments for ffmpeg process. Example: `{detached: true}`
* <a name="js-config-pixel-format" href="#js-config-pixel-format">#</a> `pixFmt` &lt;[string][]&gt; Pixel format for output video (default: `yuv420p`).
* <a name="js-config-start-delay" href="#js-config-start-delay">#</a> `startDelay` &lt;[number][]&gt; Waits `config.loadDelay` real seconds after loading before starting (default: `0`).
* <a name="js-config-keep-frames" href="#js-config-keep-frames">#</a> `keepFrames` &lt;[boolean][]&gt; If set to true, doesn't delete frames after processing them. Doesn't do anything in pipe mode.
Expand All @@ -286,6 +287,10 @@ The Node API is structured similarly to the command line options, but there are
* `page` &lt;[Page][]&gt; The puppeteer instance of the page being captured.
* `frameNumber` &lt;[number][]&gt; The current frame number (1 based).
* `totalFrames` &lt;[number][]&gt; The total number of frames.
* <a name="js-config-ffmpeg-command" href="#js-config-ffmpeg-command">#</a> `ffmpegCommand` &lt;[function][]([string][])&gt; A callback function that will be called before ffmpeg execution containing the full ffmpeg command.
* `command` &lt;[string][]&gt; The ffmpeg command.
* <a name="js-config-ffmpeg-process" href="#js-config-ffmpeg-process">#</a> `ffmpegProcess` &lt;[function][]([ChildProcess][])&gt; 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` &lt;[ChildProcess][]&gt; The ffmpeg child process.
* <a name="js-api-return" href="#js-api-return">#</a> returns: &lt;[Promise][]&gt; resolves after all the frames have been captured.

## <a name="modes" href="#modes">#</a> **timecut** Modes
Expand All @@ -312,3 +317,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
15 changes: 13 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,7 +133,15 @@ module.exports = function (config) {
}
// -y writes over existing files
ffmpegArgs = ffmpegArgs.concat(outputOptions).concat(['-y', output]);
convertProcess = spawn('ffmpeg', ffmpegArgs);
if(config.ffmpegCommand && typeof config.ffmpegCommand === 'function') {
config.ffmpegCommand('ffmpeg ' + ffmpegArgs.join(' '));
}

convertProcess = spawn('ffmpeg', ffmpegArgs, ffmpegProcessOptions);
if(config.ffmpegProcess && typeof config.ffmpegProcess === 'function') {
config.ffmpegProcess(convertProcess);
}

convertProcess.stderr.setEncoding('utf8');
convertProcess.stderr.on('data', function (data) {
log(data);
Expand All @@ -158,7 +167,9 @@ module.exports = function (config) {
if (processError) {
throw processError;
}
convertProcess.stdin.write(buffer);
if(!convertProcess.killed) {
convertProcess.stdin.write(buffer);
}
};
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down