Skip to content

Instantly share code, notes, and snippets.

@vesse
Created January 20, 2012 11:17
Show Gist options
  • Save vesse/1646752 to your computer and use it in GitHub Desktop.
Save vesse/1646752 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": "supervisor -w server.coffee -x 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
@vesse
Copy link
Author

vesse commented Oct 24, 2013

@ptkarthikreddy the dependencies and stuff are probably outdated, but it used to work by running npm install, then npm start, and then opening http://localhost:9001/ using Chrome/Chromium.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment