Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

dynamic progress line parsing, added 5m video to test onProgress, fix…

…ed presets since ffmpeg does not include libfaac support anymore
  • Loading branch information...
commit d420d046beedac1d928f2553e6e9e5680cefe044 1 parent db7e3d3
@saschagehlich saschagehlich authored
View
4 lib/fluent-ffmpeg.js
@@ -121,6 +121,10 @@ function FfmpegCommand(args) {
this.options.video.fpsInput = fps;
return this;
};
+ FfmpegCommand.prototype.withStrictExperimental = function() {
+ this.options.strictExperimental = true;
+ return this;
+ }
FfmpegCommand.prototype.withFpsOutput = function(fps) {
this.options.video.fpsOutput = fps;
return this;
View
5 lib/presets/flashvideo.js
@@ -7,8 +7,9 @@ exports.load = function(ffmpeg) {
.withVideoCodec('libx264')
.withFps(24)
.withAudioBitrate('96k')
- .withAudioCodec('libfaac')
+ .withAudioCodec('aac')
+ .withStrictExperimental()
.withAudioFrequency(22050)
.withAudioChannels(2);
return ffmpeg;
-};
+};
View
3  lib/presets/podcast.js
@@ -5,7 +5,8 @@ exports.load = function(ffmpeg) {
.withVideoCodec('libx264')
.withSize('320x176')
.withAudioBitrate('128k')
- .withAudioCodec('libfaac')
+ .withAudioCodec('aac')
+ .withStrictExperimental()
.withAudioChannels(1)
.addOptions(['-flags', '+loop', '-cmp', '+chroma', '-partitions','+parti4x4+partp8x8+partb8x8', '-flags2',
'+mixed_refs', '-me_method umh', '-subq 5', '-bufsize 2M', '-rc_eq \'blurCplx^(1-qComp)\'',
View
68 lib/processor.js
@@ -104,7 +104,6 @@ exports = module.exports = function Processor(command) {
}
if (options.onProgress) {
self._getProgressFromStdErr(stderr, self.metaData.durationsec);
-
}
});
});
@@ -196,11 +195,11 @@ exports = module.exports = function Processor(command) {
else{
cb();
}
-
+
});
-
+
},callback);
-
+
}
var unescapePath = function(path){
@@ -209,18 +208,18 @@ exports = module.exports = function Processor(command) {
if(f.lastIndexOf('"')== f.length-1)f = f.substring(0, f.length-1);
return f;
}
-
+
var makeProgress = function(){
progress.createdFiles = progress.createdFiles + 1;
progress.precent = progress.createdFiles/progress.totalFiles*100;
progressCallback(progress);
}
-
+
if(options.mergeList.length<=0)throw new Error("No file added to be merged");
-
+
var mergeList = options.mergeList;
mergeList.unshift(options.inputfile);
-
+
var progressCallback = this.options.onProgress || function(){};
var progress = {frames : 0,
currentFps: 0,
@@ -230,12 +229,12 @@ exports = module.exports = function Processor(command) {
percent: 0,
totalFiles: mergeList.length + 2,
createdFiles: 0}
-
+
var toDelete = mergeList.map(function(name){return name + ".temp.mpg"});
toDelete.push(this.options.outputfile + ".temp.merged.mpg");
deleteIntermediateFiles(toDelete);
-
-
+
+
var intermediateFiles = [];
async.whilst(function(){
@@ -547,16 +546,16 @@ exports = module.exports = function Processor(command) {
var ll = lastLine[lastLine.length - 2];
var progress;
if (ll) {
- progress = ll.split(/frame=([0-9\s]+)fps=([0-9\.\s]+)q=([0-9\.\s]+)(L?)size=([0-9\s]+)kB time=(([0-9]{2}):([0-9]{2}):([0-9]{2}).([0-9]{2})) bitrate=([0-9\.\s]+)kbits/ig);
+ progress = this._parseProgressLine(ll);
}
- if (progress && progress.length > 10) {
+ if (progress) {
// build progress report object
var ret = {
- frames: parseInt(progress[1], 10),
- currentFps: parseInt(progress[2], 10),
- currentKbps: parseFloat(progress[10]),
- targetSize: parseInt(progress[5], 10),
- timemark: progress[6]
+ frames: parseInt(progress.frame, 10),
+ currentFps: parseInt(progress.fps, 10),
+ currentKbps: parseFloat(progress.bitrate.replace("kbits/s", "")),
+ targetSize: parseInt(progress.size, 10),
+ timemark: progress.time
};
// calculate percent progress using duration
@@ -568,6 +567,29 @@ exports = module.exports = function Processor(command) {
}
};
+ command.prototype._parseProgressLine = function(line) {
+ var progress = {};
+
+ // Remove all spaces after = and trim
+ line = line.replace(/=\s+/g, '=').trim()
+ progressParts = line.split(' ')
+
+ // Split every progress part by "=" to get key and value
+ for(var i = 0; i < progressParts.length; i++) {
+ var progressSplit = progressParts[i].split("=", 2)
+ , key = progressSplit[0]
+ , value = progressSplit[1]
+
+ // This is not a progress line
+ if(typeof value === "undefined")
+ return null;
+
+ progress[key] = value
+ }
+
+ return progress
+ };
+
command.prototype._checkStdErrForCodec = function(stderrString) {
var format= /Input #[0-9]+, ([^ ]+),/.exec(stderrString);
var dur = /Duration\: ([^,]+)/.exec(stderrString);
@@ -634,7 +656,7 @@ exports = module.exports = function Processor(command) {
// add startoffset and duration
if (this.options.starttime) {
args.push('-ss', this.options.starttime);
- }
+ }
if (this.options.video.loop) {
if (this.atLeastVersion(this.meta().ffmpegversion, '0.9')){
@@ -644,7 +666,7 @@ exports = module.exports = function Processor(command) {
args.push('-loop_output', 1);
}
}
-
+
// add input format
if (this.options.fromFormat) {
@@ -696,6 +718,10 @@ exports = module.exports = function Processor(command) {
}
}
+ if (this.options.strictExperimental) {
+ args.push('-strict', 'experimental');
+ }
+
if (this.options.duration) {
args.push('-t', this.options.duration);
}
@@ -804,5 +830,5 @@ exports = module.exports = function Processor(command) {
}
return args;
};
-
+
};
View
7 test/args.test.js
@@ -32,7 +32,8 @@ describe('Command', function() {
new Ffmpeg({ source: this.testfile, nolog: true })
.usingPreset('podcast')
.getArgs(function(args) {
- args.length.should.equal(42); // on a side note: it's 42 args by coincidence ;)
+ args.length.should.equal(44); // on a side note: it's 42 args by coincidence ;)
+ // on a side note: not anymore, sorry :(
done();
});
});
@@ -283,7 +284,7 @@ describe('Command', function() {
args.indexOf('-ab').should.above(-1);
args.indexOf('256k').should.above(-1);
done();
- });
+ });
});
});
@@ -312,7 +313,7 @@ describe('Command', function() {
else{
done(new Error("args should contain loop or loop_output"))
}
-
+
});
});
it('should add the -loop 1 and a time argument (timemark)', function(done) {
View
BIN  test/assets/testvideo-5m.mpg
Binary file not shown
View
2  test/debug.test.js
@@ -32,7 +32,7 @@ describe('Debug', function() {
new Ffmpeg({ source: this.testfile, nolog: true })
.usingPreset('podcast')
.getArgs(function(args) {
- args.length.should.equal(42);
+ args.length.should.equal(44);
done();
});
});
View
11 test/extensions.test.js
@@ -15,7 +15,7 @@ describe('Extensions', function() {
assert.ok(!ext.toAspectRatio('15.929'));
});
});
-
+
describe('parseVersionString', function() {
it('should parse the major/minor/patch version correctly', function() {
var ret = ext.parseVersionString('4.5.123');
@@ -24,7 +24,7 @@ describe('Extensions', function() {
ret.should.have.property('patch').with.valueOf(123);
});
});
-
+
describe('atLeastVersion', function() {
it('should correctly compare a full version number', function() {
ext.atLeastVersion('2.3.4532', '2.3.4531').should.be.true;
@@ -39,7 +39,7 @@ describe('Extensions', function() {
ext.atLeastVersion('1.2.34', '1.2.34').should.be.true;
});
});
-
+
describe('ffmpegTimemarkToSeconds', function() {
it('should correctly convert a simple timestamp', function() {
ext.ffmpegTimemarkToSeconds('00:02:00.00').should.be.equal(120);
@@ -47,5 +47,8 @@ describe('Extensions', function() {
it('should correctly convert a complex timestamp', function() {
ext.ffmpegTimemarkToSeconds('00:08:09.10').should.be.equal(489);
});
+ it('should correclty convert a simple float timestamp', function() {
+ ext.ffmpegTimemarkToSeconds('132.44').should.be.equal(132);
+ });
});
-});
+});
View
26 test/processor.test.js
@@ -11,6 +11,7 @@ describe('Processor', function() {
// check for ffmpeg installation
this.testfile = path.join(__dirname, 'assets', 'testvideo-43.avi');
this.testfilewide = path.join(__dirname, 'assets', 'testvideo-169.avi');
+ this.testfilebig = path.join(__dirname, 'assets', 'testvideo-5m.mpg');
var self = this;
exec(testhelper.getFfmpegCheck(), function(err, stdout, stderr) {
@@ -56,13 +57,14 @@ describe('Processor', function() {
});
it('should report progress through event onProgress', function(done) {
- var testFile = path.join(__dirname, 'assets', 'testOnProgress.flv');
+ this.timeout(15000)
- new Ffmpeg({ source: this.testfile, nolog: true })
+ var testFile = path.join(__dirname, 'assets', 'testOnProgress.flv')
+ , gotProgress = false;
+
+ new Ffmpeg({ source: this.testfilebig, nolog: true })
.onProgress(function(data) {
- // conversion is too fast to make any progress reporting on the test assets,
- // but it's idiotic to commit a 5M+ file to github just for 1 test.
- // I'll leave this test here for coverage's sake...
+ gotProgress = true;
})
.usingPreset('flashvideo')
.saveToFile(testFile, function(code, err) {
@@ -70,6 +72,8 @@ describe('Processor', function() {
if (exist) {
fs.unlinkSync(testFile);
}
+
+ gotProgress.should.be.true;
done();
});
});
@@ -128,7 +132,7 @@ describe('Processor', function() {
});
});
});
-
+
it('should save the output file properly to disk using a stream', function(done) {
var testFile = path.join(__dirname, 'assets', 'te[s]t video \' " .flv');
@@ -143,7 +147,7 @@ describe('Processor', function() {
});
});
});
-
+
it('should kill the process on timeout', function(done) {
var testFile = path.join(__dirname, 'assets', 'testProcessKill.flv');
@@ -166,7 +170,7 @@ describe('Processor', function() {
});
});
});
-
+
describe('saveToFile', function() {
it('should save the output file properly to disk', function(done) {
var testFile = path.join(__dirname, 'assets', 'testConvertToFile.flv');
@@ -188,7 +192,7 @@ describe('Processor', function() {
});
});
});
-
+
it('should accept a stream as its source', function(done) {
var testFile = path.join(__dirname, 'assets', 'testConvertFromStreamToFile.flv');
var instream = fs.createReadStream(this.testfile);
@@ -233,7 +237,7 @@ describe('Processor', function() {
});
});
});
-
+
it('should accept a stream as its source', function(done) {
var testFile = path.join(__dirname, 'assets', 'testConvertFromStreamToStream.flv');
var instream = fs.createReadStream(this.testfile);
@@ -256,7 +260,7 @@ describe('Processor', function() {
});
});
});
-
+
describe('takeScreenshot',function(){
it('should return error with wrong size',function(done){
var proc = new Ffmpeg({ source: path.join(__dirname, 'assets', 'testConvertToStream.flv')})
Please sign in to comment.
Something went wrong with that request. Please try again.