ffmpeg-progress 1.1.1 → 1.2.0

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 (3) hide show
  1. package/core.d.ts +12 -2
  2. package/core.js +30 -1
  3. package/package.json +8 -2
package/core.d.ts CHANGED
@@ -1,9 +1,19 @@
1
1
  import { ChildProcessWithoutNullStreams } from 'child_process';
2
+ /** @description
3
+ * from "00:01:00.03" to 60.03;
4
+ * from "N/A" to NaN;
5
+ * */
2
6
  export declare function parseToSeconds(str: string): number;
7
+ /** @description
8
+ * from 60.03 to "00:01:00.03";
9
+ * from 60.123 to "00:01:00.123";
10
+ * from NaN to "N/A";
11
+ * */
12
+ export declare function secondsToString(seconds: number): string;
3
13
  export type ScanVideoResult = {
4
- /** @description e.g. "00:03:00.03" */
14
+ /** @description e.g. "00:03:00.03" or "N/A" */
5
15
  duration: string;
6
- /** @description e.g. 180.03 */
16
+ /** @description e.g. 180.03 or 0 */
7
17
  seconds: number;
8
18
  /** @description e.g. "4032x3024" */
9
19
  resolution: string;
package/core.js CHANGED
@@ -1,24 +1,53 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseToSeconds = parseToSeconds;
4
+ exports.secondsToString = secondsToString;
4
5
  exports.scanVideo = scanVideo;
5
6
  exports.convertFile = convertFile;
6
7
  exports.attachChildProcess = attachChildProcess;
7
8
  exports.estimateOutSize = estimateOutSize;
8
9
  const child_process_1 = require("child_process");
10
+ /** @description
11
+ * from "00:01:00.03" to 60.03;
12
+ * from "N/A" to NaN;
13
+ * */
9
14
  function parseToSeconds(str) {
15
+ if (str == 'N/A')
16
+ return NaN;
10
17
  let parts = str.split(':');
11
18
  let h = +parts[0];
12
19
  let m = +parts[1];
13
20
  let s = +parts[2];
14
21
  return (h * 60 + m) * 60 + s;
15
22
  }
23
+ /** @description
24
+ * from 60.03 to "00:01:00.03";
25
+ * from 60.123 to "00:01:00.123";
26
+ * from NaN to "N/A";
27
+ * */
28
+ function secondsToString(seconds) {
29
+ if (isNaN(seconds))
30
+ return 'N/A';
31
+ let h = Math.floor(seconds / 3600);
32
+ let m = Math.floor((seconds % 3600) / 60);
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}`;
38
+ }
39
+ function d2(x) {
40
+ if (x < 10)
41
+ return '0' + x;
42
+ return x;
43
+ }
16
44
  function scanVideo(file) {
17
45
  return new Promise((resolve, reject) => {
18
46
  (0, child_process_1.exec)(`ffmpeg -i ${JSON.stringify(file)} 2>&1`, (err, stdout, stderr) => {
19
47
  try {
20
48
  // e.g. " Duration: 00:03:00.03, start: 0.000000, bitrate: 2234 kb/s"
21
- let match = stdout.match(/Duration: ([0-9:.]+),/);
49
+ // e.g. " Duration: N/A, start: 0.000000, bitrate: N/A"
50
+ let match = stdout.match(/Duration: ([0-9:.]+|N\/A),/);
22
51
  if (!match) {
23
52
  throw new Error('failed to find video duration');
24
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ffmpeg-progress",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Extract progress from ffmpeg child_process",
5
5
  "keywords": [
6
6
  "ffmpeg",
@@ -37,12 +37,18 @@
37
37
  "core.js"
38
38
  ],
39
39
  "scripts": {
40
- "test": "tsc --noEmit",
40
+ "mocha": "ts-mocha *.test.ts",
41
+ "test": "npm run mocha && tsc --noEmit",
41
42
  "build": "tsc -p ."
42
43
  },
43
44
  "devDependencies": {
44
45
  "@beenotung/tslib": "^24.1.0",
46
+ "@types/chai": "^4.3.20",
47
+ "@types/mocha": "^10.0.10",
45
48
  "@types/node": "^22.9.0",
49
+ "chai": "^4.5.0",
50
+ "mocha": "^11.0.1",
51
+ "ts-mocha": "^10.0.0",
46
52
  "ts-node": "^10.9.2",
47
53
  "ts-node-dev": "^2.0.0",
48
54
  "typescript": "^5.6.3"