From 5df2044c90d0426d7a107ca8872c1aa6e3081db2 Mon Sep 17 00:00:00 2001 From: Sebastian Bean Date: Mon, 3 Dec 2012 23:40:29 -0500 Subject: [PATCH 1/4] added ffmpeg support to uploader --- .DS_Store | Bin 0 -> 6148 bytes index.js | 3 ++- lib/uploadhandler.js | 39 +++++++++++++++++++++++++++++++++++++++ package.json | 3 ++- 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f9f60d0a8f94f19a9f55d4bcbfeaf7866207ada5 GIT binary patch literal 6148 zcmeH~Jr2S!425mzfW*>~F$)La1`&c2Z~;_UkSZ}C_8gt(pM}DVD)cPbU+mOs`-Y|# z5#2wpJCR;QR&b+iElf<2FJ+XQ4A;kH9PangN^Xm!72v&0_H&z{0#twsPys4H1!kl` z9^|X_jGl>)LItS6JQT3+LxCG>vIYIqf#4$m*rDu(wa*e@u>x3=Er<$CqZN!+^)bZi z-VT<$t|nVB+C_8t(7dzS6a&*}7cEF&S{)2jfC@|$SVrF4`G16eoBt;*OsN1B_%j8x zJDd)Cyi}g8AFpTib5?EL;GkcQ@b(jc#E#+(+ztE17GO=bASy8a2)GOkRN$uyyZ{;| B5o7=W literal 0 HcmV?d00001 diff --git a/index.js b/index.js index 4abb708..7c6a06c 100644 --- a/index.js +++ b/index.js @@ -70,7 +70,8 @@ JqueryFileUploadMiddleware.prototype.prepareOptions = function (options) { minFileSize: 1, maxFileSize: 10000000000, // 10 GB acceptFileTypes: /.+/i, - imageTypes: /\.(gif|jpe?g|png)$/i, + imageTypes: /\.(gif|jpe?g|png|mp4)$/i, + videoTypes: /\.(mp4|mov|wmv|avi)$/i, imageVersions: { // thumbnail: { // width: 80, diff --git a/lib/uploadhandler.js b/lib/uploadhandler.js index dcd81b2..3b94999 100644 --- a/lib/uploadhandler.js +++ b/lib/uploadhandler.js @@ -96,6 +96,45 @@ module.exports = function (options) { } var generatePreviews = function () { + + if (options.videoTypes.test(fileInfo.name)) { + var image_path = options.uploadDir() + '/' + path.basename(file.path) + '.png'; + var proc = new ffmpeg({ + // input source, required + source: '/Users/seb/Desktop/rock_show_360.mp4', + // timout of the spawned ffmpeg sub-processes in seconds (optional, defaults to 30) + timeout: 30, + // default priority for all ffmpeg sub-processes (optional, defaults to 0 which is no priorization) + priority: 0, + // set a custom [winston](https://github.com/flatiron/winston) logging instance (optional, default null which will cause fluent-ffmpeg to spawn a winston console logger) + logger: null, + // completely disable logging (optional, defaults to false) + nolog: false + }) + // .withSize('450x?') + .addOption('-vframes', '1') + .onProgress(function(progress) { + // console.log(progress); + }) + .saveToFile(image_path, function(retcode, error) { + console.log('file has been converted succesfully'); + _.each(options.imageVersions, function (value, version) { + // creating directory recursive + if (!fs.existsSync(options.uploadDir() + '/' + version + '/')) + mkdirp.sync(options.uploadDir() + '/' + version + '/'); + + counter++; + var opts = options.imageVersions[version]; + imageMagick.resize({ + width: opts.width, + height: opts.height, + srcPath: image_path, + dstPath: options.uploadDir() + '/' + version + '/' + fileInfo.name + }, finish); + }); + }) + } + if (options.imageTypes.test(fileInfo.name)) { _.each(options.imageVersions, function (value, version) { // creating directory recursive diff --git a/package.json b/package.json index 8ab826b..dfe5210 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "formidable": ">=1.0.11", "imagemagick": ">=0.1.2", "lodash": ">= 0.9.2", - "mkdirp": ">= 0.3.4" + "mkdirp": ">= 0.3.4", + "fluent-ffmpeg" : "latest" }, "engines": { "node": ">= 0.8.8" From 17aa725461b8caeff627b3bbc2273e07365876ac Mon Sep 17 00:00:00 2001 From: Sebastian Bean Date: Mon, 3 Dec 2012 23:44:32 -0500 Subject: [PATCH 2/4] stupid ffmpeg missing --- lib/uploadhandler.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/uploadhandler.js b/lib/uploadhandler.js index 3b94999..910faba 100644 --- a/lib/uploadhandler.js +++ b/lib/uploadhandler.js @@ -4,7 +4,8 @@ var EventEmitter = require('events').EventEmitter, formidable = require('formidable'), imageMagick = require('imagemagick'), mkdirp = require('mkdirp'), - _ = require('lodash'); + _ = require('lodash'), + ffmpeg = require('fluent-ffmpeg') module.exports = function (options) { From 4b9dbc0cd7fef8df0edb6b400e93e0a88cd4707b Mon Sep 17 00:00:00 2001 From: Sebastian Bean Date: Tue, 4 Dec 2012 08:57:43 -0500 Subject: [PATCH 3/4] using info name for upload --- .DS_Store | Bin 6148 -> 6148 bytes lib/uploadhandler.js | 4 +++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.DS_Store b/.DS_Store index f9f60d0a8f94f19a9f55d4bcbfeaf7866207ada5..f832d5bcee7509294594782efb4428cc753e6442 100644 GIT binary patch delta 349 zcmZoMXfc=|#>B`mF;R?_gMono$Pkfb0y02=8HgDf7z7xK3zBm3lYqSSNd*%Vm)CF^yG8vMR%8?~=GK)(L46ZRUF|)9;v2y?cPfU1bUP^wsQ+{b)N^x{>Mt*s4W=d*O zVo@xZU6NQ*TI`fq1eOU%EXe@MfY~AW`8hy#3{-V^W=cs$ynsY?wWVdfsg8n?sX?ud zLbbWMfsTTSu|;hyClCm1<`7lVv+)Q?tf{T5ZveUy2pEB000Ukq4WpWX45%+sij#Aa zfEI$3LWRnLi}G^v^U{GLFauy3Hx~S3oopb&vYDHMn*$hl8xy}XPv#dAjHu~3+iaq>k*FU;>j242(b;hy@subCUA&a~L->GO@937GPS$ jxS5@Up9827DDs_oGQWr-CrE7qNZ(`=9_7t3A}g2y_FNED diff --git a/lib/uploadhandler.js b/lib/uploadhandler.js index 910faba..09bb2f1 100644 --- a/lib/uploadhandler.js +++ b/lib/uploadhandler.js @@ -100,9 +100,11 @@ module.exports = function (options) { if (options.videoTypes.test(fileInfo.name)) { var image_path = options.uploadDir() + '/' + path.basename(file.path) + '.png'; + console.log(image_path) + break; var proc = new ffmpeg({ // input source, required - source: '/Users/seb/Desktop/rock_show_360.mp4', + source: options.uploadDir() + '/' + fileInfo.name, // timout of the spawned ffmpeg sub-processes in seconds (optional, defaults to 30) timeout: 30, // default priority for all ffmpeg sub-processes (optional, defaults to 0 which is no priorization) From 249e58ec0a6502ac1cd265246a8758ce0255c8a5 Mon Sep 17 00:00:00 2001 From: Sebastian Bean Date: Tue, 4 Dec 2012 09:24:16 -0500 Subject: [PATCH 4/4] added custom ffmpeg --- lib/uploadhandler.js | 72 +++++++++++++++++++++----------------------- package.json | 2 +- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/lib/uploadhandler.js b/lib/uploadhandler.js index 09bb2f1..fc178a4 100644 --- a/lib/uploadhandler.js +++ b/lib/uploadhandler.js @@ -44,6 +44,10 @@ module.exports = function (options) { size: stats.size }); this.initUrls(fileInfo); + + if(options.videoTypes.test(name)) + fileInfo.is_video = true + files.push(fileInfo); } }, this); @@ -99,43 +103,37 @@ module.exports = function (options) { var generatePreviews = function () { if (options.videoTypes.test(fileInfo.name)) { - var image_path = options.uploadDir() + '/' + path.basename(file.path) + '.png'; - console.log(image_path) - break; - var proc = new ffmpeg({ - // input source, required - source: options.uploadDir() + '/' + fileInfo.name, - // timout of the spawned ffmpeg sub-processes in seconds (optional, defaults to 30) - timeout: 30, - // default priority for all ffmpeg sub-processes (optional, defaults to 0 which is no priorization) - priority: 0, - // set a custom [winston](https://github.com/flatiron/winston) logging instance (optional, default null which will cause fluent-ffmpeg to spawn a winston console logger) - logger: null, - // completely disable logging (optional, defaults to false) - nolog: false - }) - // .withSize('450x?') - .addOption('-vframes', '1') - .onProgress(function(progress) { - // console.log(progress); - }) - .saveToFile(image_path, function(retcode, error) { - console.log('file has been converted succesfully'); - _.each(options.imageVersions, function (value, version) { - // creating directory recursive - if (!fs.existsSync(options.uploadDir() + '/' + version + '/')) - mkdirp.sync(options.uploadDir() + '/' + version + '/'); - - counter++; - var opts = options.imageVersions[version]; - imageMagick.resize({ - width: opts.width, - height: opts.height, - srcPath: image_path, - dstPath: options.uploadDir() + '/' + version + '/' + fileInfo.name - }, finish); - }); - }) + + var video_path = options.uploadDir() + '/' + fileInfo.name + + + + _.each(options.imageVersions, function (opts, version) { + // var version_dir = options.uploadDir() + '/' + version + '/'; + // creating directory recursive + // if (!fs.existsSync(version_dir)) + // mkdirp.sync(version_dir); + + counter++; + + console.log('video path '+ video_path); + + var proc = new ffmpeg({ + // input source, required + source: video_path + }) + .withSize(opts.width + 'x?') + .takeScreenshots({ + count: 1, + timemarks: ['0'], + filename: '/%b' + }, path.join(options.uploadDir(), version), function(err, filenames) { + console.log('files ' + filenames + ' error ' + err) + finish(); + }) + }); + + } if (options.imageTypes.test(fileInfo.name)) { diff --git a/package.json b/package.json index dfe5210..5757319 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "imagemagick": ">=0.1.2", "lodash": ">= 0.9.2", "mkdirp": ">= 0.3.4", - "fluent-ffmpeg" : "latest" + "fluent-ffmpeg" : "git://github.com/sebbean/node-fluent-ffmpeg.git#master" }, "engines": { "node": ">= 0.8.8"