Add vaapi hardware acceleration

This commit is contained in:
Zoe Roux
2024-02-25 00:57:01 +01:00
parent 9a5142ced3
commit c1cdcddf41
7 changed files with 81 additions and 6 deletions
+18 -1
View File
@@ -31,7 +31,6 @@ func DetectHardwareAccel() HwAccelT {
return HwAccelT{
Name: "nvidia",
DecodeFlags: []string{
// TODO: check if this can always be enabled (for example with weird video formats)
"-hwaccel", "cuda",
// this flag prevents data to go from gpu space to cpu space
// it forces the whole dec/enc to be on the gpu. We want that.
@@ -47,6 +46,24 @@ func DetectHardwareAccel() HwAccelT {
// since we use hwaccel_output_format, decoded data stays in gpu memory so we must not specify it (it errors)
ScaleFilter: "scale_cuda=%d:%d",
}
case "vaapi":
return HwAccelT{
Name: name,
DecodeFlags: []string{
"-hwaccel", "vaapi",
"-hwaccel_device", GetEnvOr("GOTRANSCODER_VAAPI_RENDERER", "/dev/dri/renderD128"),
"-hwaccel_output_format", "vaapi",
},
EncodeFlags: []string{
// h264_vaapi does not have any preset or scenecut flags.
"-c:v", "h264_vaapi",
// if the hardware decoder could not work and fallbacked to soft decode, we need to instruct ffmpeg to
// upload back frames to gpu space (after converting them)
// see https://trac.ffmpeg.org/wiki/Hardware/VAAPI#Encoding for more info
// "-vf", "format=nv12|vaapi,hwupload",
},
ScaleFilter: "scale_vaapi=%d:%d",
}
default:
log.Printf("No hardware accelerator named: %s", name)
os.Exit(2)