├── LICENSE ├── README.md ├── bin └── cmd.js ├── index.js └── package.json /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Stephen Whitmore 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # screen-stream 2 | 3 | Provides a video stream of your computer's display. 4 | 5 | [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) 6 | 7 | ## Install 8 | 9 | ```sh 10 | npm install screen-stream 11 | ``` 12 | 13 | You will also need `ffmpeg` installed and accessible from the command line. 14 | 15 | Linux only so far! :O 16 | 17 | ## CLI Usage 18 | 19 | Remember to install globally so you can access the screen-stream command: 20 | 21 | ```sh 22 | $ npm install -g screen-stream 23 | ``` 24 | 25 | Then freely pipe the stream anywhere! 26 | 27 | ```sh 28 | $ screen-stream > recording.mp4 29 | ^C 30 | 31 | $ mplayer recording.mp4 32 | ``` 33 | 34 | ## API 35 | 36 | `screen-stream` exports a single method, which creates a new live stream of your 37 | display. 38 | 39 | Stream your live screen to e.g. an HTTP endpoint! 40 | 41 | ```js 42 | var screen = require('screen-stream') 43 | var request = require('request') 44 | 45 | screen().pipe(request.put("http://my.website.com/live_stream_feed")) 46 | ``` 47 | 48 | ## Limitations 49 | 50 | * Linux support only so far 51 | * Requires a pre-existing ffmpeg install that's setup on your command line 52 | * No way to customize output (size, bitrate, format, etc) 53 | 54 | ## Contributing 55 | 56 | Pull requests and stars are always welcome. For bugs and feature requests, 57 | [please create an issue](https://github.com/noffle/screen-stream/issues/new). 58 | 59 | Please use [standard Javascript](https://github.com/feross/standard) in your pull requests. 60 | 61 | 62 | -------------------------------------------------------------------------------- /bin/cmd.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | process.chdir(__dirname + '/../') 4 | 5 | var screen = require('../index') 6 | var http = require('http') 7 | 8 | // TODO: minimalist support; usage doc 9 | var doServer = process.argv[2] 10 | if (doServer && doServer === '-s') { 11 | runServer() 12 | } else { 13 | screen().pipe(process.stdout) 14 | } 15 | 16 | function runServer() { 17 | var server = http.createServer(function (req, res) { 18 | if (req.url === '/') { 19 | screen().pipe(res) 20 | } 21 | }) 22 | server.listen(6900) 23 | } 24 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var os = require('os') 2 | var exec = require('exec-stream') 3 | var spawn = require('child_process').spawn 4 | 5 | module.exports = function (opts) { 6 | 7 | var cmd = "ffmpeg" 8 | 9 | opts = opts || {} 10 | opts.fps = opts.fps || 20 11 | opts.resolution = opts.resolution || '1440x900' 12 | opts.threads = opts.threads || 2 13 | opts.bitrateKbps = opts.bitrateKbps || "3000k" 14 | opts.audioRate = opts.audioRate || 44100 15 | opts.videoCodec = opts.videoCodec || 'libx264' 16 | 17 | // Platform-specific junk 18 | if (os.platform() === 'linux') { 19 | opts.captureVideoDevice = "x11grab" 20 | opts.captureAudioDevice = "pulse" 21 | opts.display = ":0.0" 22 | } else { 23 | throw new Error(os.platform() + ' not yet supported!') 24 | } 25 | 26 | var params = [ 27 | '-f', opts.captureVideoDevice, 28 | '-s', opts.resolution, 29 | '-r', opts.fps, 30 | '-i', opts.display, 31 | '-f', 'alsa', 32 | '-i', 'pulse', 33 | '-f', 'flv', 34 | '-ac', '2', 35 | '-ar', opts.audioRate, 36 | '-vcodec', opts.videoCodec, 37 | '-g', opts.fps * 2, 38 | '-keyint_min', opts.fps, 39 | '-b:v', opts.bitrateKbps, 40 | '-minrate', opts.bitrateKbps, 41 | '-maxrate', opts.bitrateKbps, 42 | '-pix_fmt', 'yuv420p', 43 | '-s', opts.resolution, 44 | '-preset', 'ultrafast', 45 | '-tune', 'film', 46 | '-acodec', 'libmp3lame', 47 | '-threads', opts.threads, 48 | '-strict', 'normal', 49 | '-bufsize', opts.bitrateKbps 50 | ] 51 | 52 | params.push('pipe:1') 53 | 54 | return spawn(cmd, params).stdout 55 | } 56 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "screen-stream", 3 | "description": "Get a video stream of your computer's display.", 4 | "version": "0.4.0", 5 | "repository": { 6 | "url": "git://github.com/noffle/screen-stream.git" 7 | }, 8 | "bin": { 9 | "screen-stream": "./bin/cmd.js" 10 | }, 11 | "main": "index.js", 12 | "scripts": { 13 | "test": "standard" 14 | }, 15 | "dependencies": { 16 | "exec-stream": "^0.1.0" 17 | }, 18 | "devDependencies": { 19 | "tape": "*" 20 | }, 21 | "license": "MIT" 22 | } 23 | --------------------------------------------------------------------------------