Optimizations for NVENC transcode profile

Permormance and quality related optimizations for NVENC. Also contains a bugfix where transcoding with "max"-profile would fail due to a bug in the NVENC itself.
monorepo
MB-Finski 2022-11-29 20:33:26 +02:00 committed by GitHub
parent 9972fc23c6
commit 0dd14fabe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 14 deletions

View File

@ -315,12 +315,7 @@ func (s *Stream) transcode(startId int) {
scale = fmt.Sprintf("scale_vaapi=w=%d:h=%d:force_original_aspect_ratio=decrease", s.width, s.height)
} else if CV == "h264_nvenc" {
// NVENC
format = "format=nv12|cuda,hwupload"
if s.width >= s.height {
scale = fmt.Sprintf("scale_cuda=-2:%d", s.height)
} else {
scale = fmt.Sprintf("scale_cuda=%d:-2", s.width)
}
scale = fmt.Sprintf("scale_cuda=w=%d:h=%d:force_original_aspect_ratio=decrease:passthrough=0", s.width, s.height)
} else {
// x264
format = "format=nv12"
@ -333,12 +328,28 @@ func (s *Stream) transcode(startId int) {
// do not scale or set bitrate for full quality
if s.quality == "max" {
if CV == "h264_nvenc" {
// Due to a bug(?) in NVENC, passthrough=0 must be set
args = append(args, []string{
"-vf", "scale_cuda=passthrough=0",
}...)
} else {
args = append(args, []string{
"-vf", format,
}...)
}
} else {
if CV == "h264_nvenc" {
args = append(args, []string{
"-vf", scale,
}...)
} else {
args = append(args, []string{
"-vf", fmt.Sprintf("%s,%s", format, scale),
}...)
}
// Common arguments
args = append(args, []string{
"-maxrate", fmt.Sprintf("%d", s.bitrate),
"-bufsize", fmt.Sprintf("%d", s.bitrate*2),
}...)
@ -356,6 +367,15 @@ func (s *Stream) transcode(startId int) {
"-low_power", "1",
"-global_quality", "25",
}...)
} else if CV == "h264_nvenc" {
args = append(args, []string{
"-preset", "p6",
"-tune", "ll",
"-temporal-aq", "1",
"-rc", "vbr",
"-rc-lookahead","30",
"-cq", "24",
}...)
} else if CV == "libx264" {
args = append(args, []string{
"-preset", "faster",