fix mp4 upload and video conversion progress display; fixes #21
This commit is contained in:
parent
dc986dcc7e
commit
c075c562d6
@ -92,14 +92,14 @@ function createWaveform(fileName, localFilePath, callback){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertVideo(fileName, filePath, codec, callback, progress_callback) {
|
function convertVideo(fileName, filePath, codec, callback, progressCallback) {
|
||||||
var ext = path.extname(fileName);
|
var ext = path.extname(fileName);
|
||||||
var presetMime = mime.lookup(fileName);
|
var presetMime = mime.lookup(fileName);
|
||||||
|
|
||||||
var newExt = codec == "mp4" ? "mp4" : "ogv";
|
var newExt = codec == "mp4" ? "mp4" : "ogv";
|
||||||
var convertedPath = filePath + "." + newExt;
|
var convertedPath = filePath + "." + newExt;
|
||||||
|
|
||||||
console.log("converting", filePath, "to", convertedPath, "progress_cb:",progress_callback);
|
console.log("converting", filePath, "to", convertedPath);
|
||||||
|
|
||||||
var convertArgs = (codec == "mp4") ? [
|
var convertArgs = (codec == "mp4") ? [
|
||||||
"-i", filePath,
|
"-i", filePath,
|
||||||
@ -134,8 +134,8 @@ function convertVideo(fileName, filePath, codec, callback, progress_callback) {
|
|||||||
|
|
||||||
ff.stderr.on('data', function (data) {
|
ff.stderr.on('data', function (data) {
|
||||||
console.log('[ffmpeg-video] stderr: ' + data);
|
console.log('[ffmpeg-video] stderr: ' + data);
|
||||||
if (progress_callback) {
|
if (progressCallback) {
|
||||||
progress_callback(data);
|
progressCallback(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -280,7 +280,7 @@ var resizeAndUploadImage = function(a, mimeType, size, fileName, fileNameOrg, im
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
convert: function(a, fileName, localFilePath, payloadCallback, progress_callback) {
|
convert: function(a, fileName, localFilePath, payloadCallback, progressCallback) {
|
||||||
getMime(fileName, localFilePath, function(err, mimeType){
|
getMime(fileName, localFilePath, function(err, mimeType){
|
||||||
console.log("[convert] fn: "+fileName+" local: "+localFilePath+" mimeType:", mimeType);
|
console.log("[convert] fn: "+fileName+" local: "+localFilePath+" mimeType:", mimeType);
|
||||||
|
|
||||||
@ -311,8 +311,8 @@ module.exports = {
|
|||||||
var s3Key = "s"+ a.space_id.toString() + "/a" + a._id.toString() + "/" + fileName;
|
var s3Key = "s"+ a.space_id.toString() + "/a" + a._id.toString() + "/" + fileName;
|
||||||
|
|
||||||
uploader.uploadFile(s3Key, "image/gif", localFilePath, function(err, url) {
|
uploader.uploadFile(s3Key, "image/gif", localFilePath, function(err, url) {
|
||||||
if(err)callback(err);
|
if (err) payloadCallback(err);
|
||||||
else{
|
else {
|
||||||
console.log(localFilePath);
|
console.log(localFilePath);
|
||||||
var stats = fs.statSync(localFilePath);
|
var stats = fs.statSync(localFilePath);
|
||||||
|
|
||||||
@ -357,8 +357,8 @@ module.exports = {
|
|||||||
thumbnail: function(callback) {
|
thumbnail: function(callback) {
|
||||||
createThumbnailForVideo(fileName, localFilePath, function(err, created){
|
createThumbnailForVideo(fileName, localFilePath, function(err, created){
|
||||||
console.log("thumbnail created: ", err, created);
|
console.log("thumbnail created: ", err, created);
|
||||||
if(err) callback(err);
|
if (err) callback(err);
|
||||||
else{
|
else {
|
||||||
var keyName = "s" + a.space_id.toString() + "/a" + a._id.toString() + "/" + fileName + ".jpg" ;
|
var keyName = "s" + a.space_id.toString() + "/a" + a._id.toString() + "/" + fileName + ".jpg" ;
|
||||||
uploader.uploadFile(keyName, "image/jpeg", created, function(err, url){
|
uploader.uploadFile(keyName, "image/jpeg", created, function(err, url){
|
||||||
if (err) callback(err);
|
if (err) callback(err);
|
||||||
@ -380,7 +380,7 @@ module.exports = {
|
|||||||
else callback(null, url);
|
else callback(null, url);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, progress_callback);
|
}, progressCallback);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mp4: function(callback) {
|
mp4: function(callback) {
|
||||||
@ -396,7 +396,7 @@ module.exports = {
|
|||||||
else callback(null, url);
|
else callback(null, url);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, progress_callback);
|
}, progressCallback);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
original: function(callback){
|
original: function(callback){
|
||||||
@ -404,7 +404,7 @@ module.exports = {
|
|||||||
callback(null, url);
|
callback(null, url);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, function(err, results){
|
}, function(err, results) {
|
||||||
console.log(err, results);
|
console.log(err, results);
|
||||||
|
|
||||||
if (err) payloadCallback(err, a);
|
if (err) payloadCallback(err, a);
|
||||||
@ -438,19 +438,16 @@ module.exports = {
|
|||||||
db.packArtifact(a);
|
db.packArtifact(a);
|
||||||
|
|
||||||
a.updated_at = new Date();
|
a.updated_at = new Date();
|
||||||
a.save(function(err) {
|
a.save().then(function() {
|
||||||
if (err) payloadCallback(err, null);
|
fs.unlink(localFilePath, function (err) {
|
||||||
else {
|
if (err) {
|
||||||
fs.unlink(localFilePath, function (err) {
|
console.error(err);
|
||||||
if (err){
|
payloadCallback(err, null);
|
||||||
console.error(err);
|
} else {
|
||||||
payloadCallback(err, null);
|
console.log('successfully deleted ' + localFilePath);
|
||||||
} else {
|
payloadCallback(null, a);
|
||||||
console.log('successfully deleted ' + localFilePath);
|
}
|
||||||
payloadCallback(null, a);
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -123,11 +123,11 @@ router.post('/:artifact_id/payload', function(req, res, next) {
|
|||||||
var writeStream = fs.createWriteStream(localFilePath);
|
var writeStream = fs.createWriteStream(localFilePath);
|
||||||
var stream = req.pipe(writeStream);
|
var stream = req.pipe(writeStream);
|
||||||
|
|
||||||
var progress_callback = function(progress_msg) {
|
var progressCallback = function(progressMsg) {
|
||||||
a.description = progress_msg.toString();
|
a.description = progressMsg.toString();
|
||||||
db.packArtifact(a);
|
db.packArtifact(a);
|
||||||
a.save();
|
a.save();
|
||||||
redis.sendMessage("update", a, JSON.stringify(a), req.channelId);
|
redis.sendMessage("update", "Artifact", a, req.channelId);
|
||||||
};
|
};
|
||||||
|
|
||||||
stream.on('finish', function() {
|
stream.on('finish', function() {
|
||||||
@ -137,7 +137,7 @@ router.post('/:artifact_id/payload', function(req, res, next) {
|
|||||||
db.Space.update({ updated_at: new Date() }, {where: {_id: req.space._id}});
|
db.Space.update({ updated_at: new Date() }, {where: {_id: req.space._id}});
|
||||||
res.distributeUpdate("Artifact", artifact);
|
res.distributeUpdate("Artifact", artifact);
|
||||||
}
|
}
|
||||||
}, progress_callback);
|
}, progressCallback);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res.status(401).json({
|
res.status(401).json({
|
||||||
|
Loading…
Reference in New Issue
Block a user