Skip to content

Commit af3ccad

Browse files
committed
Use frames for progress ratio
1 parent 9c14cca commit af3ccad

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/createFFmpeg.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ module.exports = (_options = {}) => {
2525
let logging = optLog;
2626
let progress = optProgress;
2727
let duration = 0;
28+
let frames = 0;
29+
let readFrames = false;
2830
let ratio = 0;
2931

3032
const detectCompletion = (message) => {
@@ -53,11 +55,17 @@ module.exports = (_options = {}) => {
5355
prog({ duration: d, ratio });
5456
if (duration === 0 || duration > d) {
5557
duration = d;
58+
readFrames = true;
5659
}
60+
} else if (readFrames && message.startsWith(' Stream')) {
61+
const fps = parseFloat(message.match(/(\d+) fps/)[1]);
62+
frames = duration * fps;
63+
readFrames = false;
5764
} else if (message.startsWith('frame') || message.startsWith('size')) {
5865
const ts = message.split('time=')[1].split(' ')[0];
5966
const t = ts2sec(ts);
60-
ratio = t / duration;
67+
const f = parseFloat(message.match(/frame=\s*(\d+)/)[1]);
68+
ratio = Math.min(f / frames, 1);
6169
prog({ ratio, time: t });
6270
} else if (message.startsWith('video:')) {
6371
prog({ ratio: 1 });

0 commit comments

Comments
 (0)