ffmpeg-progress 1.7.0 → 1.8.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/cli.js +31 -13
- 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
|
-
|
|
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();
|
|
@@ -67,28 +79,32 @@ function onProgress(args) {
|
|
|
67
79
|
writeProgress(`progress=${progress} speed=${speed}x elapsed=${elapsed} eta=${eta}`);
|
|
68
80
|
}
|
|
69
81
|
if (args.length == 0) {
|
|
70
|
-
|
|
82
|
+
writeProgress('reading ffmpeg output from pipe...');
|
|
71
83
|
(0, core_1.attachStream)({
|
|
72
84
|
stream: process.stdin,
|
|
73
85
|
onData: checkOverwrite,
|
|
74
86
|
onProgress,
|
|
75
87
|
}).on('end', () => {
|
|
76
88
|
process.stdout.write('\n');
|
|
77
|
-
|
|
89
|
+
if (verbose) {
|
|
90
|
+
console.log('end of ffmpeg output.');
|
|
91
|
+
}
|
|
78
92
|
});
|
|
79
93
|
}
|
|
80
94
|
else {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
let
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
95
|
+
if (verbose) {
|
|
96
|
+
let cmd = 'ffmpeg';
|
|
97
|
+
for (let arg of args) {
|
|
98
|
+
let str = JSON.stringify(arg);
|
|
99
|
+
if (str == `"${arg}"`) {
|
|
100
|
+
cmd += ' ' + arg;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
cmd += ' ' + str;
|
|
104
|
+
}
|
|
89
105
|
}
|
|
106
|
+
console.log('> ' + cmd);
|
|
90
107
|
}
|
|
91
|
-
console.log('> ' + cmd);
|
|
92
108
|
let childProcess = (0, child_process_1.spawn)('ffmpeg', args, {
|
|
93
109
|
stdio: ['inherit', 'pipe', 'pipe'],
|
|
94
110
|
});
|
|
@@ -99,7 +115,9 @@ else {
|
|
|
99
115
|
})
|
|
100
116
|
.then(() => {
|
|
101
117
|
process.stdout.write('\n');
|
|
102
|
-
|
|
118
|
+
if (verbose) {
|
|
119
|
+
console.log('ffmpeg process finished.');
|
|
120
|
+
}
|
|
103
121
|
})
|
|
104
122
|
.catch(error => {
|
|
105
123
|
process.stderr.write('\n');
|