Add progress
This commit is contained in:
parent
3e83d9a718
commit
7a380f529b
@ -24,6 +24,7 @@ createWorker is a factory function that creates a ffmpeg worker, a worker is bas
|
||||
- `workerPath` path for downloading worker script
|
||||
- `workerBlobURL` a boolean to define whether to use Blob URL for worker script, default: true
|
||||
- `logger` a function to log the progress, a quick example is `m => console.log(m)`
|
||||
- `progress` a function to trace the progress, a quick example is `p => console.log(p)`
|
||||
|
||||
|
||||
**Examples:**
|
||||
|
47
package-lock.json
generated
47
package-lock.json
generated
@ -811,9 +811,9 @@
|
||||
}
|
||||
},
|
||||
"@ffmpeg/core": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@ffmpeg/core/-/core-0.3.0.tgz",
|
||||
"integrity": "sha512-bm95T4C2/glYHuzTW7r49Ia+CCSYCbmOe0VOhvCorR3eBzPV/4ESuA4LxdouIraOHueDZf6rcPik94Jv1+t0iQ=="
|
||||
"version": "0.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@ffmpeg/core/-/core-0.3.1.tgz",
|
||||
"integrity": "sha512-rRybQazQF4JOzj3QA/KIukSGy2B2882AYGywaUgxGpHWEMlCMsaYSbuoBrLjEnIMpsJQx6MC7uXABWzQa1IlkA=="
|
||||
},
|
||||
"@hapi/address": {
|
||||
"version": "2.1.2",
|
||||
@ -3407,8 +3407,7 @@
|
||||
"ansi-regex": {
|
||||
"version": "2.1.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"aproba": {
|
||||
"version": "1.2.0",
|
||||
@ -3429,14 +3428,12 @@
|
||||
"balanced-match": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"balanced-match": "^1.0.0",
|
||||
"concat-map": "0.0.1"
|
||||
@ -3451,20 +3448,17 @@
|
||||
"code-point-at": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"console-control-strings": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"core-util-is": {
|
||||
"version": "1.0.2",
|
||||
@ -3581,8 +3575,7 @@
|
||||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"ini": {
|
||||
"version": "1.3.5",
|
||||
@ -3594,7 +3587,6 @@
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"number-is-nan": "^1.0.0"
|
||||
}
|
||||
@ -3609,7 +3601,6 @@
|
||||
"version": "3.0.4",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
@ -3617,14 +3608,12 @@
|
||||
"minimist": {
|
||||
"version": "0.0.8",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"minipass": {
|
||||
"version": "2.3.5",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"safe-buffer": "^5.1.2",
|
||||
"yallist": "^3.0.0"
|
||||
@ -3643,7 +3632,6 @@
|
||||
"version": "0.5.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"minimist": "0.0.8"
|
||||
}
|
||||
@ -3724,8 +3712,7 @@
|
||||
"number-is-nan": {
|
||||
"version": "1.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"object-assign": {
|
||||
"version": "4.1.1",
|
||||
@ -3737,7 +3724,6 @@
|
||||
"version": "1.4.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
@ -3823,8 +3809,7 @@
|
||||
"safe-buffer": {
|
||||
"version": "5.1.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
@ -3860,7 +3845,6 @@
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"code-point-at": "^1.0.0",
|
||||
"is-fullwidth-code-point": "^1.0.0",
|
||||
@ -3880,7 +3864,6 @@
|
||||
"version": "3.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"ansi-regex": "^2.0.0"
|
||||
}
|
||||
@ -3924,14 +3907,12 @@
|
||||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"yallist": {
|
||||
"version": "3.0.3",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -38,7 +38,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/ffmpegjs/ffmpeg.js#readme",
|
||||
"dependencies": {
|
||||
"@ffmpeg/core": "^0.3.0",
|
||||
"@ffmpeg/core": "^0.3.1",
|
||||
"is-url": "^1.2.4",
|
||||
"node-fetch": "^2.6.0",
|
||||
"regenerator-runtime": "^0.13.3",
|
||||
|
@ -1,3 +1,4 @@
|
||||
module.exports = {
|
||||
logger: () => {},
|
||||
progress: () => {},
|
||||
};
|
||||
|
@ -1,6 +1,7 @@
|
||||
const createJob = require('./createJob');
|
||||
const { log } = require('./utils/log');
|
||||
const getId = require('./utils/getId');
|
||||
const extractProgress = require('./utils/extractProgress');
|
||||
const resolvePaths = require('./utils/resolvePaths');
|
||||
const {
|
||||
defaultOptions,
|
||||
@ -17,6 +18,7 @@ module.exports = (_options = {}) => {
|
||||
const id = getId('Worker', workerCounter);
|
||||
const {
|
||||
logger,
|
||||
progress,
|
||||
...options
|
||||
} = resolvePaths({
|
||||
...defaultOptions,
|
||||
@ -131,6 +133,7 @@ module.exports = (_options = {}) => {
|
||||
rejects[action](data);
|
||||
throw Error(data);
|
||||
} else if (status === 'progress') {
|
||||
extractProgress(data, progress);
|
||||
logger(data);
|
||||
}
|
||||
});
|
||||
|
19
src/utils/extractProgress.js
Normal file
19
src/utils/extractProgress.js
Normal file
@ -0,0 +1,19 @@
|
||||
let duration = 0;
|
||||
|
||||
const ts2sec = (ts) => {
|
||||
const [h, m, s] = ts.split(':');
|
||||
return (parseFloat(h) * 60 * 60) + (parseFloat(m) * 60) + parseFloat(s);
|
||||
};
|
||||
|
||||
module.exports = ({ message }, progress) => {
|
||||
if (message.startsWith(' Duration')) {
|
||||
const ts = message.split(', ')[0].split(': ')[1];
|
||||
duration = ts2sec(ts);
|
||||
} else if (message.startsWith('frame')) {
|
||||
const ts = message.split('time=')[1].split(' ')[0];
|
||||
const t = ts2sec(ts);
|
||||
progress({ ratio: t / duration });
|
||||
} else if (message.startsWith('video:')) {
|
||||
progress({ ratio: 1 });
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user