ffmpeg-progress 1.0.1 → 1.0.2

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 (4) hide show
  1. package/README.md +10 -7
  2. package/core.d.ts +15 -9
  3. package/core.js +15 -5
  4. package/package.json +5 -5
package/README.md CHANGED
@@ -60,13 +60,16 @@ export type ProgressArgs = {
60
60
  onData?: (chunk: Buffer) => void
61
61
  onDuration?: (duration: string) => void
62
62
  onTime?: (time: string) => void
63
- onProgress?: (args: {
64
- deltaSeconds: number
65
- currentSeconds: number
66
- totalSeconds: number
67
- time: string
68
- duration: string
69
- }) => void
63
+ onProgress?: (args: OnProgressArgs) => void
64
+ }
65
+
66
+ export type OnProgressArgs = {
67
+ deltaSeconds: number
68
+ currentSeconds: number
69
+ totalSeconds: number
70
+ time: string
71
+ duration: string
72
+ abort: () => void
70
73
  }
71
74
 
72
75
  export function convertFile(
package/core.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { ChildProcessWithoutNullStreams } from 'child_process';
4
2
  export declare function parseToSeconds(str: string): number;
5
3
  export type ScanVideoResult = {
@@ -11,13 +9,15 @@ export type ProgressArgs = {
11
9
  onData?: (chunk: Buffer) => void;
12
10
  onDuration?: (duration: string) => void;
13
11
  onTime?: (time: string) => void;
14
- onProgress?: (args: {
15
- deltaSeconds: number;
16
- currentSeconds: number;
17
- totalSeconds: number;
18
- time: string;
19
- duration: string;
20
- }) => void;
12
+ onProgress?: (args: OnProgressArgs) => void;
13
+ };
14
+ export type OnProgressArgs = {
15
+ deltaSeconds: number;
16
+ currentSeconds: number;
17
+ totalSeconds: number;
18
+ time: string;
19
+ duration: string;
20
+ abort: () => void;
21
21
  };
22
22
  export declare function convertFile(args: {
23
23
  inFile: string;
@@ -26,3 +26,9 @@ export declare function convertFile(args: {
26
26
  export declare function attachChildProcess(args: {
27
27
  childProcess: ChildProcessWithoutNullStreams;
28
28
  } & ProgressArgs): Promise<void>;
29
+ export declare function estimateOutSize(args: {
30
+ inSize: number;
31
+ currentOutSize: number;
32
+ currentSeconds: number;
33
+ totalSeconds: number;
34
+ }): number;
package/core.js CHANGED
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.attachChildProcess = exports.convertFile = exports.scanVideo = exports.parseToSeconds = void 0;
3
+ exports.parseToSeconds = parseToSeconds;
4
+ exports.scanVideo = scanVideo;
5
+ exports.convertFile = convertFile;
6
+ exports.attachChildProcess = attachChildProcess;
7
+ exports.estimateOutSize = estimateOutSize;
4
8
  const child_process_1 = require("child_process");
5
9
  function parseToSeconds(str) {
6
10
  let parts = str.split(':');
@@ -9,7 +13,6 @@ function parseToSeconds(str) {
9
13
  let s = +parts[2];
10
14
  return (h * 60 + m) * 60 + s;
11
15
  }
12
- exports.parseToSeconds = parseToSeconds;
13
16
  function scanVideo(file) {
14
17
  return new Promise((resolve, reject) => {
15
18
  (0, child_process_1.exec)(`ffmpeg -i ${JSON.stringify(file)} 2>&1`, (err, stdout, stderr) => {
@@ -27,12 +30,10 @@ function scanVideo(file) {
27
30
  });
28
31
  });
29
32
  }
30
- exports.scanVideo = scanVideo;
31
33
  async function convertFile(args) {
32
34
  let childProcess = (0, child_process_1.spawn)('ffmpeg', ['-y', '-i', args.inFile, args.outFile]);
33
35
  return attachChildProcess({ childProcess, ...args });
34
36
  }
35
- exports.convertFile = convertFile;
36
37
  async function attachChildProcess(args) {
37
38
  let { code, signal } = await new Promise((resolve, reject) => {
38
39
  let { childProcess } = args;
@@ -40,6 +41,9 @@ async function attachChildProcess(args) {
40
41
  let time = '';
41
42
  let totalSeconds = 0;
42
43
  let lastSeconds = 0;
44
+ function abort() {
45
+ childProcess.kill('SIGKILL');
46
+ }
43
47
  if (args.onData) {
44
48
  childProcess.stdout.on('data', args.onData);
45
49
  }
@@ -70,6 +74,7 @@ async function attachChildProcess(args) {
70
74
  totalSeconds,
71
75
  time,
72
76
  duration,
77
+ abort,
73
78
  });
74
79
  }
75
80
  }
@@ -82,4 +87,9 @@ async function attachChildProcess(args) {
82
87
  return;
83
88
  throw new Error(`ffmpeg exit abnormally, exit code: ${code}, signal: ${signal}`);
84
89
  }
85
- exports.attachChildProcess = attachChildProcess;
90
+ function estimateOutSize(args) {
91
+ let estimatedRate = args.currentOutSize / args.currentSeconds;
92
+ let remindSeconds = args.totalSeconds - args.currentSeconds;
93
+ let estimatedOutSize = args.currentOutSize + estimatedRate * remindSeconds;
94
+ return estimatedOutSize;
95
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ffmpeg-progress",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Extract progress from ffmpeg child_process",
5
5
  "keywords": [
6
6
  "ffmpeg",
@@ -41,10 +41,10 @@
41
41
  "build": "tsc -p ."
42
42
  },
43
43
  "devDependencies": {
44
- "@beenotung/tslib": "^22.1.1",
45
- "@types/node": "^18.18.5",
46
- "ts-node": "^10.9.1",
44
+ "@beenotung/tslib": "^24.1.0",
45
+ "@types/node": "^22.9.0",
46
+ "ts-node": "^10.9.2",
47
47
  "ts-node-dev": "^2.0.0",
48
- "typescript": "^5.2.2"
48
+ "typescript": "^5.6.3"
49
49
  }
50
50
  }