Skip to content

Commit 249e58e

Browse files
author
Sebastian Bean
committed
added custom ffmpeg
1 parent 4b9dbc0 commit 249e58e

File tree

2 files changed

+36
-38
lines changed

2 files changed

+36
-38
lines changed

lib/uploadhandler.js

+35-37
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ module.exports = function (options) {
4444
size: stats.size
4545
});
4646
this.initUrls(fileInfo);
47+
48+
if(options.videoTypes.test(name))
49+
fileInfo.is_video = true
50+
4751
files.push(fileInfo);
4852
}
4953
}, this);
@@ -99,43 +103,37 @@ module.exports = function (options) {
99103
var generatePreviews = function () {
100104

101105
if (options.videoTypes.test(fileInfo.name)) {
102-
var image_path = options.uploadDir() + '/' + path.basename(file.path) + '.png';
103-
console.log(image_path)
104-
break;
105-
var proc = new ffmpeg({
106-
// input source, required
107-
source: options.uploadDir() + '/' + fileInfo.name,
108-
// timout of the spawned ffmpeg sub-processes in seconds (optional, defaults to 30)
109-
timeout: 30,
110-
// default priority for all ffmpeg sub-processes (optional, defaults to 0 which is no priorization)
111-
priority: 0,
112-
// 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)
113-
logger: null,
114-
// completely disable logging (optional, defaults to false)
115-
nolog: false
116-
})
117-
// .withSize('450x?')
118-
.addOption('-vframes', '1')
119-
.onProgress(function(progress) {
120-
// console.log(progress);
121-
})
122-
.saveToFile(image_path, function(retcode, error) {
123-
console.log('file has been converted succesfully');
124-
_.each(options.imageVersions, function (value, version) {
125-
// creating directory recursive
126-
if (!fs.existsSync(options.uploadDir() + '/' + version + '/'))
127-
mkdirp.sync(options.uploadDir() + '/' + version + '/');
128-
129-
counter++;
130-
var opts = options.imageVersions[version];
131-
imageMagick.resize({
132-
width: opts.width,
133-
height: opts.height,
134-
srcPath: image_path,
135-
dstPath: options.uploadDir() + '/' + version + '/' + fileInfo.name
136-
}, finish);
137-
});
138-
})
106+
107+
var video_path = options.uploadDir() + '/' + fileInfo.name
108+
109+
110+
111+
_.each(options.imageVersions, function (opts, version) {
112+
// var version_dir = options.uploadDir() + '/' + version + '/';
113+
// creating directory recursive
114+
// if (!fs.existsSync(version_dir))
115+
// mkdirp.sync(version_dir);
116+
117+
counter++;
118+
119+
console.log('video path '+ video_path);
120+
121+
var proc = new ffmpeg({
122+
// input source, required
123+
source: video_path
124+
})
125+
.withSize(opts.width + 'x?')
126+
.takeScreenshots({
127+
count: 1,
128+
timemarks: ['0'],
129+
filename: '/%b'
130+
}, path.join(options.uploadDir(), version), function(err, filenames) {
131+
console.log('files ' + filenames + ' error ' + err)
132+
finish();
133+
})
134+
});
135+
136+
139137
}
140138

141139
if (options.imageTypes.test(fileInfo.name)) {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"imagemagick": ">=0.1.2",
1515
"lodash": ">= 0.9.2",
1616
"mkdirp": ">= 0.3.4",
17-
"fluent-ffmpeg" : "latest"
17+
"fluent-ffmpeg" : "git://github.com/sebbean/node-fluent-ffmpeg.git#master"
1818
},
1919
"engines": {
2020
"node": ">= 0.8.8"

0 commit comments

Comments
 (0)