ffmpeg-progress 1.1.2 → 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.
- package/core.d.ts +10 -0
- package/core.js +47 -0
- package/package.json +8 -2
package/core.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
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
14
|
/** @description e.g. "00:03:00.03" or "N/A" */
|
|
5
15
|
duration: string;
|
package/core.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
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) {
|
|
10
15
|
if (str == 'N/A')
|
|
11
16
|
return NaN;
|
|
@@ -15,6 +20,48 @@ function parseToSeconds(str) {
|
|
|
15
20
|
let s = +parts[2];
|
|
16
21
|
return (h * 60 + m) * 60 + s;
|
|
17
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
|
+
// 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}`;
|
|
47
|
+
}
|
|
48
|
+
function d2(x) {
|
|
49
|
+
if (x < 10)
|
|
50
|
+
return '0' + x;
|
|
51
|
+
return x;
|
|
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
|
+
}
|
|
18
65
|
function scanVideo(file) {
|
|
19
66
|
return new Promise((resolve, reject) => {
|
|
20
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.1
|
|
3
|
+
"version": "1.2.1",
|
|
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
|
-
"
|
|
40
|
+
"mocha": "rm -f *.js && 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"
|