-
Notifications
You must be signed in to change notification settings - Fork 3
/
cropdetect.js
112 lines (103 loc) · 3.05 KB
/
cropdetect.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
const addFilter = require('./utils').addFilter;
const registerFilter = require('./utils').registerFilter;
/**
* Augment FfmpegCommand with the cropdetect function.
*
*
* @example
* ffmpeg().cropdetect()
* ... // 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 cropdetect function.
*/
function cropdetect(ffmpegCommand) {
registerFilter(ffmpegCommand, 'cropdetect', function() {
return new CropdetectFilter(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 CropdetectFilter {
/**
* @param {FfmpegCommand} ffmpegCommand The fluent-ffmpeg constructor.
*/
constructor (ffmpeg) {
this.ffmpeg = ffmpeg;
CropdetectFilter.prototype.withLimit = this.limit;
CropdetectFilter.prototype.withRound = this.round;
CropdetectFilter.prototype.withReset_count = this.reset_count;
}
/**
* Set higher black value threshold, which can be optionally specified
* from nothing (0) to everything (255 for 8-bit based formats). An intensity
* value greater to the set value is considered non-black. It defaults to 24.
* You can also specify a value between 0.0 and 1.0 which will be scaled depending
* on the bitdepth of the pixel format.
*
*
* @param val
*/
limit(val) {
this._limit = val;
return this;
}
/**
* The value which the width/height should be divisible by. It defaults to
* 16. The offset is automatically adjusted to center the video. Use 2 to
* get only even dimensions (needed for 4:2:2 video). 16 is best when
* encoding to most video codecs.
*
*
* @param val
*/
round(val) {
this._round = val;
return this;
}
/**
* Set the counter that determines after how many frames cropdetect will
* reset the previously detected largest video area and start over to
* detect the current optimal crop area. Default value is 0.
*
* This can be useful when channel logos distort the video area. 0
* indicates ’never reset’, and returns the largest area encountered during
* playback.
*
* @param val
*/
reset_count(val) {
this._reset_count = val;
return this;
}
/**
* Creates this filter configuration and registers it in the ffmpeg instance.
* @return {ffmpegCommand} The ffmpeg instance.
*/
build() {
let opt = {};
if (this._limit) {
opt['limit'] = this._limit;
}
if (this._round) {
opt['round'] = this._round;
}
if (this._reset_count) {
opt['reset_count'] = this._reset_count;
}
addFilter(this.ffmpeg, {
filter: 'cropdetect',
options: opt
});
return this.ffmpeg;
}
}
module.exports.cropdetect = cropdetect;