Repository: clipisode/puppeteer-recorder Branch: master Commit: b56909216e20 Files: 5 Total size: 4.7 KB Directory structure: gitextract__i29i1e7/ ├── .gitignore ├── LICENSE ├── README.md ├── index.js └── package.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # Logs logs *.log npm-debug.log* yarn-debug.log* yarn-error.log* # Runtime data pids *.pid *.seed *.pid.lock # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # nyc test coverage .nyc_output # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # Bower dependency directory (https://bower.io/) bower_components # node-waf configuration .lock-wscript # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directories node_modules/ jspm_packages/ # Typescript v1 declaration files typings/ # Optional npm cache directory .npm # Optional eslint cache .eslintcache # Optional REPL history .node_repl_history # Output of 'npm pack' *.tgz # Yarn Integrity file .yarn-integrity # dotenv environment variables file .env ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2017 Clipisode Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # puppeteer-recorder Record frame-by-frame animations using puppeteer. Based on electron-recorder. # Usage ```javascript const { record } = require('puppeteer-recorder'); await record({ browser: null, // Optional: a puppeteer Browser instance, page: null, // Optional: a puppeteer Page instance, output: 'output.webm', fps: 60, frames: 60 * 5, // 5 seconds at 60 fps prepare: function (browser, page) { /* executed before first capture */ }, render: function (browser, page, frame) { /* executed before each capture */ } }); ``` ================================================ FILE: index.js ================================================ const { spawn } = require('child_process'); const puppeteer = require('puppeteer'); module.exports.record = async function(options) { const browser = options.browser || (await puppeteer.launch()); const page = options.page || (await browser.newPage()); await options.prepare(browser, page); var ffmpegPath = options.ffmpeg || 'ffmpeg'; var fps = options.fps || 60; var outFile = options.output; const args = ffmpegArgs(fps); if ('format' in options) args.push('-f', options.format); else if (!outFile) args.push('-f', 'matroska'); args.push(outFile || '-'); const ffmpeg = spawn(ffmpegPath, args); if (options.pipeOutput) { ffmpeg.stdout.pipe(process.stdout); ffmpeg.stderr.pipe(process.stderr); } const closed = new Promise((resolve, reject) => { ffmpeg.on('error', reject); ffmpeg.on('close', resolve); }); for (let i = 1; i <= options.frames; i++) { if (options.logEachFrame) console.log( `[puppeteer-recorder] rendering frame ${i} of ${options.frames}.` ); await options.render(browser, page, i); let screenshot = await page.screenshot({ omitBackground: true }); await write(ffmpeg.stdin, screenshot); } ffmpeg.stdin.end(); await closed; }; const ffmpegArgs = fps => [ '-y', '-f', 'image2pipe', '-r', `${+fps}`, '-i', '-', '-c:v', 'libvpx', '-auto-alt-ref', '0', '-pix_fmt', 'yuva420p', '-metadata:s:v:0', 'alpha_mode="1"' ]; const write = (stream, buffer) => new Promise((resolve, reject) => { stream.write(buffer, error => { if (error) reject(error); else resolve(); }); }); ================================================ FILE: package.json ================================================ { "name": "puppeteer-recorder", "version": "1.0.7", "description": "Record animations using puppeteer. Based on electron-recorder.", "main": "index.js", "peerDependencies": { "puppeteer": ">= 0.9.0" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "git+https://github.com/clipisode/puppeteer-recorder.git" }, "keywords": [ "puppeteer", "ffmpeg", "animation", "recorder" ], "author": "Max Schmeling", "license": "MIT", "bugs": { "url": "https://github.com/clipisode/puppeteer-recorder/issues" }, "homepage": "https://github.com/clipisode/puppeteer-recorder#readme" }