Allow progress callback to interpret information
fix issues described in https://github.com/ffmpegwasm/ffmpeg.wasm/issues/152
This commit is contained in:
parent
47c1d1c5d8
commit
fa80649fb4
@ -1,4 +1,5 @@
|
|||||||
let duration = 0;
|
let duration = 0;
|
||||||
|
let ratio = 0;
|
||||||
|
|
||||||
const ts2sec = (ts) => {
|
const ts2sec = (ts) => {
|
||||||
const [h, m, s] = ts.split(':');
|
const [h, m, s] = ts.split(':');
|
||||||
@ -10,13 +11,15 @@ module.exports = (message, progress) => {
|
|||||||
if (message.startsWith(' Duration')) {
|
if (message.startsWith(' Duration')) {
|
||||||
const ts = message.split(', ')[0].split(': ')[1];
|
const ts = message.split(', ')[0].split(': ')[1];
|
||||||
const d = ts2sec(ts);
|
const d = ts2sec(ts);
|
||||||
|
progress({ duration: d, ratio });
|
||||||
if (duration === 0 || duration > d) {
|
if (duration === 0 || duration > d) {
|
||||||
duration = d;
|
duration = d;
|
||||||
}
|
}
|
||||||
} else if (message.startsWith('frame') || message.startsWith('size')) {
|
} else if (message.startsWith('frame') || message.startsWith('size')) {
|
||||||
const ts = message.split('time=')[1].split(' ')[0];
|
const ts = message.split('time=')[1].split(' ')[0];
|
||||||
const t = ts2sec(ts);
|
const t = ts2sec(ts);
|
||||||
progress({ ratio: t / duration });
|
ratio = t / duration;
|
||||||
|
progress({ ratio, time: t });
|
||||||
} else if (message.startsWith('video:')) {
|
} else if (message.startsWith('video:')) {
|
||||||
progress({ ratio: 1 });
|
progress({ ratio: 1 });
|
||||||
duration = 0;
|
duration = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user