Better error handling, add support for mp3/ogg-vorbis

This commit is contained in:
Calvin Montgomery 2014-06-05 21:58:26 -07:00
parent 1d1630fb50
commit b8ed36df5a
6 changed files with 69 additions and 26 deletions

View file

@ -885,7 +885,8 @@ PlaylistModule.prototype._addItem = function (media, data, user, cb) {
}
/* Warn about possibly unsupported formats */
if (media.type === "fi" && media.meta.codec !== "mov/h264" &&
if (media.type === "fi" && meta.meta.codec.indexOf("/") !== -1 &&
media.meta.codec !== "mov/h264" &&
media.meta.codec !== "flv/h264") {
user.socket.emit("queueWarn", {
msg: "The codec <code>" + media.meta.codec + "</code> is not supported " +

View file

@ -9,7 +9,7 @@ function init() {
Metadata = require("fluent-ffmpeg").Metadata;
Logger.syslog.log("Enabling raw file support with fluent-ffmpeg");
enabled = true;
} catch (e) {
} catch (e) {
Logger.errlog.log("Failed to load fluent-ffmpeg. Did you remember to " +
"execute `npm install fluent-ffmpeg` ?");
}
@ -24,6 +24,11 @@ var acceptedCodecs = {
"ogg/theora": true,
};
var acceptedAudioCodecs = {
"mp3": true,
"vorbis": true
};
exports.query = function (filename, cb) {
if (!Metadata) {
init();
@ -38,24 +43,50 @@ exports.query = function (filename, cb) {
return cb(err);
}
var video = meta.video;
if (!video) {
return cb("File has no video stream");
if (isVideo(meta)) {
var video = meta.video;
var codec = video.container + "/" + video.codec;
if (!(codec in acceptedCodecs)) {
return cb("Unsupported video codec " + codec);
}
var data = {
title: meta.title || "Raw Video",
duration: meta.durationsec,
bitrate: video.bitrate,
codec: codec
};
cb(null, data);
} else if (isAudio(meta)) {
var audio = meta.audio;
var codec = audio.codec;
if (!(codec in acceptedAudioCodecs)) {
return cb("Unsupported audio codec " + codec);
}
var data = {
title: meta.title || "Raw Audio",
duration: meta.durationsec,
bitrate: audio.bitrate,
codec: codec
};
cb(null, data);
} else {
return cb("Parsed metadata did not contain a valid video or audio stream. " +
"Either the file is invalid or it has a format unsupported by " +
"this server's version of ffmpeg.");
}
var codec = video.container + "/" + video.codec;
if (!(codec in acceptedCodecs)) {
return cb("Unsupported video codec " + codec);
}
var data = {
title: meta.title || "Raw Video",
duration: meta.durationsec,
bitrate: video.bitrate,
codec: codec
};
cb(null, data);
});
};
function isVideo(meta) {
return meta.video && meta.video.bitrate > 0 && meta.video.container && meta.video.codec;
}
function isAudio(meta) {
return meta.audio && meta.audio.bitrate > 0 && meta.audio.codec;
}

View file

@ -846,7 +846,7 @@ Callbacks = {
}
if (data.type === "fi") {
if (USEROPTS.no_h264 && data.meta.codec !== "matroska/vp8") {
if (USEROPTS.no_h264 && data.meta.codec === "mov/h264") {
data.forceFlash = true;
}

View file

@ -1155,7 +1155,14 @@ function FilePlayer(data) {
self.init = function (data) {
self.videoId = data.id;
self.videoURL = data.url;
var video = $("<video/>")
var isAudio = data.meta.codec && data.meta.codec.match(/^mp3$|^vorbis$/);
var video;
if (isAudio) {
video = $("<audio/>");
} else {
video = $("<video/>")
}
video
.attr("src", self.videoURL)
.attr("controls", "controls")
.attr("id", "#ytapiplayer")
@ -1175,7 +1182,11 @@ function FilePlayer(data) {
};
self.load = function (data) {
self.init(data);
if (data.forceFlash) {
self.initFlash(data);
} else {
self.init(data);
}
};
self.pause = function () {

View file

@ -398,7 +398,7 @@ $("#mediaurl").keyup(function(ev) {
}
var url = $("#mediaurl").val().split("?")[0];
if (url.match(/^https?:\/\/(.*)?\.(flv|mp4|ogg|webm)$/)) {
if (url.match(/^https?:\/\/(.*)?\.(flv|mp4|og[gv]|webm|mp3)$/)) {
var title = $("#addfromurl-title");
if (title.length === 0) {
title = $("<div/>")

View file

@ -1289,7 +1289,7 @@ function parseMediaLink(url) {
/* Raw file */
var tmp = url.split("?")[0];
if (tmp.match(/^https?:\/\//)) {
if (tmp.match(/\.(mp4|flv|webm|ogg)$/)) {
if (tmp.match(/\.(mp4|flv|webm|og[gv]|mp3)$/)) {
return {
id: url,
type: "fi"
@ -1298,7 +1298,7 @@ function parseMediaLink(url) {
Callbacks.queueFail({
link: url,
msg: "The file you are attempting to queue does not match the supported " +
"file extensions mp4, flv, webm, ogg."
"file extensions mp4, flv, webm, ogg, ogv, mp3."
});
throw new Error("ERROR_QUEUE_UNSUPPORTED_EXTENSION");
}