forked from fluent-ffmpeg/node-fluent-ffmpeg
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.d.ts
More file actions
510 lines (473 loc) · 21.5 KB
/
index.d.ts
File metadata and controls
510 lines (473 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
/// <reference types="node" />
import * as events from "events";
import * as stream from "stream";
declare namespace Ffmpeg {
interface FfmpegCommandLogger {
error(...data: any[]): void;
warn(...data: any[]): void;
info(...data: any[]): void;
debug(...data: any[]): void;
}
interface FfmpegCommandOptions {
logger?: FfmpegCommandLogger | undefined;
niceness?: number | undefined;
priority?: number | undefined;
presets?: string | undefined;
preset?: string | undefined;
stdoutLines?: number | undefined;
timeout?: number | undefined;
terminateTimeout?: number | undefined;
source?: string | stream.Readable | undefined;
cwd?: string | undefined;
signal?: AbortSignal | undefined; // an AbortSignal to cancel the command
}
interface FilterSpecification {
filter: string;
inputs?: string | string[] | undefined;
outputs?: string | string[] | undefined;
options?: any | string | any[] | undefined;
}
type PresetFunction = (command: FfmpegCommand) => void;
interface Filter {
description: string;
input: string;
multipleInputs: boolean;
output: string;
multipleOutputs: boolean;
}
interface Filters {
[key: string]: Filter;
}
type FiltersCallback = (err: Error, filters: Filters) => void;
interface Codec {
type: string;
description: string;
canDecode: boolean;
canEncode: boolean;
drawHorizBand?: boolean | undefined;
directRendering?: boolean | undefined;
weirdFrameTruncation?: boolean | undefined;
intraFrameOnly?: boolean | undefined;
isLossy?: boolean | undefined;
isLossless?: boolean | undefined;
}
interface Codecs {
[key: string]: Codec;
}
type CodecsCallback = (err: Error, codecs: Codecs) => void;
interface Encoder {
type: string;
description: string;
frameMT: boolean;
sliceMT: boolean;
experimental: boolean;
drawHorizBand: boolean;
directRendering: boolean;
}
interface Encoders {
[key: string]: Encoder;
}
type EncodersCallback = (err: Error, encoders: Encoders) => void;
interface Format {
description: string;
canDemux: boolean;
canMux: boolean;
}
interface Formats {
[key: string]: Format;
}
type FormatsCallback = (err: Error, formats: Formats) => void;
interface FfprobeData {
streams: FfprobeStream[];
format: FfprobeFormat;
chapters: any[];
}
interface FfprobeStream {
[key: string]: any;
index: number;
codec_name?: string | undefined;
codec_long_name?: string | undefined;
profile?: number | undefined;
codec_type?: string | undefined;
codec_time_base?: string | undefined;
codec_tag_string?: string | undefined;
codec_tag?: string | undefined;
width?: number | undefined;
height?: number | undefined;
coded_width?: number | undefined;
coded_height?: number | undefined;
has_b_frames?: number | undefined;
sample_aspect_ratio?: string | undefined;
display_aspect_ratio?: string | undefined;
pix_fmt?: string | undefined;
level?: string | undefined;
color_range?: string | undefined;
color_space?: string | undefined;
color_transfer?: string | undefined;
color_primaries?: string | undefined;
chroma_location?: string | undefined;
field_order?: string | undefined;
timecode?: string | undefined;
refs?: number | undefined;
id?: string | undefined;
r_frame_rate?: string | undefined;
avg_frame_rate?: string | undefined;
time_base?: string | undefined;
start_pts?: number | undefined;
start_time?: number | undefined;
duration_ts?: string | undefined;
duration?: string | undefined;
bit_rate?: string | undefined;
max_bit_rate?: string | undefined;
bits_per_raw_sample?: string | undefined;
nb_frames?: string | undefined;
nb_read_frames?: string | undefined;
nb_read_packets?: string | undefined;
sample_fmt?: string | undefined;
sample_rate?: number | undefined;
channels?: number | undefined;
channel_layout?: string | undefined;
bits_per_sample?: number | undefined;
disposition?: FfprobeStreamDisposition | undefined;
rotation?: string | number | undefined;
}
interface FfprobeStreamDisposition {
[key: string]: any;
default?: number | undefined;
dub?: number | undefined;
original?: number | undefined;
comment?: number | undefined;
lyrics?: number | undefined;
karaoke?: number | undefined;
forced?: number | undefined;
hearing_impaired?: number | undefined;
visual_impaired?: number | undefined;
clean_effects?: number | undefined;
attached_pic?: number | undefined;
timed_thumbnails?: number | undefined;
}
interface FfprobeFormat {
[key: string]: any;
filename?: string | undefined;
nb_streams?: number | undefined;
nb_programs?: number | undefined;
format_name?: string | undefined;
format_long_name?: string | undefined;
start_time?: number | undefined;
duration?: number | undefined;
size?: number | undefined;
bit_rate?: number | undefined;
probe_score?: number | undefined;
tags?: Record<string, string | number> | undefined;
}
interface ScreenshotsConfig {
count?: number | undefined;
folder?: string | undefined;
filename?: string | undefined;
timemarks?: number[] | string[] | undefined;
timestamps?: number[] | string[] | undefined;
fastSeek?: boolean | undefined;
size?: string | undefined;
}
interface AudioVideoFilter {
filter: string;
options: string | string[] | {};
}
// static methods
function setFfmpegPath(path: string): FfmpegCommand;
function setFfprobePath(path: string): FfmpegCommand;
function setFlvtoolPath(path: string): FfmpegCommand;
function availableFilters(callback: FiltersCallback): void;
function getAvailableFilters(callback: FiltersCallback): void;
function availableCodecs(callback: CodecsCallback): void;
function getAvailableCodecs(callback: CodecsCallback): void;
function availableEncoders(callback: EncodersCallback): void;
function getAvailableEncoders(callback: EncodersCallback): void;
function availableFormats(callback: FormatsCallback): void;
function getAvailableFormats(callback: FormatsCallback): void;
class FfmpegCommand extends events.EventEmitter {
constructor(options?: FfmpegCommandOptions);
constructor(input?: string | stream.Readable, options?: FfmpegCommandOptions);
// options/inputs
mergeAdd(source: string | stream.Readable): FfmpegCommand;
addInput(source: string | stream.Readable): FfmpegCommand;
input(source: string | stream.Readable): FfmpegCommand;
withInputFormat(format: string): FfmpegCommand;
inputFormat(format: string): FfmpegCommand;
fromFormat(format: string): FfmpegCommand;
withInputFps(fps: number): FfmpegCommand;
withInputFPS(fps: number): FfmpegCommand;
withFpsInput(fps: number): FfmpegCommand;
withFPSInput(fps: number): FfmpegCommand;
inputFPS(fps: number): FfmpegCommand;
inputFps(fps: number): FfmpegCommand;
fpsInput(fps: number): FfmpegCommand;
FPSInput(fps: number): FfmpegCommand;
nativeFramerate(): FfmpegCommand;
withNativeFramerate(): FfmpegCommand;
native(): FfmpegCommand;
setStartTime(seek: string | number): FfmpegCommand;
seekInput(seek: string | number): FfmpegCommand;
loop(duration?: string | number): FfmpegCommand;
// options/audio
withNoAudio(): FfmpegCommand;
noAudio(): FfmpegCommand;
withAudioCodec(codec: string): FfmpegCommand;
audioCodec(codec: string): FfmpegCommand;
withAudioBitrate(bitrate: string | number): FfmpegCommand;
audioBitrate(bitrate: string | number): FfmpegCommand;
withAudioChannels(channels: number): FfmpegCommand;
audioChannels(channels: number): FfmpegCommand;
withAudioFrequency(freq: number): FfmpegCommand;
audioFrequency(freq: number): FfmpegCommand;
withAudioQuality(quality: number): FfmpegCommand;
audioQuality(quality: number): FfmpegCommand;
withAudioFilter(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
withAudioFilters(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
audioFilter(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
audioFilters(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
// options/video;
withNoVideo(): FfmpegCommand;
noVideo(): FfmpegCommand;
withVideoCodec(codec: string): FfmpegCommand;
videoCodec(codec: string): FfmpegCommand;
withVideoBitrate(bitrate: string | number, constant?: boolean): FfmpegCommand;
videoBitrate(bitrate: string | number, constant?: boolean): FfmpegCommand;
withVideoFilter(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
withVideoFilters(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
videoFilter(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
videoFilters(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
withOutputFps(fps: number): FfmpegCommand;
withOutputFPS(fps: number): FfmpegCommand;
withFpsOutput(fps: number): FfmpegCommand;
withFPSOutput(fps: number): FfmpegCommand;
withFps(fps: number): FfmpegCommand;
withFPS(fps: number): FfmpegCommand;
outputFPS(fps: number): FfmpegCommand;
outputFps(fps: number): FfmpegCommand;
fpsOutput(fps: number): FfmpegCommand;
FPSOutput(fps: number): FfmpegCommand;
fps(fps: number): FfmpegCommand;
FPS(fps: number): FfmpegCommand;
takeFrames(frames: number): FfmpegCommand;
withFrames(frames: number): FfmpegCommand;
frames(frames: number): FfmpegCommand;
// options/videosize
keepPixelAspect(): FfmpegCommand;
keepDisplayAspect(): FfmpegCommand;
keepDisplayAspectRatio(): FfmpegCommand;
keepDAR(): FfmpegCommand;
withSize(size: string): FfmpegCommand;
setSize(size: string): FfmpegCommand;
size(size: string): FfmpegCommand;
withAspect(aspect: string | number): FfmpegCommand;
withAspectRatio(aspect: string | number): FfmpegCommand;
setAspect(aspect: string | number): FfmpegCommand;
setAspectRatio(aspect: string | number): FfmpegCommand;
aspect(aspect: string | number): FfmpegCommand;
aspectRatio(aspect: string | number): FfmpegCommand;
applyAutopadding(pad?: boolean, color?: string): FfmpegCommand;
applyAutoPadding(pad?: boolean, color?: string): FfmpegCommand;
applyAutopad(pad?: boolean, color?: string): FfmpegCommand;
applyAutoPad(pad?: boolean, color?: string): FfmpegCommand;
withAutopadding(pad?: boolean, color?: string): FfmpegCommand;
withAutoPadding(pad?: boolean, color?: string): FfmpegCommand;
withAutopad(pad?: boolean, color?: string): FfmpegCommand;
withAutoPad(pad?: boolean, color?: string): FfmpegCommand;
autoPad(pad?: boolean, color?: string): FfmpegCommand;
autopad(pad?: boolean, color?: string): FfmpegCommand;
// options/output
addOutput(target: string | stream.Writable, pipeopts?: { end?: boolean | undefined }): FfmpegCommand;
output(target: string | stream.Writable, pipeopts?: { end?: boolean | undefined }): FfmpegCommand;
seekOutput(seek: string | number): FfmpegCommand;
seek(seek: string | number): FfmpegCommand;
withDuration(duration: string | number): FfmpegCommand;
setDuration(duration: string | number): FfmpegCommand;
duration(duration: string | number): FfmpegCommand;
toFormat(format: string): FfmpegCommand;
withOutputFormat(format: string): FfmpegCommand;
outputFormat(format: string): FfmpegCommand;
format(format: string): FfmpegCommand;
map(spec: string): FfmpegCommand;
updateFlvMetadata(): FfmpegCommand;
flvmeta(): FfmpegCommand;
// options/custom
addInputOption(options: string[]): FfmpegCommand;
addInputOption(...options: string[]): FfmpegCommand;
addInputOptions(options: string[]): FfmpegCommand;
addInputOptions(...options: string[]): FfmpegCommand;
withInputOption(options: string[]): FfmpegCommand;
withInputOption(...options: string[]): FfmpegCommand;
withInputOptions(options: string[]): FfmpegCommand;
withInputOptions(...options: string[]): FfmpegCommand;
inputOption(options: string[]): FfmpegCommand;
inputOption(...options: string[]): FfmpegCommand;
inputOptions(options: string[]): FfmpegCommand;
inputOptions(...options: string[]): FfmpegCommand;
addOutputOption(options: string[]): FfmpegCommand;
addOutputOption(...options: string[]): FfmpegCommand;
addOutputOptions(options: string[]): FfmpegCommand;
addOutputOptions(...options: string[]): FfmpegCommand;
addOption(options: string[]): FfmpegCommand;
addOption(...options: string[]): FfmpegCommand;
addOptions(options: string[]): FfmpegCommand;
addOptions(...options: string[]): FfmpegCommand;
withOutputOption(options: string[]): FfmpegCommand;
withOutputOption(...options: string[]): FfmpegCommand;
withOutputOptions(options: string[]): FfmpegCommand;
withOutputOptions(...options: string[]): FfmpegCommand;
withOption(options: string[]): FfmpegCommand;
withOption(...options: string[]): FfmpegCommand;
withOptions(options: string[]): FfmpegCommand;
withOptions(...options: string[]): FfmpegCommand;
outputOption(options: string[]): FfmpegCommand;
outputOption(...options: string[]): FfmpegCommand;
outputOptions(options: string[]): FfmpegCommand;
outputOptions(...options: string[]): FfmpegCommand;
filterGraph(
spec: string | FilterSpecification | Array<string | FilterSpecification>,
map?: string[] | string,
): FfmpegCommand;
complexFilter(
spec: string | FilterSpecification | Array<string | FilterSpecification>,
map?: string[] | string,
): FfmpegCommand;
// options/misc
usingPreset(preset: string | PresetFunction): FfmpegCommand;
preset(preset: string | PresetFunction): FfmpegCommand;
// processor
renice(niceness: number): FfmpegCommand;
kill(signal: string): FfmpegCommand;
_getArguments(): string[];
// capabilities
setFfmpegPath(path: string): FfmpegCommand;
setFfprobePath(path: string): FfmpegCommand;
setFlvtoolPath(path: string): FfmpegCommand;
availableFilters(callback: FiltersCallback): void;
getAvailableFilters(callback: FiltersCallback): void;
availableCodecs(callback: CodecsCallback): void;
getAvailableCodecs(callback: CodecsCallback): void;
availableEncoders(callback: EncodersCallback): void;
getAvailableEncoders(callback: EncodersCallback): void;
availableFormats(callback: FormatsCallback): void;
getAvailableFormats(callback: FormatsCallback): void;
// ffprobe
ffprobe(callback: (err: any, data: FfprobeData) => void): void;
ffprobe(index: number, callback: (err: any, data: FfprobeData) => void): void;
ffprobe(options: string[], callback: (err: any, data: FfprobeData) => void): void; // tslint:disable-line unified-signatures
ffprobe(index: number, options: string[], callback: (err: any, data: FfprobeData) => void): void;
// event listeners
/**
* Emitted just after ffmpeg has been spawned.
*
* @event FfmpegCommand#start
* @param command ffmpeg command line
*/
on(event: "start", listener: (command: string) => void): this;
/**
* Emitted when ffmpeg reports progress information
*
* @event FfmpegCommand#progress
* @param progress progress object
* @param progress.frames number of frames transcoded
* @param progress.currentFps current processing speed in frames per second
* @param progress.currentKbps current output generation speed in kilobytes per second
* @param progress.targetSize current output file size
* @param progress.timemark current video timemark
* @param [progress.percent] processing progress (may not be available depending on input)
*/
on(
event: "progress",
listener: (progress: {
frames: number;
currentFps: number;
currentKbps: number;
targetSize: number;
timemark: string;
percent?: number | undefined;
}) => void,
): this;
/**
* Emitted when ffmpeg outputs to stderr
*
* @event FfmpegCommand#stderr
* @param line stderr output line
*/
on(event: "stderr", listener: (line: string) => void): this;
/**
* Emitted when ffmpeg reports input codec data
*
* @event FfmpegCommand#codecData
* @param codecData codec data object
* @param codecData.format input format name
* @param codecData.audio input audio codec name
* @param codecData.audio_details input audio codec parameters
* @param codecData.video input video codec name
* @param codecData.video_details input video codec parameters
* @param codecData.duration input video duration
*/
on(
event: "codecData",
listener: (codecData: {
format: string;
audio: string;
audio_details: string[];
video: string;
video_details: string[];
duration: string;
}) => void,
): this;
/**
* Emitted when an error happens when preparing or running a command
*
* @event FfmpegCommand#error
* @param error error object, with optional properties 'inputStreamError' / 'outputStreamError' for errors on their respective streams
* @param stdout ffmpeg stdout, unless outputting to a stream
* @param stderr ffmpeg stderr
*/
on(event: "error", listener: (error: Error, stdout: string | null, stderr: string | null) => void): this;
/**
* Emitted when a taking screenshots
*
* @event FfmpegCommand#filenames
* @param filenames generated filenames when taking screenshots
*/
on(event: "filenames", listener: (filenames: string[]) => void): this;
/**
* Emitted when a command finishes processing
*
* @event FfmpegCommand#end
* @param stdout ffmpeg stdout when not outputting to a stream, null otherwise
* @param stderr ffmpeg stderr
*/
on(event: "end", listener: (stdout: string | null, stderr: string | null) => void): this;
// recipes
saveToFile(output: string): FfmpegCommand;
save(output: string): FfmpegCommand;
writeToStream(stream: stream.Writable, options?: { end?: boolean | undefined }): stream.Writable;
pipe(stream?: stream.Writable, options?: { end?: boolean | undefined }): stream.Writable | stream.PassThrough;
stream(stream: stream.Writable, options?: { end?: boolean | undefined }): stream.Writable;
takeScreenshots(config: number | ScreenshotsConfig, folder?: string): FfmpegCommand;
thumbnail(config: number | ScreenshotsConfig, folder?: string): FfmpegCommand;
thumbnails(config: number | ScreenshotsConfig, folder?: string): FfmpegCommand;
screenshot(config: number | ScreenshotsConfig, folder?: string): FfmpegCommand;
screenshots(config: number | ScreenshotsConfig, folder?: string): FfmpegCommand;
mergeToFile(target: string | stream.Writable, tmpFolder: string): FfmpegCommand;
concatenate(target: string | stream.Writable, options?: { end?: boolean | undefined }): FfmpegCommand;
concat(target: string | stream.Writable, options?: { end?: boolean | undefined }): FfmpegCommand;
clone(): FfmpegCommand;
run(): void;
}
function ffprobe(file: string, callback: (err: any, data: FfprobeData) => void): void;
function ffprobe(file: string, index: number, callback: (err: any, data: FfprobeData) => void): void;
function ffprobe(file: string, options: string[], callback: (err: any, data: FfprobeData) => void): void; // tslint:disable-line unified-signatures
function ffprobe(
file: string,
index: number,
options: string[],
callback: (err: any, data: FfprobeData) => void,
): void;
}
declare function Ffmpeg(options?: Ffmpeg.FfmpegCommandOptions): Ffmpeg.FfmpegCommand;
declare function Ffmpeg(input?: string | stream.Readable, options?: Ffmpeg.FfmpegCommandOptions): Ffmpeg.FfmpegCommand;
export = Ffmpeg;