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.
- package/cli.js +53 -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();
|
|
@@ -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
|
-
|
|
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
|
-
|
|
107
|
+
if (verbose) {
|
|
108
|
+
logVerbose('end of ffmpeg output.');
|
|
109
|
+
}
|
|
78
110
|
});
|
|
79
111
|
}
|
|
80
112
|
else {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
let
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
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);
|