Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Requirements

* NodeJS http://nodejs.org/
* MongoDB http://www.mongodb.org/
* FFmpeg https://ffmpeg.org/


Setup
Expand All @@ -21,7 +22,7 @@ Setup
2. Restore the DB using `AVnodeDB.zip` [mongorestore](http://docs.mongodb.org/manual/reference/program/mongorestore/) with `mongorestore --drop -d avnode <directory-of-dumped-backup>`
3. Request the file repository `/warehouse` to g.delgobbo@flyer.it (you don't need it to let the app starts)
4. Run `npm install && bower install`
5. Run `npm start`
5. Run `npm start` and `npm run start:videostranscoder`
6. Login with your FLxER user or use user: GianlucaDelGobbo password: GianlucaDelGobbo


Expand All @@ -31,6 +32,12 @@ Contributing
Want to contribute? Great!!!


Development
------------

For development we use `nodemon` to detect changes during developement. Ensure to start both scripts the main app with `npm run dev` and our videotranscoding queue worker with `npm run dev:videotranscoder`.


### Commands

1. Fork it.
Expand Down
79 changes: 79 additions & 0 deletions app/server/modules/filehandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
var FFmpeg = require('fluent-ffmpeg'),
config = require('getconfig'),
path = require('path');

// FIXME Move to config.
var directory = config.sitepath+'/warehouse/uploads/videos/';

var webPreset = function(command) {
command
.format('mp4')
//.audioCodec('libfaac')
.videoCodec('libx264')
.keepDAR();
};
var mobilePreset = function(command) {
command
.format('mp4')
//.audioCodec('libfaac')
.videoCodec('libx264')
.keepDAR()
.size('720x?');
};

var fileName = function(file) {
return path.basename(file.name, path.extname(file.name));
};

module.exports.createThumbnails = function(file, next) {
FFmpeg(directory + file.name)
.on('filenames', function(filenames) {
next(null, filenames);
})
.screenshots({
timemarks: ['10%', '25%'],
folder: directory,
filename: fileName(file) + '.png'
});
};

module.exports.mobileVersion = function(file, next) {
var start = new Date().getTime();

//FIXME Check if file is actually a transcodable video file
var destination = directory + path.basename(file.name, path.extname(file.name)) + '-mobile.mp4';
FFmpeg(directory + file.name)
.preset(mobilePreset)
.output(destination)
.on('end', function() {
var end = new Date().getTime();
var seconds = ((end - start) / 60);
console.log('Mobile version took', seconds, ' seconds');
next(null, file);
})
.run();
};

module.exports.transcode = function(file, next) {
var start = new Date().getTime();

//FIXME Check if file is actually a transcodable video file
var destination = directory + path.basename(file.name, path.extname(file.name)) + '.mp4';
FFmpeg(directory + file.name)
.preset(webPreset)
.output(destination)
.on('end', function() {
var end = new Date().getTime();
var seconds = ((end - start) / 60);
console.log('Transcoding took', seconds, ' seconds');
next(null, file);
})
.run();
};

module.exports.info = function(file, next) {
FFmpeg.ffprobe(directory+file.name, function(err, metadata) {
if (err) return next(err, null);
next(null, metadata);
});
};
35 changes: 35 additions & 0 deletions app/server/modules/queue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var config = require('getconfig'),
mongodb = require('mongodb'),
mongoDbQueue = require('mongodb-queue');

var queue = null;
var con = config.mongo;

module.exports.connect = function (done) {
mongodb.MongoClient.connect(con, function(err, db) {
queue = mongoDbQueue(db, 'queue');
done(err);
});
};

module.exports.get = function(handler) {
queue.get(handler);
};

module.exports.ping = function(ack, done) {
queue.ping(ack, done);
};

module.exports.remove = function(ack, done) {
queue.ack(ack, done);
};

module.exports.add = function(job) {
if (queue) {
queue.add(job, function(err) {
if (err) throw err;
console.log('job added', job);
});
}
};

38 changes: 31 additions & 7 deletions app/server/routes/api.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var express = require('express');
var router = express.Router();
var config = require('getconfig');

var fs = require('fs');
var process = require('process');
var path = require('path');

var multer = require('multer');
var upload = multer({ dest: process.cwd() + '/warehouse/tmp/' });
var upload = multer({ dest: config.sitepath + '/warehouse/tmp/' });
var mime = require('mime');
var sha1 = require('sha1');

Expand All @@ -16,8 +16,6 @@ var _ = require('lodash');
var validateParams = require('../validation.js').validateParams;
var Joi = require('joi');

var config = require('getconfig');

var multipart = require('connect-multiparty');
var resumable = require('../modules/resumable.js')('/tmp/avnode-uploads/');
var uuid = require('uuid');
Expand All @@ -28,7 +26,7 @@ router.post('/upload/image', upload.single('image'), function (req, res) {
var extension = mime.extension(req.file.mimetype);
if (extension === 'png' || extension === 'jpeg') {
response = '/warehouse/uploads/' + sha1(req.file.originalname) + '.' + extension;
var destAbsolute = process.cwd() + response;
var destAbsolute = config.sitepath + response;
fs.createReadStream(req.file.path).pipe(fs.createWriteStream(destAbsolute));
fs.unlink(req.file.path);
}
Expand Down Expand Up @@ -56,14 +54,15 @@ router.get(
);

router.post('/upload/files', function(req, res){
var destination = process.cwd() + '/warehouse/uploads/videos/';
var destination = config.sitepath + '/warehouse/uploads/videos/';
if (!fs.existsSync(destination)){
fs.mkdirSync(destination);
}
resumable.post(req, function(status, filename, original_filename, identifier){
if (status === 'done') {
// FIXME Path.extname can be something different than the acutal file extension.
var uniqueFileName = uuid.v4() + path.extname(filename);
var id = uuid.v4();
var uniqueFileName = id + path.extname(filename);
//when all chunks uploaded, then createWriteStream to /uploads folder with filename
var stream = fs.createWriteStream(destination + uniqueFileName);
//stitches the file chunks back together to create the original file.
Expand All @@ -75,6 +74,7 @@ router.post('/upload/files', function(req, res){
});
}
res.send({
id: id,
fileName: uniqueFileName,
status: status
});
Expand Down Expand Up @@ -189,4 +189,28 @@ router.get(
});
}
);
router.get('/video/:id/poster', function(req,res) {
try {
res.sendFile(config.sitepath + '/warehouse/uploads/videos/' + req.params.id);
}
catch (e) {
res.sendStatus(404);
}
});
router.get('/video/:id', function(req,res) {
try {
res.sendFile(config.sitepath + '/warehouse/uploads/videos/' + req.params.id + '.mp4');
}
catch (e) {
res.sendStatus(404);
}
});
router.get('/video/:id/mobile', function(req,res) {
try {
res.sendFile(config.sitepath + '/warehouse/uploads/videos/' + req.params.id + '-mobile.mp4');
}
catch (e) {
res.sendStatus(404);
}
});
module.exports = router;
33 changes: 23 additions & 10 deletions app/server/routes/controlpanel/footages.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ var User = require('../../models/user');
var config = require('getconfig');
var mongoose = require('mongoose');
var _ = require('lodash');
var Queue = require('../../modules/queue');


exports.listGet = function get(req, res) {
// In case a new one will be created
var footageId = mongoose.Types.ObjectId();
User.findOne({_id: req.user._id})
.populate('footages')
.exec(function(err, resolvedUser) {
res.render('controlpanel/footages/list', {
config: config,
user: req.user,
footages: resolvedUser.footages
footages: resolvedUser.footages,
newFootageId: footageId
});
});
};
Expand All @@ -26,19 +30,28 @@ exports.createPost = function post(req, res) {
// TODO Display error/alert, because permalink isn't unique
res.redirect('/controlpanel/footage');
} else {
var footageId = mongoose.Types.ObjectId();
if (req.body.file) {
var file = JSON.parse(req.body.file);
var attachment = new File({
_id: mongoose.Types.ObjectId(),
file: file.id,
uuid: file.uuid,
name: file.name,
original_name: file.original_name,
size: file.size,
mimetype: file.type,
duration: 129831,
encoded: false
});
Queue.add({
type: 'thumbnail',
file: file,
footage: footageId
});
Queue.add({
type: 'transcode',
file: file,
footage: footageId
});
}
var footageId = mongoose.Types.ObjectId();
new Footage({
_id: footageId,
title: req.body.title,
Expand Down Expand Up @@ -72,12 +85,11 @@ exports.updatePost = function(req, res) {
} else if (file !== null) {
attachment = new File({
_id: mongoose.Types.ObjectId(),
file: file.id,
uuid: file.uuid,
name: file.name,
original_name: file.original_name,
size: file.size,
mimetype: file.type,
duration: 129831,
encoded: false
});
}

Expand Down Expand Up @@ -115,8 +127,9 @@ exports.editGet = function(req, res) {
};

exports.filePost = function(req, res) {
var file = req.body.file;
res.status(200).json(file);
var file = JSON.parse(req.body.file);
console.log('>>>>>>>',file);
res.status(200).json(JSON.stringify(file));
};

exports.deleteReq = function post(req,res) {
Expand Down
14 changes: 10 additions & 4 deletions app/server/schema/file.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
var Schema = require('mongoose').Schema;

module.exports = new Schema({
file: String,
uuid: String,
name: String,
original_name: String,
mimetype: String,
preview: String,
size: Number,
duration: Number,
encoded:Boolean
duration: {type: Number, default: 0},
metadata: Object,
previews: Array,
status: {
preview: {type: Boolean, default: false},
transcoded: {type: Boolean, default: false},
mobile: {type: Boolean, default: false}
}
});
1 change: 0 additions & 1 deletion app/server/schema/footage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module.exports = new Schema({
text: {},
is_public: Boolean,
file: File, //always one
preview_file: String, //FIXME put it inside file
tags: [Tag],
stats: {
visits: Number,
Expand Down
1 change: 0 additions & 1 deletion app/server/schema/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var text = {};

config.locales.forEach(function(locale) {
text[locale] = String;

});

module.exports = new Schema({
Expand Down
4 changes: 0 additions & 4 deletions app/server/schema/tvshow.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ config.locales.forEach(function (locale) {
text[locale] = String;
});





module.exports = new Schema({
old_id: String,
creation_date: Date,
Expand Down
Loading