From 54f2ad7c5cada197fa038847d200188d927cf763 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Tue, 19 May 2015 22:07:55 -0400 Subject: [PATCH] Fixes --- lib/ffmpeg.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/ffmpeg.js b/lib/ffmpeg.js index b044b746..972af6c8 100644 --- a/lib/ffmpeg.js +++ b/lib/ffmpeg.js @@ -2,7 +2,7 @@ var Logger = require("./logger"); var Config = require("./config"); var spawn = require("child_process").spawn; -var SUPPORTS_JSON = true; +var USE_JSON = true; var acceptedCodecs = { "mov/h264": true, @@ -62,13 +62,13 @@ function reformatData(data) { if (isNaN(bitrate)) bitrate = 0; reformatted.bitrate = bitrate; - reformatted.title = data.format.tags.title; + reformatted.title = data.format.tags ? data.format.tags.title : null; var container = data.format.format_name.split(",")[0]; data.streams.forEach(function (stream) { if (stream.codec_type === "video") { reformatted.vcodec = stream.codec_name; - if (!reformatted.title) { + if (!reformatted.title && stream.tags) { reformatted.title = stream.tags.title; } } else if (stream.codec_type === "audio") { @@ -90,7 +90,7 @@ function reformatData(data) { exports.ffprobe = function ffprobe(filename, cb) { var childErr; var args = ["-show_streams", "-show_format", filename]; - if (SUPPORTS_JSON) args = ["-of", "json"].concat(args); + if (USE_JSON) args = ["-of", "json"].concat(args); var child = spawn(Config.get("ffmpeg.ffprobe-exec"), args); var stdout = ""; var stderr = ""; @@ -109,10 +109,10 @@ exports.ffprobe = function ffprobe(filename, cb) { child.on("close", function (code) { if (code !== 0) { - if (stderr.match(/-of/)) { + if (stderr.match(/unrecognized option|json/i) && USE_JSON) { Logger.errlog.log("Warning: ffprobe does not support -of json. " + "Assuming it will have old output format."); - SUPPORTS_JSON = false; + USE_JSON = false; return ffprobe(filename, cb); } @@ -121,7 +121,7 @@ exports.ffprobe = function ffprobe(filename, cb) { } var result; - if (SUPPORTS_JSON) { + if (USE_JSON) { try { result = JSON.parse(stdout); } catch (e) { @@ -166,7 +166,7 @@ exports.query = function (filename, cb) { try { data = reformatData(data); } catch (e) { - Logger.errlog.log(err.stack || err); + Logger.errlog.log(e.stack || e); return cb("Unable to query file data with ffmpeg"); } @@ -184,17 +184,15 @@ exports.query = function (filename, cb) { cb(null, data); } else if (data.medium === "audio") { - var codec = meta.acodec; - - if (!acceptedAudioCodecs.hasOwnProperty(data.type)) { - return cb("Unsupported audio codec " + data.type); + if (!acceptedAudioCodecs.hasOwnProperty(data.acodec)) { + return cb("Unsupported audio codec " + data.acodec); } data = { title: data.title || "Raw Audio", duration: data.duration, bitrate: data.bitrate, - codec: codec + codec: data.acodec }; cb(null, data);