Merge pull request #3 from MB-Finski/patch-1

Add support for NVIDIA GPU accelerated transcoding
monorepo
Varun Patil 2022-11-29 13:52:08 -08:00 committed by GitHub
commit 64767d7a78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 9 deletions

View File

@ -357,11 +357,15 @@ func (s *Stream) transcodeArgs(startAt float64) []string {
// encoder selection
CV := "libx264"
// no need to transcode h264 streams for max quality
// Check whether hwaccel should be used
if os.Getenv("VAAPI") == "1" {
CV = "h264_vaapi"
extra := "-hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi"
args = append(args, strings.Split(extra, " ")...)
} else if os.Getenv("NVENC") == "1" {
CV = "h264_nvenc"
extra := "-hwaccel cuda -hwaccel_output_format cuda"
args = append(args, strings.Split(extra, " ")...)
}
// Input specs
@ -378,6 +382,10 @@ func (s *Stream) transcodeArgs(startAt float64) []string {
// VAAPI
format = "format=nv12|vaapi,hwupload"
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"
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"
@ -390,9 +398,16 @@ func (s *Stream) transcodeArgs(startAt float64) []string {
// 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", fmt.Sprintf("%s,%s", format, "scale_cuda=passthrough=0"),
}...)
} else {
args = append(args, []string{
"-vf", format,
}...)
}
} else {
args = append(args, []string{
"-vf", fmt.Sprintf("%s,%s", format, scale),
@ -413,6 +428,15 @@ func (s *Stream) transcodeArgs(startAt float64) []string {
"-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",