Made the service basically start working
This commit is contained in:
38
Encoder/Utils.cs
Normal file
38
Encoder/Utils.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
namespace Encoder;
|
||||
|
||||
public static class Utils {
|
||||
static Tuple<int, int>[] QPTable = new Tuple<int, int>[] {
|
||||
new(1280*720, 64),
|
||||
new(1920*1080, 96),
|
||||
new(3840*2160, 128),
|
||||
new(5760*2880, 96), //VR6K
|
||||
new(8128*4096, 120) //VR8K
|
||||
}.OrderBy(t => t.Item1).ToArray();
|
||||
|
||||
static float lerp(float v0, float v1, float t) {
|
||||
return v0 + t * (v1 - v0);
|
||||
}
|
||||
|
||||
static float remap(float value, float from1, float to1, float from2, float to2) {
|
||||
return from2 + (value - from1) * (to2 - from2) / (to1 - from1);
|
||||
}
|
||||
|
||||
public static int ToQPValue(int W, int H) {
|
||||
int pixels = W * H;
|
||||
for (var i = 0; i < QPTable.Length; i++) {
|
||||
var t = QPTable[i];
|
||||
if (pixels <= t.Item1) {
|
||||
var minQP = QPTable[i - 1].Item2;
|
||||
var maxQP = QPTable[i].Item2;
|
||||
|
||||
var minPixels = QPTable[i - 1].Item1;
|
||||
var maxPixels = QPTable[i].Item1;
|
||||
var tPixels = remap(pixels, minPixels, maxPixels, 0, 1);
|
||||
|
||||
return (int)lerp(minQP, maxQP, tPixels);
|
||||
}
|
||||
}
|
||||
// Return the highest QP for anything higher than 8K VR
|
||||
return QPTable.Last().Item2;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user