Better error handling, add support for mp3/ogg-vorbis
This commit is contained in:
parent
1d1630fb50
commit
6dde745784
6 changed files with 69 additions and 26 deletions
|
|
@ -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" && media.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 " +
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue