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) scale = fmt.Sprintf("scale_vaapi=w=%d:h=%d:force_original_aspect_ratio=decrease", s.width, s.height)
} else if CV == "h264_nvenc" { } else if CV == "h264_nvenc" {
// NVENC // NVENC
format = "format=nv12|cuda,hwupload" scale = fmt.Sprintf("scale_cuda=w=%d:h=%d:force_original_aspect_ratio=decrease:passthrough=0", s.width, s.height)
if s.width >= s.height {
scale = fmt.Sprintf("scale_cuda=-2:%d", s.height)
} else {
scale = fmt.Sprintf("scale_cuda=%d:-2", s.width)
}
} else { } else {
// x264 // x264
format = "format=nv12" format = "format=nv12"
@ -333,15 +328,31 @@ func (s *Stream) transcode(startId int) {
// do not scale or set bitrate for full quality // do not scale or set bitrate for full quality
if s.quality == "max" { if s.quality == "max" {
args = append(args, []string{ if CV == "h264_nvenc" {
"-vf", format, // 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 { } else {
args = append(args, []string{ if CV == "h264_nvenc" {
"-vf", fmt.Sprintf("%s,%s", format, scale), args = append(args, []string{
"-maxrate", fmt.Sprintf("%d", s.bitrate), "-vf", scale,
"-bufsize", fmt.Sprintf("%d", s.bitrate*2), }...)
}...) } 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),
}...)
} }
// Output specs // Output specs
@ -356,6 +367,15 @@ func (s *Stream) transcode(startId int) {
"-low_power", "1", "-low_power", "1",
"-global_quality", "25", "-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" { } else if CV == "libx264" {
args = append(args, []string{ args = append(args, []string{
"-preset", "faster", "-preset", "faster",