ffmpeg-progress 1.0.2 → 1.1.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.
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,28 @@ 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
- let match = stdout.match(/Duration: ([0-9:.]+),/);
20
- if (match) {
19
+ try {
20
+ let match = stdout.match(/Duration: ([0-9:.]+),/);
21
+ if (!match) {
22
+ throw new Error('failed to find video duration');
23
+ }
21
24
  let duration = match[1];
22
25
  let seconds = parseToSeconds(duration);
23
- resolve({ duration, seconds });
24
- return;
26
+ match = stdout.match(/Stream #0:\d.+: Video: .+ (\d+x\d+),/);
27
+ if (!match) {
28
+ throw new Error('failed to find video resolution');
29
+ }
30
+ let resolution = match[1];
31
+ resolve({ duration, seconds, resolution });
32
+ }
33
+ catch (e) {
34
+ let error = e instanceof Error ? e : new Error(String(e));
35
+ if (err) {
36
+ error.cause = err;
37
+ }
38
+ Object.assign(error, { stdout });
39
+ reject(error);
25
40
  }
26
- let error = new Error('failed to find video duration');
27
- error.cause = err;
28
- Object.assign(error, { stdout });
29
- reject(error);
30
41
  });
31
42
  });
32
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ffmpeg-progress",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Extract progress from ffmpeg child_process",
5
5
  "keywords": [
6
6
  "ffmpeg",