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