From fdfc52280a49bce9d62c611e71ae94b2b5bdd41d Mon Sep 17 00:00:00 2001 From: Mister Hat Date: Sun, 4 Dec 2016 10:57:37 -0600 Subject: [PATCH] linux support --- index.js | 17 ++++++++++++++++- package.json | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 5294d2e..945c75a 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,22 @@ class Aperture { recorderOpts.push(`${cropArea.x}:${cropArea.y}:${cropArea.width}:${cropArea.height}`); } - this.recorder = execa(path.join(__dirname, 'swift', 'main'), recorderOpts); + if (process.platform === 'darwin') { + this.recorder = execa(path.join(__dirname, 'swift', 'main'), recorderOpts); + } else if (process.platform === 'linux') { + let args = ['-f', 'x11grab', '-i']; + + if (opts.cropArea) { + args.push(':0+' + opts.cropArea.x + ',' + opts.cropArea.y); + args.push('-video_size', opts.cropArea.width + 'x' + opts.cropArea.height); + } else { + args.push(':0'); + } + + args.push('-framerate', opts.fps, this.tmpPath); + + this.recorder = execa('ffmpeg', args); + } const timeout = setTimeout(() => { const err = new Error('unnable to start the recorder after 5 seconds'); diff --git a/package.json b/package.json index b72c6e9..db15fef 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "main": "index.js", "scripts": { "test": "xo", - "build": "cd swift && xcodebuild && mv build/release/aperture main && rm -r build", - "postinstall": "npm run build" + "build-macos": "cd swift && xcodebuild && mv build/release/aperture main && rm -r build", + "postinstall": "case $OSTYPE in darwin*) npm run build-macos ;; esac" }, "repository": { "type": "git",