├── LICENSE
├── README.md
├── example
└── index.js
├── index.html
├── index.js
└── package.json
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 CM
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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### About
2 | GStreamer wrapper for very low latency streaming over websocket.
3 |
4 | Perfect for IP Camera in a browser, webview etc.
5 |
6 | ### Installation
7 | ```
8 | sudo apt-get install gstreamer-tools
9 | ```
10 | Then
11 | ```
12 | npm install gstreamer
13 | ```
14 |
15 | ### Usage
16 | ```javascript
17 | var gstreamer = require("../");
18 |
19 | gstreamer.start({
20 | url: "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov",
21 | //url: "rtsp://192.168.1.92:554//1",
22 | port: 80,
23 | quiet: false
24 | });
25 | ```
26 |
27 | Run the example, and browse to your http://IP to see the result
28 |
--------------------------------------------------------------------------------
/example/index.js:
--------------------------------------------------------------------------------
1 |
2 | var gstreamer = require("../");
3 |
4 | gstreamer.start({
5 | url: "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov?random=" + Math.random(),
6 | //url: "rtsp://192.168.1.92:554//1",
7 | port: 80,
8 | quiet: false
9 | });
10 |
11 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | GStreamer RTSP to WebBrowser
6 |
19 |
20 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | module.exports = new gstreamer();
2 |
3 | function gstreamer() {
4 | var self = this;
5 | self.cp = require("child_process");
6 | self.fs = require("fs");
7 | self.net = require("net");
8 | self.http = require("http");
9 | self.sio = require("socket.io");
10 | }
11 |
12 | gstreamer.prototype._args = function () {
13 | return [
14 | "rtspsrc", "location=\"" + this.url + "\"",
15 | "latency=0",
16 | "is-live=true", //probably outdated, but can't hurt
17 | "low-latency=true", //probably outdated, but can't hurt
18 | "!", "decodebin",
19 | "!", "jpegenc", "quality=" + this.quality,
20 | "!", "tcpclientsink", "host=127.0.0.1", "port=" + this.tcpport
21 | ];
22 | };
23 |
24 | gstreamer.prototype.start = function (options) {
25 | var self = this;
26 | options = options || {};
27 | self.quiet = options.quiet || false;
28 | self.cmd = options.cmd || "gst-launch-1.0";
29 | self.url = options.url || "rtsp://r3---sn-a5m7zu76.c.youtube.com/CiILENy73wIaGQnup-1SztVOYBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp";
30 | self.host = options.host || undefined;
31 | self.port = options.port || 80;
32 | self.suffix = options.suffix || "/cam0";
33 | self.quality = options.quality || 85;
34 | self.tcpport = options.tcpport || 6161; //internal socket
35 | self.index = __dirname + "/index.html";
36 |
37 | var args = self._args();
38 | self.server = self.http.createServer(function (request, response) {
39 | if (self.index && request.url === "/") {
40 | self.fs.readFile(self.index, "utf-8", function (error, content) {
41 | response.writeHead(200, {"Content-Type": "text/html"});
42 | response.end(content);
43 | });
44 | console.log("Index loaded");
45 | }
46 | });
47 | var io = self.sio.listen(self.server);
48 | var cam0 = io.of(self.suffix);
49 | cam0.on("connection", function (request, response) {
50 | console.log("Client connected");
51 | });
52 | self.tcp = self.net.createServer(function (socket) {
53 | socket.on("data", function (data) {
54 | cam0.emit("data", data);
55 | });
56 | }).on("listening", function () {
57 | self.gst = self.cp.spawn(self.cmd, args);
58 | self.gst.stderr.pipe(process.stderr);
59 | if (!self.quiet) {
60 | self.gst.stdout.pipe(process.stdout);
61 | console.log("GStreamer started [ " + self.cmd + " " + args.join(" ") + " ]");
62 | }
63 | }).listen(self.tcpport, "127.0.0.1");
64 | self.server.listen(self.port, self.host);
65 | };
66 |
67 | gstreamer.prototype.close = function () {
68 | var self = this;
69 | if (self.io !== null) {
70 | self.io.close();
71 | }
72 | if (!this.quiet) {
73 | console.log("GStreamer stopped");
74 | }
75 | };
76 |
77 |
78 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "gstreamer",
3 | "version": "1.0.3",
4 | "description": "GStreamer RTSP to WebBrowser",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git+https://github.com/ced-dev/gstreamer.git"
12 | },
13 | "keywords": [
14 | "gstreamer",
15 | "rtsp",
16 | "websocket"
17 | ],
18 | "author": "ced-dev",
19 | "license": "MIT",
20 | "bugs": {
21 | "url": "https://github.com/ced-dev/gstreamer/issues"
22 | },
23 | "homepage": "https://github.com/ced-dev/gstreamer#readme",
24 | "dependencies": {
25 | "socket.io": "^1.4.5"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------