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
|
- `workerPath` path for downloading worker script
|
||||||
- `workerBlobURL` a boolean to define whether to use Blob URL for worker script, default: true
|
- `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)`
|
- `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:**
|
**Examples:**
|
||||||
|
47
package-lock.json
generated
47
package-lock.json
generated
@ -811,9 +811,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@ffmpeg/core": {
|
"@ffmpeg/core": {
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/@ffmpeg/core/-/core-0.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/@ffmpeg/core/-/core-0.3.1.tgz",
|
||||||
"integrity": "sha512-bm95T4C2/glYHuzTW7r49Ia+CCSYCbmOe0VOhvCorR3eBzPV/4ESuA4LxdouIraOHueDZf6rcPik94Jv1+t0iQ=="
|
"integrity": "sha512-rRybQazQF4JOzj3QA/KIukSGy2B2882AYGywaUgxGpHWEMlCMsaYSbuoBrLjEnIMpsJQx6MC7uXABWzQa1IlkA=="
|
||||||
},
|
},
|
||||||
"@hapi/address": {
|
"@hapi/address": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
@ -3407,8 +3407,7 @@
|
|||||||
"ansi-regex": {
|
"ansi-regex": {
|
||||||
"version": "2.1.1",
|
"version": "2.1.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"aproba": {
|
"aproba": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
@ -3429,14 +3428,12 @@
|
|||||||
"balanced-match": {
|
"balanced-match": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"brace-expansion": {
|
"brace-expansion": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.11",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"balanced-match": "^1.0.0",
|
"balanced-match": "^1.0.0",
|
||||||
"concat-map": "0.0.1"
|
"concat-map": "0.0.1"
|
||||||
@ -3451,20 +3448,17 @@
|
|||||||
"code-point-at": {
|
"code-point-at": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"concat-map": {
|
"concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"console-control-strings": {
|
"console-control-strings": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"core-util-is": {
|
"core-util-is": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
@ -3581,8 +3575,7 @@
|
|||||||
"inherits": {
|
"inherits": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"ini": {
|
"ini": {
|
||||||
"version": "1.3.5",
|
"version": "1.3.5",
|
||||||
@ -3594,7 +3587,6 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"number-is-nan": "^1.0.0"
|
"number-is-nan": "^1.0.0"
|
||||||
}
|
}
|
||||||
@ -3609,7 +3601,6 @@
|
|||||||
"version": "3.0.4",
|
"version": "3.0.4",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"brace-expansion": "^1.1.7"
|
"brace-expansion": "^1.1.7"
|
||||||
}
|
}
|
||||||
@ -3617,14 +3608,12 @@
|
|||||||
"minimist": {
|
"minimist": {
|
||||||
"version": "0.0.8",
|
"version": "0.0.8",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"minipass": {
|
"minipass": {
|
||||||
"version": "2.3.5",
|
"version": "2.3.5",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"safe-buffer": "^5.1.2",
|
"safe-buffer": "^5.1.2",
|
||||||
"yallist": "^3.0.0"
|
"yallist": "^3.0.0"
|
||||||
@ -3643,7 +3632,6 @@
|
|||||||
"version": "0.5.1",
|
"version": "0.5.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"minimist": "0.0.8"
|
"minimist": "0.0.8"
|
||||||
}
|
}
|
||||||
@ -3724,8 +3712,7 @@
|
|||||||
"number-is-nan": {
|
"number-is-nan": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"object-assign": {
|
"object-assign": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
@ -3737,7 +3724,6 @@
|
|||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"wrappy": "1"
|
"wrappy": "1"
|
||||||
}
|
}
|
||||||
@ -3823,8 +3809,7 @@
|
|||||||
"safe-buffer": {
|
"safe-buffer": {
|
||||||
"version": "5.1.2",
|
"version": "5.1.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"safer-buffer": {
|
"safer-buffer": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
@ -3860,7 +3845,6 @@
|
|||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"code-point-at": "^1.0.0",
|
"code-point-at": "^1.0.0",
|
||||||
"is-fullwidth-code-point": "^1.0.0",
|
"is-fullwidth-code-point": "^1.0.0",
|
||||||
@ -3880,7 +3864,6 @@
|
|||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"ansi-regex": "^2.0.0"
|
"ansi-regex": "^2.0.0"
|
||||||
}
|
}
|
||||||
@ -3924,14 +3907,12 @@
|
|||||||
"wrappy": {
|
"wrappy": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"yallist": {
|
"yallist": {
|
||||||
"version": "3.0.3",
|
"version": "3.0.3",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/ffmpegjs/ffmpeg.js#readme",
|
"homepage": "https://github.com/ffmpegjs/ffmpeg.js#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ffmpeg/core": "^0.3.0",
|
"@ffmpeg/core": "^0.3.1",
|
||||||
"is-url": "^1.2.4",
|
"is-url": "^1.2.4",
|
||||||
"node-fetch": "^2.6.0",
|
"node-fetch": "^2.6.0",
|
||||||
"regenerator-runtime": "^0.13.3",
|
"regenerator-runtime": "^0.13.3",
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
logger: () => {},
|
logger: () => {},
|
||||||
|
progress: () => {},
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
const createJob = require('./createJob');
|
const createJob = require('./createJob');
|
||||||
const { log } = require('./utils/log');
|
const { log } = require('./utils/log');
|
||||||
const getId = require('./utils/getId');
|
const getId = require('./utils/getId');
|
||||||
|
const extractProgress = require('./utils/extractProgress');
|
||||||
const resolvePaths = require('./utils/resolvePaths');
|
const resolvePaths = require('./utils/resolvePaths');
|
||||||
const {
|
const {
|
||||||
defaultOptions,
|
defaultOptions,
|
||||||
@ -17,6 +18,7 @@ module.exports = (_options = {}) => {
|
|||||||
const id = getId('Worker', workerCounter);
|
const id = getId('Worker', workerCounter);
|
||||||
const {
|
const {
|
||||||
logger,
|
logger,
|
||||||
|
progress,
|
||||||
...options
|
...options
|
||||||
} = resolvePaths({
|
} = resolvePaths({
|
||||||
...defaultOptions,
|
...defaultOptions,
|
||||||
@ -131,6 +133,7 @@ module.exports = (_options = {}) => {
|
|||||||
rejects[action](data);
|
rejects[action](data);
|
||||||
throw Error(data);
|
throw Error(data);
|
||||||
} else if (status === 'progress') {
|
} else if (status === 'progress') {
|
||||||
|
extractProgress(data, progress);
|
||||||
logger(data);
|
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