ffmpeg-progress 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/core.js +25 -4
  2. package/package.json +2 -2
package/core.js CHANGED
@@ -31,16 +31,37 @@ function secondsToString(seconds) {
31
31
  let h = Math.floor(seconds / 3600);
32
32
  let m = Math.floor((seconds % 3600) / 60);
33
33
  let s = Math.floor(seconds % 60);
34
- let ms = (seconds * 1000) % 1000;
35
- return ms < 100
36
- ? `${d2(h)}:${d2(m)}:${d2(s)}.${d2(ms / 10)}`
37
- : `${d2(h)}:${d2(m)}:${d2(s)}.${ms}`;
34
+ // handle precision edge case, e.g. 60.1234 % 1 = 0.12339999999999662
35
+ let ms;
36
+ let str = seconds.toString();
37
+ if (str.includes('.')) {
38
+ ms = str.split('.')[1];
39
+ }
40
+ else {
41
+ ms = '';
42
+ }
43
+ if (!ms) {
44
+ return `${d2(h)}:${d2(m)}:${d2(s)}`;
45
+ }
46
+ return `${d2(h)}:${d2(m)}:${d2(s)}.${ms}`;
38
47
  }
39
48
  function d2(x) {
40
49
  if (x < 10)
41
50
  return '0' + x;
42
51
  return x;
43
52
  }
53
+ function format_ms(ms) {
54
+ // round 0.123.39999999999418 to 0.123
55
+ let seconds = ms / 1000;
56
+ let str = seconds.toFixed(3);
57
+ seconds = +str;
58
+ ms = seconds * 1000;
59
+ if (ms < 10)
60
+ return '00' + ms;
61
+ if (ms < 100)
62
+ return '0' + ms;
63
+ return ms;
64
+ }
44
65
  function scanVideo(file) {
45
66
  return new Promise((resolve, reject) => {
46
67
  (0, child_process_1.exec)(`ffmpeg -i ${JSON.stringify(file)} 2>&1`, (err, stdout, stderr) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ffmpeg-progress",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Extract progress from ffmpeg child_process",
5
5
  "keywords": [
6
6
  "ffmpeg",
@@ -37,7 +37,7 @@
37
37
  "core.js"
38
38
  ],
39
39
  "scripts": {
40
- "mocha": "ts-mocha *.test.ts",
40
+ "mocha": "rm -f *.js && ts-mocha *.test.ts",
41
41
  "test": "npm run mocha && tsc --noEmit",
42
42
  "build": "tsc -p ."
43
43
  },