From f2769e5062e7dfebdc4e15db9407235c34b8551f Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Sun, 1 Jun 2014 11:43:18 -0700 Subject: [PATCH] Start adding file playback queue support --- lib/channel/playlist.js | 10 ++++++- lib/config.js | 5 +++- lib/ffmpeg.js | 58 +++++++++++++++++++++++++++++++++++++++++ lib/get-info.js | 17 +++++++++++- lib/media.js | 4 ++- www/js/callbacks.js | 8 ++++++ 6 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 lib/ffmpeg.js diff --git a/lib/channel/playlist.js b/lib/channel/playlist.js index e555fe34..f0a96a8e 100644 --- a/lib/channel/playlist.js +++ b/lib/channel/playlist.js @@ -310,7 +310,7 @@ PlaylistModule.prototype.handleQueue = function (user, data) { } /* Specifying a custom title is currently only allowed for custom media */ - if (typeof data.title !== "string" || data.type !== "cu") { + if (typeof data.title !== "string" || (data.type !== "cu" && data.type !== "fi")) { data.title = false; } @@ -860,6 +860,14 @@ PlaylistModule.prototype._addItem = function (media, data, user, cb) { }); } + /* Warn about high bitrate for raw files */ + if (media.type === "fi" && media.meta.bitrate > 1000) { + user.socket.emit("queueWarn", { + msg: "This video has a bitrate over 1000kbps. Clients with slow " + + "connections may experience lots of buffering." + }); + } + var item = new PlaylistItem(media, { uid: self._nextuid++, temp: data.temp, diff --git a/lib/config.js b/lib/config.js index fbd4ed2a..37d6645c 100644 --- a/lib/config.js +++ b/lib/config.js @@ -104,7 +104,10 @@ var defaults = { "max-items": 4000, "update-interval": 5 }, - "channel-blacklist": [] + "channel-blacklist": [], + ffmpeg: { + enabled: false + } }; /** diff --git a/lib/ffmpeg.js b/lib/ffmpeg.js new file mode 100644 index 00000000..305d9323 --- /dev/null +++ b/lib/ffmpeg.js @@ -0,0 +1,58 @@ +var Logger = require("./logger"); +var Config = require("./config"); +var Metadata; +var enabled = false; + +function init() { + if (Config.get("ffmpeg.enabled")) { + try { + Metadata = require("fluent-ffmpeg").Metadata; + Logger.syslog.log("Enabling raw file support with fluent-ffmpeg"); + enabled = true; + } catch (e) { + Logger.errlog.log("Failed to load fluent-ffmpeg. Did you remember to " + + "execute `npm install fluent-ffmpeg` ?"); + } + } +} + +var acceptedCodecs = { + "mov/h264": true, + "matroska/vp8": true +}; + +exports.query = function (filename, cb) { + if (!Metadata) { + init(); + } + + if (!enabled) { + return cb("Raw file playback is not enabled on this server"); + } + + new Metadata(filename, function (meta, err) { + if (err) { + return cb(err); + } + + var video = meta.video; + if (!video) { + return cb("File has no video stream"); + } + + var codec = video.container + "/" + video.codec; + + if (!(codec in acceptedCodecs)) { + return cb("Unsupported codec " + codec); + } + + var data = { + title: meta.title || "Raw Video", + duration: meta.durationsec, + bitrate: video.bitrate, + codec: codec + }; + + cb(null, data); + }); +}; diff --git a/lib/get-info.js b/lib/get-info.js index 882ee3b3..282c3667 100644 --- a/lib/get-info.js +++ b/lib/get-info.js @@ -8,7 +8,6 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - var http = require("http"); var https = require("https"); var domain = require("domain"); @@ -17,6 +16,7 @@ var Media = require("./media"); var CustomEmbedFilter = require("./customembed").filter; var Server = require("./server"); var Config = require("./config"); +var ffmpeg = require("./ffmpeg"); var urlRetrieve = function (transport, options, callback) { // Catch any errors that crop up along the way of the request @@ -766,6 +766,21 @@ var Getters = { callback(res, null); } }); + }, + + /* ffmpeg for raw files */ + fi: function (id, cb) { + ffmpeg.query(id, function (err, data) { + if (err) { + return cb(err); + } + + var m = new Media(id, data.title, data.duration, "fi", { + bitrate: data.bitrate, + codec: data.codec + }); + cb(null, m); + }); } }; diff --git a/lib/media.js b/lib/media.js index 4d56c436..1c0ee658 100644 --- a/lib/media.js +++ b/lib/media.js @@ -31,7 +31,9 @@ Media.prototype = { object: this.meta.object, params: this.meta.params, direct: this.meta.direct, - restricted: this.meta.restricted + restricted: this.meta.restricted, + codec: this.meta.codec, + bitrate: this.meta.bitrate } }; }, diff --git a/www/js/callbacks.js b/www/js/callbacks.js index 8560c8e7..5d797b85 100644 --- a/www/js/callbacks.js +++ b/www/js/callbacks.js @@ -845,6 +845,14 @@ Callbacks = { $("#ytapiplayer_wrapper").remove(); } + if (data.type === "fi") { + if (USEROPTS.no_h264 && data.meta.codec !== "matroska/vp8") { + data.forceFlash = true; + } + + data.url = data.id; + } + /* VIMEO SIMULATOR 2014