This repository was archived by the owner on Apr 24, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencoder_h264_nvenc.js
More file actions
147 lines (134 loc) · 3.58 KB
/
encoder_h264_nvenc.js
File metadata and controls
147 lines (134 loc) · 3.58 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
const encoder = require('./encoder.js');
const path = require('path');
const fs = require('fs');
const crypto = require('crypto');
let version = 1;
class h264_nvenc extends encoder {
constructor(ffmpeg, config, settings) {
super(ffmpeg, config, settings);
}
available() {
if (global.debug) console.time("Checking...");
let res = ff.ffmpegSync([
"-hide_banner", "-v", "quiet",
"-f", "lavfi",
"-i", "color=size=256x256:duration=1:rate=30:color=black",
"-c:v", "h264_nvenc",
"-f", "null",
"-"
]);
if (global.debug) console.timeEnd("Checking...");
if (res.status != 0) {
return false;
}
return true;
}
available() {
if (global.debug) console.time("Checking...");
let res = this.ffmpeg.ffmpegSync([
"-hide_banner", "-v", "error",
"-f", "lavfi",
"-i", "color=size=256x256:duration=1:rate=30:color=black",
"-c:v", "h264_nvenc",
"-f", "null",
"-"
]);
if (global.debug) console.timeEnd("Checking...");
if (res.status != 0) {
return false;
}
return true;
}
load() {
let name = function(opts) {
let name = "";
for (let idx = 0; idx < opts.length; idx += 2) {
let opt = opts[idx];
let val = opts[idx + 1];
if (name.length != 0)
name += ";";
name += `${opt.substr(1)}=${val}`;
}
return `${name};version=${version}`;
}
if (global.debug) console.time("Generating...");
this.indexes = {};
this.combinations = [];
for (let preset of this.settings.presets) {
for (let tune of this.settings.tunes) {
for (let rcla of this.settings["rc-lookahead"]) {
for (let scenecut of this.settings.scenecut) {
if ((rcla == 0) && (scenecut == true)) { // Requires lookahead.
continue;
}
for (let bf of this.settings.bframes) {
for (let bfm of this.settings.bframe_reference_mode) {
if ((bf == 0) && (bfm != "disabled")) { // Requires B-Frames
continue;
}
for (let mp of [0, 1, 2]) {
for (let taq of [0, 1]) {
for (let saqs of [0, 7, 15]) {
let _opts = [
"-profile:v", "high",
"-preset", preset,
"-tune", tune,
"-rc", "cbr",
"-cbr", 1,
"-rc-lookahead", rcla,
"-no-scenecut", scenecut == true ? 0 : 1,
"-bf", bf,
"-b_ref_mode", bfm,
"-b_adapt", 1,
"-multipass", mp,
"-temporal_aq", taq,
];
if (saqs == 0) {
_opts.push(
"-spatial-aq", 0,
);
} else {
_opts.push(
"-spatial-aq", 1,
"-aq-strength", saqs,
);
}
let _name = name(_opts);
let _hash = crypto.createHash("sha256").update(_name).digest("hex");
let _cost = (1.0 / this.settings.parallel) * 1.01;
let combo = {
name: _name,
hash: _hash,
options: _opts,
cost: _cost,
};
this.indexes[_hash] = combo.options;
this.combinations.push(combo);
}
}
}
}
}
}
}
}
}
fs.writeFileSync(
path.join(this.config.paths.output, "h264_nvenc.json"),
JSON.stringify(this.indexes, null, '\t'),
{encoding: "utf8"}
);
if (global.debug) console.timeEnd("Generating...");
if (global.debug) console.log(`Combinations: ${this.combinations.length}`)
}
pool() {
return this.settings.pool;
}
get(index, width, height, framerate) {
return this.combinations[index];
}
extra() {
return ["-gpu", this.settings.gpu];
}
}
module.exports = h264_nvenc;