Skip to content

Commit

Permalink
use command data to extract progress percent
Browse files Browse the repository at this point in the history
  • Loading branch information
richywalls committed Jul 19, 2016
1 parent cd17940 commit 632e511
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
8 changes: 1 addition & 7 deletions lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,8 @@ module.exports = function(proto) {

// 'progress' event
if (self.listeners('progress').length) {
var duration = 0;

if (self._ffprobeData && self._ffprobeData.format && self._ffprobeData.format.duration) {
duration = Number(self._ffprobeData.format.duration);
}

stderrRing.callback(function(line) {
utils.extractProgress(self, line, duration);
utils.extractProgress(self, line);
});
}
}
Expand Down
9 changes: 5 additions & 4 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ var utils = module.exports = {
* @param {Number} [duration=0] expected output duration in seconds
* @private
*/
extractProgress: function(command, stderrLine, duration) {
extractProgress: function(command, stderrLine) {
var progress = parseProgressLine(stderrLine);

if (progress) {
Expand All @@ -338,10 +338,11 @@ var utils = module.exports = {
};

// calculate percent progress using duration
if (duration && duration > 0) {
ret.percent = (utils.timemarkToSeconds(ret.timemark) / duration) * 100;
if (command._ffprobeData && command._ffprobeData.format && command._ffprobeData.format.duration) {
var duration = Number(command._ffprobeData.format.duration);
if (!isNaN(duration))
ret.percent = (utils.timemarkToSeconds(ret.timemark) / duration) * 100;
}

command.emit('progress', ret);
}
},
Expand Down

0 comments on commit 632e511

Please sign in to comment.