Skip to content

Instantly share code, notes, and snippets.

@grantmichaels
Forked from vesse/package.json
Created May 13, 2012 19:03
Show Gist options
  • Save grantmichaels/2689775 to your computer and use it in GitHub Desktop.
Save grantmichaels/2689775 to your computer and use it in GitHub Desktop.
Stream live web cam video using Node.js and Gstreamer
{
"name": "streamingtest",
"version": "0.0.1",
"engines": {
"node": ">=0.6.0"
},
"dependencies": {
"express": "2.5.x",
"coffee-script": "1.2.x"
},
"devDependencies": {
"supervisor": "0.2.x"
},
"scripts": {
"start": "node_modules/supervisor/lib/cli-wrapper.js -w server.coffee -x node_modules/coffee-script/bin/coffee server.coffee"
},
"config": {
"port": 9001
}
}
# Original article http://delog.wordpress.com/2011/04/26/stream-live-webm-video-to-browser-using-node-js-and-gstreamer/
express = require 'express'
net = require 'net'
child = require 'child_process'
app = express.createServer()
app.get '/stream', (req, res) ->
res.writeHead 200, {
'Date': (new Date()).toUTCString()
'Connection': 'close'
'Cache-Control': 'private'
'Content-Type': 'video/webm'
}
server = net.createServer (socket) ->
socket.on 'data', (data) ->
res.write(data)
socket.on 'close', (had_error) ->
res.end()
server.listen () ->
args = [
'v4l2src',
'!', 'video/x-raw-rgb,framerate=30/1',
'!', 'ffmpegcolorspace',
'!', 'vp8enc', 'speed=2',
'!', 'queue2',
'!', 'm.', 'autoaudiosrc',
'!', 'audioconvert',
'!', 'vorbisenc',
'!', 'queue2',
'!', 'm.', 'webmmux', 'name=m', 'streamable=true',
'!', 'tcpclientsink', 'host=localhost', 'port=' + server.address().port
]
# gst-launch is in Ubuntu package gstreamer-tools
gst_muxer = child.spawn 'gst-launch', args, null
gst_muxer.stderr.on 'data', onSpawnError
gst_muxer.on 'exit', onSpawnExit
res.connection.on 'close', () ->
gst_muxer.kill()
app.listen process.env.npm_package_config_port
onSpawnError = (data) ->
console.log data.toString()
onSpawnExit = (code) ->
if code?
console.error 'GStreamer error, exit code ' + code
process.on 'uncaughtException', (err) ->
console.debug err
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment