ffmpeg-progress 1.7.0 → 1.8.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.
Files changed (2) hide show
  1. package/cli.js +53 -13
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const child_process_1 = require("child_process");
4
4
  const core_1 = require("./core");
5
5
  let args = process.argv.slice(2);
6
+ let custom_args = [];
7
+ let verbose = false;
6
8
  for (let arg of args) {
7
9
  if (arg == '-h' || arg == '--help') {
8
10
  console.log(`
@@ -20,9 +22,13 @@ EXAMPLES:
20
22
  # pipe from ffmpeg output (need to redirect stderr):
21
23
  ffmpeg -i input.mp4 -c:v libx264 output.mp4 2>&1 | ffmpeg-progress
22
24
 
25
+ # using calling other script that use ffmpeg indirectly
26
+ to-mp4 --auto-name input.mov | ffmpeg-progress
27
+
23
28
  OPTIONS:
24
29
  -h, --help show this help message and exit
25
- -v, --version show version and exit
30
+ --version show version and exit
31
+ --verbose verbose mode
26
32
 
27
33
  NOTES:
28
34
  - Pipe mode requires redirecting ffmpeg stderr to stdout (2>&1)
@@ -36,7 +42,13 @@ NOTES:
36
42
  console.log(`ffmpeg-progress ${pkg.version}`);
37
43
  process.exit(0);
38
44
  }
45
+ if (arg == '--verbose') {
46
+ verbose = true;
47
+ custom_args.push(arg);
48
+ continue;
49
+ }
39
50
  }
51
+ args = args.filter(arg => !custom_args.includes(arg));
40
52
  let errorLines = [];
41
53
  function checkOverwrite(chunk) {
42
54
  let str = chunk.toString();
@@ -66,29 +78,52 @@ function onProgress(args) {
66
78
  (args.currentSeconds / (passedTime / 1000)));
67
79
  writeProgress(`progress=${progress} speed=${speed}x elapsed=${elapsed} eta=${eta}`);
68
80
  }
81
+ function timestamp() {
82
+ let date = new Date();
83
+ let y = date.getFullYear();
84
+ let m = (date.getMonth() + 1).toString().padStart(2, '0');
85
+ let d = date.getDate().toString().padStart(2, '0');
86
+ let H = date.getHours().toString().padStart(2, '0');
87
+ let M = date.getMinutes().toString().padStart(2, '0');
88
+ let S = date.getSeconds().toString().padStart(2, '0');
89
+ return `${y}-${m}-${d} ${H}:${M}:${S}`;
90
+ }
91
+ function logVerbose(message) {
92
+ console.log(`[${timestamp()}] ${message}`);
93
+ }
69
94
  if (args.length == 0) {
70
- console.log('reading ffmpeg output from pipe...');
95
+ if (verbose) {
96
+ logVerbose('reading ffmpeg output from pipe...');
97
+ }
98
+ else {
99
+ writeProgress('reading ffmpeg output from pipe...');
100
+ }
71
101
  (0, core_1.attachStream)({
72
102
  stream: process.stdin,
73
103
  onData: checkOverwrite,
74
104
  onProgress,
75
105
  }).on('end', () => {
76
106
  process.stdout.write('\n');
77
- console.log('end of ffmpeg output.');
107
+ if (verbose) {
108
+ logVerbose('end of ffmpeg output.');
109
+ }
78
110
  });
79
111
  }
80
112
  else {
81
- let cmd = 'ffmpeg';
82
- for (let arg of args) {
83
- let str = JSON.stringify(arg);
84
- if (str == `"${arg}"`) {
85
- cmd += ' ' + arg;
86
- }
87
- else {
88
- cmd += ' ' + str;
113
+ if (verbose) {
114
+ let cmd = 'ffmpeg';
115
+ for (let arg of args) {
116
+ let str = JSON.stringify(arg);
117
+ if (str == `"${arg}"`) {
118
+ cmd += ' ' + arg;
119
+ }
120
+ else {
121
+ cmd += ' ' + str;
122
+ }
89
123
  }
124
+ console.log('> ' + cmd);
125
+ logVerbose('starting ffmpeg process...');
90
126
  }
91
- console.log('> ' + cmd);
92
127
  let childProcess = (0, child_process_1.spawn)('ffmpeg', args, {
93
128
  stdio: ['inherit', 'pipe', 'pipe'],
94
129
  });
@@ -99,9 +134,14 @@ else {
99
134
  })
100
135
  .then(() => {
101
136
  process.stdout.write('\n');
102
- console.log('ffmpeg process finished.');
137
+ if (verbose) {
138
+ logVerbose('ffmpeg process finished.');
139
+ }
103
140
  })
104
141
  .catch(error => {
142
+ if (verbose) {
143
+ logVerbose('ffmpeg process failed.');
144
+ }
105
145
  process.stderr.write('\n');
106
146
  for (let line of errorLines) {
107
147
  console.error(line);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ffmpeg-progress",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "Extract progress from ffmpeg child_process",
5
5
  "keywords": [
6
6
  "ffmpeg",