-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStreamConfigurator.cs
64 lines (52 loc) · 1.59 KB
/
StreamConfigurator.cs
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
using Xabe.FFmpeg;
namespace dis.Features.Conversion;
public sealed class StreamConfigurator
{
private readonly string[] _av1Args =
[
"-lag-in-frames 48",
"-row-mt 1",
"-tile-rows 0",
"-tile-columns 1"
];
private readonly string[] _vp9Args =
[
"-row-mt 1",
"-lag-in-frames 25",
"-cpu-used 4",
"-auto-alt-ref 1",
"-arnr-maxframes 7",
"-arnr-strength 4",
"-aq-mode 0",
"-enable-tpl 1",
"-row-mt 1"
];
public void SetResolution(IVideoStream stream, string res)
{
double width = stream.Width;
double height = stream.Height;
var resInt = int.Parse(res[..^1]); // 1080p -> 1080
var aspectRatio = width / height;
var outputWidth = (int)Math.Round(resInt * aspectRatio);
var outputHeight = resInt;
outputWidth -= outputWidth % 2;
outputHeight -= outputHeight % 2;
stream.SetSize(outputWidth, outputHeight);
}
public void SetCpuForAv1(IConversion conversion, double framerate)
{
const string twoCores = "-cpu-used 2";
const string fourCore = "-cpu-used 4";
const string sixCore = "-cpu-used 6";
var cpuUsedParameter = framerate switch
{
< 24 => twoCores,
> 60 => sixCore,
_ => fourCore
};
conversion.AddParameter(string.Join(" ", _av1Args));
conversion.AddParameter(cpuUsedParameter);
}
public void SetVp9Args(IConversion conversion)
=> conversion.AddParameter(string.Join(" ", _vp9Args));
}