ffmpeg-progress 1.0.2 → 1.1.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/README.md +4 -0
- package/core.d.ts +4 -0
- package/core.js +22 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,8 +52,12 @@ export function parseToSeconds(str: string): number
|
|
|
52
52
|
export function scanVideo(file: string): Promise<ScanVideoResult>
|
|
53
53
|
|
|
54
54
|
export type ScanVideoResult = {
|
|
55
|
+
/** @description e.g. "00:03:00.03" */
|
|
55
56
|
duration: string
|
|
57
|
+
/** @description e.g. 180.03 */
|
|
56
58
|
seconds: number
|
|
59
|
+
/** @description e.g. "4032x3024" */
|
|
60
|
+
resolution: string
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
export type ProgressArgs = {
|
package/core.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { ChildProcessWithoutNullStreams } from 'child_process';
|
|
2
2
|
export declare function parseToSeconds(str: string): number;
|
|
3
3
|
export type ScanVideoResult = {
|
|
4
|
+
/** @description e.g. "00:03:00.03" */
|
|
4
5
|
duration: string;
|
|
6
|
+
/** @description e.g. 180.03 */
|
|
5
7
|
seconds: number;
|
|
8
|
+
/** @description e.g. "4032x3024" */
|
|
9
|
+
resolution: string;
|
|
6
10
|
};
|
|
7
11
|
export declare function scanVideo(file: string): Promise<ScanVideoResult>;
|
|
8
12
|
export type ProgressArgs = {
|
package/core.js
CHANGED
|
@@ -16,17 +16,31 @@ function parseToSeconds(str) {
|
|
|
16
16
|
function scanVideo(file) {
|
|
17
17
|
return new Promise((resolve, reject) => {
|
|
18
18
|
(0, child_process_1.exec)(`ffmpeg -i ${JSON.stringify(file)} 2>&1`, (err, stdout, stderr) => {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
try {
|
|
20
|
+
// e.g. " Duration: 00:03:00.03, start: 0.000000, bitrate: 2234 kb/s"
|
|
21
|
+
let match = stdout.match(/Duration: ([0-9:.]+),/);
|
|
22
|
+
if (!match) {
|
|
23
|
+
throw new Error('failed to find video duration');
|
|
24
|
+
}
|
|
21
25
|
let duration = match[1];
|
|
22
26
|
let seconds = parseToSeconds(duration);
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
// e.g. " Stream #0:0[0x1](und): Video: h264 (Baseline) (avc1 / 0x31637661), yuvj420p(pc, progressive), 4032x3024, 2045 kb/s, 29.73 fps, 600 tbr, 600 tbn (default)"
|
|
28
|
+
// e.g. " Stream #0:0[0x1](eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt470bg/unknown/unknown, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 3958 kb/s, 29.49 fps, 29.83 tbr, 11456 tbn (default)"
|
|
29
|
+
match = stdout.match(/Stream #0:\d.+: Video: .+ (\d+x\d+)[\s|,]/);
|
|
30
|
+
if (!match) {
|
|
31
|
+
throw new Error('failed to find video resolution');
|
|
32
|
+
}
|
|
33
|
+
let resolution = match[1];
|
|
34
|
+
resolve({ duration, seconds, resolution });
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
let error = e instanceof Error ? e : new Error(String(e));
|
|
38
|
+
if (err) {
|
|
39
|
+
error.cause = err;
|
|
40
|
+
}
|
|
41
|
+
Object.assign(error, { stdout });
|
|
42
|
+
reject(error);
|
|
25
43
|
}
|
|
26
|
-
let error = new Error('failed to find video duration');
|
|
27
|
-
error.cause = err;
|
|
28
|
-
Object.assign(error, { stdout });
|
|
29
|
-
reject(error);
|
|
30
44
|
});
|
|
31
45
|
});
|
|
32
46
|
}
|