-
Notifications
You must be signed in to change notification settings - Fork 0
/
enc_hevc_nvenc.py
80 lines (66 loc) · 1.98 KB
/
enc_hevc_nvenc.py
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
"""
Nvidia rigaya/NVEnc
https://github.com/rigaya/NVEnc/blob/master/NVEncC_Options.en.md
lut: --vpp-colorspace lut3d=<path> lut3d_interp=<string>
output-csp yuv420(default), yuv444
RTX 3060
RC Modes CQP, CBR, CBRHQ, VBR, VBRHQ
Max Bframes 5
Max Level 186 (6.2)
4:4:4 yes
10bit depth yes
NVDec features
H.264/AVC: nv12, yv12
H.265/HEVC: nv12, yv12, yv12(10bit), yv12(12bit), yuv444, yuv444(10bit), yuv444(12bit)
"""
from lib import BaseEncoder
OUTPUT_BUFFER = 64
FORMATS_OUT = {
'yuv420:8': 'yuv420',
'yuv422:8': 'yuv444',
'yuv420:10': 'yuv444',
'yuv422:10': 'yuv444',
}
PROFILES = {
'yuv420:8': 'main',
'yuv422:8': 'main444',
'yuv420:10': 'main10',
'yuv422:10': 'main444',
}
COLORS = {
'BT.709': 'bt709'
# smpte2084 bt2020nc bt2020c
}
class Encoder(BaseEncoder):
CMD = ['nvencc']
can_scale = True
def __init__(self, vid):
#print(f'nvenc idx: {vid.idx()}')
self.params = {
'c': 'hevc',
'u': 'quality',
'-cqp': vid.crf,
'-profile': PROFILES[vid.idx()],
'-tier': 'high',
'-output-csp': FORMATS_OUT[vid.idx()],
'-output-depth': vid.bits,
'-output-buf': OUTPUT_BUFFER,
'-mv-precision': 'Q-pel',
}
if vid.gop:
self.params['-gop-len'] = vid.gop
#if vid.all_i:
# self.params['-gop-len'] = 1
if vid.color_primaries:
self.params['-colorprim'] = COLORS[vid.color_primaries]
if vid.transfer_characteristics:
self.params['-transfer'] = COLORS[vid.transfer_characteristics]
if vid.matrix_coefficients:
self.params['-colormatrix'] = COLORS[vid.matrix_coefficients]
self.res = vid.res
def get_params(self):
return self.params
def get_filter(self, *args, scale=None, **kwargs):
if not scale:
return {}
return ['--output-res', f'-2x{self.res}', '--vpp-resize', 'lanczos3']