-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathastats.js
140 lines (131 loc) · 3.12 KB
/
astats.js
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
const addFilter = require('./utils').addFilter;
const registerFilter = require('./utils').registerFilter;
/**
* Augment FfmpegCommand with the astats function.
*
*
* @example
* ffmpeg().astats()
* ... // call filter configuration functions
* .build() // end filter configuration
* ...
* .applyFilters() // called once all filters have been configured
*
* @param {FfmpegCommand} ffmpegCommand The fluent-ffmpeg constructor.
* @return {FfmpegCommand} The ffmpegCommand augmented with the astats function.
*/
function astats(ffmpegCommand) {
registerFilter(ffmpegCommand, 'astats', function() {
return new AstatsFilter(this);
});
return ffmpegCommand;
}
/**
* Class exposing methods to configure the vstack filter in a builder pattern way.
*
* See {@link http://ffmpeg.org/ffmpeg-filters.html#vstack} for a description
* of each configuration option.
*/
class AstatsFilter {
/**
* @param {FfmpegCommand} ffmpegCommand The fluent-ffmpeg constructor.
*/
constructor (ffmpeg) {
this.ffmpeg = ffmpeg;
AstatsFilter.prototype.withLength = this.length;
AstatsFilter.prototype.withMetadata = this.metadata;
AstatsFilter.prototype.withReset = this.reset;
}
/**
* Short window length in seconds, used for peak and trough RMS measurement.
* Default is 0.05 (50 milliseconds). Allowed range is [0.1 - 10].
*
*
* @param val
*/
length(val) {
this._length = val;
return this;
}
/**
*
* Set metadata injection. All the metadata keys are prefixed with lavfi.astats.X,
* where X is channel number starting from 1 or string Overall. Default is
* disabled.
*
* Available keys for each channel are:
* DC_offset
* Min_level
* Max_level
* Min_difference
* Max_difference
* Mean_difference
* Peak_level
* RMS_peak
* RMS_trough
* Crest_factor
* Flat_factor
* Peak_count
* Bit_depth
*
* and for Overall:
* DC_offset
* Min_level
* Max_level
* Min_difference
* Max_difference
* Mean_difference
* Peak_level
* RMS_level
* RMS_peak
* RMS_trough
* Flat_factor
* Peak_count
* Bit_depth
* Number_of_samples
*
* For example full key look like this lavfi.astats.1.DC_offset or
* this lavfi.astats.Overall.Peak_count.
*
* For description what each key means read below.
*
*
* @param val
*/
metadata(val) {
this._metadata = val;
return this;
}
/**
* Set number of frame after which stats are going to be recalculated.
* Default is disabled.
*
* @param val
*/
reset(val) {
this._reset = val;
return this;
}
/**
* Creates this filter configuration and registers it in the ffmpeg instance.
* @return {ffmpegCommand} The ffmpeg instance.
*/
build() {
let opt = {};
if (this._length) {
opt['length'] = this._length;
}
if (this._metadata) {
opt['metadata'] = this._metadata;
}
if (this._reset) {
opt['reset'] = this._reset;
}
addFilter(this.ffmpeg, {
filter: 'astats',
options: opt
});
return this.ffmpeg;
}
}
module.exports.astats = astats;