Skip to content

Commit ce36020

Browse files
committed
Frame ratio also in src/util/parseProgress.js
1 parent 7bf17ea commit ce36020

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/utils/parseProgress.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
let duration = 0;
2+
let frames = 0;
3+
let readFrames = false;
24
let ratio = 0;
35

46
const ts2sec = (ts) => {
@@ -14,11 +16,26 @@ module.exports = (message, progress) => {
1416
progress({ duration: d, ratio });
1517
if (duration === 0 || duration > d) {
1618
duration = d;
19+
readFrames = true;
1720
}
21+
} else if (readFrames && message.startsWith(' Stream')) {
22+
const match = message.match(/([\d\.]+) fps/);
23+
if (match) {
24+
const fps = parseFloat(match[1]);
25+
frames = duration * fps;
26+
} else {
27+
frames = 0;
28+
};
29+
readFrames = false;
1830
} else if (message.startsWith('frame') || message.startsWith('size')) {
1931
const ts = message.split('time=')[1].split(' ')[0];
2032
const t = ts2sec(ts);
21-
ratio = t / duration;
33+
const f = parseFloat(message.match(/frame=\s*(\d+)/)[1]);
34+
if (frames) {
35+
ratio = Math.min(f / frames, 1);
36+
} else {
37+
ratio = t / duration;
38+
};
2239
progress({ ratio, time: t });
2340
} else if (message.startsWith('video:')) {
2441
progress({ ratio: 1 });

0 commit comments

Comments
 (0)