Permalink
Browse files

Use full precision timestamps, fixes #81

  • Loading branch information...
1 parent 5bf1d4d commit 56b85600085279aca3839b78b9ad15f47aaca7fb @njoyard njoyard committed Feb 28, 2014
Showing with 5 additions and 9 deletions.
  1. +1 −0 README.md
  2. +2 −7 lib/extensions.js
  3. +2 −2 test/extensions.test.js
View
1 README.md
@@ -256,6 +256,7 @@ var command = new FFmpeg({ source: '/path/to/video.avi' })
// - 'targetSize': the current size of the target file
// in kilobytes
// - 'timemark': the timestamp of the current frame
+ // in seconds
// - 'percent': an estimation of the progress
console.log('Processing: ' + progress.percent + '% done');
View
9 lib/extensions.js
@@ -39,19 +39,14 @@ exports = module.exports = function Extensions(command) {
};
command.prototype.ffmpegTimemarkToSeconds = function(timemark) {
-
// In case ffmpeg outputs the timemark as float
if(timemark.indexOf(':') === -1 && timemark.indexOf('.') >= 0)
- return parseInt(timemark)
+ return parseFloat(timemark)
var parts = timemark.split(':');
- var secs = 0;
-
- // split sec/msec part
- var secParts = parts.pop().split('.');
// add seconds
- secs += parseInt(secParts[0], 10);
+ var secs = parseFloat(parts.pop());
if (parts.length) {
// add minutes
View
4 test/extensions.test.js
@@ -45,10 +45,10 @@ describe('Extensions', function() {
ext.ffmpegTimemarkToSeconds('00:02:00.00').should.be.equal(120);
});
it('should correctly convert a complex timestamp', function() {
- ext.ffmpegTimemarkToSeconds('00:08:09.10').should.be.equal(489);
+ ext.ffmpegTimemarkToSeconds('00:08:09.10').should.be.equal(489.1);
});
it('should correclty convert a simple float timestamp', function() {
- ext.ffmpegTimemarkToSeconds('132.44').should.be.equal(132);
+ ext.ffmpegTimemarkToSeconds('132.44').should.be.equal(132.44);
});
});
});

0 comments on commit 56b8560

Please sign in to comment.