Created
January 20, 2012 11:17
-
-
Save vesse/1646752 to your computer and use it in GitHub Desktop.
Stream live web cam video using Node.js and Gstreamer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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
@ptkarthikreddy the dependencies and stuff are probably outdated, but it used to work by running
npm install
, thennpm start
, and then opening http://localhost:9001/ using Chrome/Chromium.