Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 632e511

Browse files
committed
use command data to extract progress percent
1 parent cd17940 commit 632e511

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

lib/processor.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -516,14 +516,8 @@ module.exports = function(proto) {
516516

517517
// 'progress' event
518518
if (self.listeners('progress').length) {
519-
var duration = 0;
520-
521-
if (self._ffprobeData && self._ffprobeData.format && self._ffprobeData.format.duration) {
522-
duration = Number(self._ffprobeData.format.duration);
523-
}
524-
525519
stderrRing.callback(function(line) {
526-
utils.extractProgress(self, line, duration);
520+
utils.extractProgress(self, line);
527521
});
528522
}
529523
}

lib/utils.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ var utils = module.exports = {
324324
* @param {Number} [duration=0] expected output duration in seconds
325325
* @private
326326
*/
327-
extractProgress: function(command, stderrLine, duration) {
327+
extractProgress: function(command, stderrLine) {
328328
var progress = parseProgressLine(stderrLine);
329329

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

340340
// calculate percent progress using duration
341-
if (duration && duration > 0) {
342-
ret.percent = (utils.timemarkToSeconds(ret.timemark) / duration) * 100;
341+
if (command._ffprobeData && command._ffprobeData.format && command._ffprobeData.format.duration) {
342+
var duration = Number(command._ffprobeData.format.duration);
343+
if (!isNaN(duration))
344+
ret.percent = (utils.timemarkToSeconds(ret.timemark) / duration) * 100;
343345
}
344-
345346
command.emit('progress', ret);
346347
}
347348
},

0 commit comments

Comments
 (0)