Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiokas committed Apr 10, 2012
0 parents commit 7b06357
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 0 deletions.
12 changes: 12 additions & 0 deletions restreamer/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
46 changes: 46 additions & 0 deletions restreamer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Restreamer server module for node.js
Restreamer creates stand-alone servers for re-encoding live network audio streams on the fly.
A single server instance allow any number of audio streams. It may work with video, but I haven't tried thoroughly.

## Requirements
- An *NIX box with ffmpeg.
- fluent-ffmpeg node module (listed as dependency in npm).

## Usage
Start the server with default parameters

var rs = require('restreamer');
// Start server with default port (17856), converting to the Ogg format.
restreamer.create().listen();

At this point,

http://[your-domain]:17856/?url=[your live media URL]

will convert whichever input format the input media is, to the free Ogg format. The resulting above URL can be used as a media stream just like that.

Keep in mind that you're specifying an URL inside an URL (doh!). Encode the media URL to avoid special characters issues.

## Options
A few options are available. Defaults are: listen to the 17856 port, convert to Ogg, do not allow overriding the output format.

// Listen on the 5566 port, convert input to the ac3 format
restreamer.create({port: 5566, format: "ac3").listen();

// Listen on the 5566 port, allow overriding the output format on the URL
restreamer.create({port: 5566, override: true}).listen();

// Specify the port on the listen method.
restreamer.create().listen(5566);

If you choose to allow overriding the output format, your can specify the desired one in the URL, e.g.:

http://[your-domain]:17856/?url=[your live media URL]&format=ac3

will use AC3 as the output format for the given media stream. If overriding is not allowed, the requested format will be ignored and the default one will be used instead.

## Formats
Input and output formats availability are limited exclusively by your ffmpeg installation. Run ''ffmpeg -formats'' to know which ones are available in your system.

## Questions
Github issues, or dev at sergiokas dot com
3 changes: 3 additions & 0 deletions restreamer/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var restreamer = require("./lib/restreamer");

var s = restreamer.create({port: 5566, override: true}).listen();
1 change: 1 addition & 0 deletions restreamer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("./lib/restreamer-server");
65 changes: 65 additions & 0 deletions restreamer/lib/restreamer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
var http = require('http');
var url = require('url');
var ffmpeg = require('fluent-ffmpeg');

var defaults = {
port: 17856, // Default listening port
format: 'ogg', // Resulting format
override: false // Allow overriding the format on the URL.
};

/**
* Main object, start a restreamer server with the given settings (or defaults if none)
* - port: port to listen for incoming requests
* - format: output format to re-encode the input stream.
* - override: allow overriding the format on the URL.
*/
var restreamer = function(settings) {
var self = this;
settings = settings||{};

// Set defaults
settings.port = (settings.port||defaults.port);
settings.format = (settings.format||defaults.format);
settings.override = (settings.override||defaults.override);

// Request handler, if media is valid the response will never end.
var server = http.createServer(function(req, res) {
// Get media URL from query string
var u = url.parse(req.url, true);
var media = u.query['url'];
var format = u.query['format'];
format = (settings.override&&format)?format:settings.format;
// Start converting media.
if(!media) {
self.log("No media for " + format + " format");
res.end(); // Die if no media
}
else {
self.log("Streaming " + media + " to " + format + " format");
res.writeHeader({'Cache-control': "max-age=0, no-cache"});
(new ffmpeg(media))
.toFormat(format)
.writeToStream(res, function(retcode, error){
console.log(retcode, error);
self.log("Finished " + format + " encoding for " + media);
});
}
});

// Public listen function. At this point, the listening port can be overriden.
self.listen = function(port) {
server.listen(port||settings.port);
};

self.log = function(msg) {
console.log(msg);
};
};

restreamer.create = function(settings) {
return new restreamer(settings);
};

// Export just the server function.
module.exports = restreamer;
18 changes: 18 additions & 0 deletions restreamer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "restreamer",
"version": "0.1.0",
"description": "Standalone server to re-encode live media streams into other output formats",
"keywords": ["ffmpeg","media","audio","video","server"],
"author": "Sergio Kaszczyszyn <dev@sergiokas.com>",
"bugs": {
"mail": "dev@sergiokas.com",
"url": "github issues url"
},
"repository": "git://github.com/sergiokas/restreamer.git",
"dependencies": {"fluent-ffmpeg": ">=0.3.0"},
"engines" : { "node" : ">=0.4.0" },
"main": "index.js",
"scripts": {
"test": "nodeunit test"
}
}

0 comments on commit 7b06357

Please sign in to comment.