2024-03-07 22:18:35 +05:00
|
|
|
package h264_nvenc
|
|
|
|
|
|
|
|
import (
|
2024-04-28 14:43:18 +05:00
|
|
|
"errors"
|
2024-03-07 22:18:35 +05:00
|
|
|
encoder2 "git.kor-elf.net/kor-elf/gui-for-ffmpeg/encoder"
|
|
|
|
)
|
|
|
|
|
2024-04-28 14:43:18 +05:00
|
|
|
var Presets = []string{
|
|
|
|
"default",
|
|
|
|
"slow",
|
|
|
|
"medium",
|
|
|
|
"fast",
|
|
|
|
"hp",
|
|
|
|
"hq",
|
|
|
|
"bd",
|
|
|
|
"ll",
|
|
|
|
"llhq",
|
|
|
|
"llhp",
|
|
|
|
"lossless",
|
|
|
|
"losslesshp",
|
|
|
|
}
|
|
|
|
|
2024-03-07 22:18:35 +05:00
|
|
|
func NewEncoder() encoder2.EncoderContract {
|
2024-04-28 14:43:18 +05:00
|
|
|
parameters := map[string]encoder2.ParameterContract{
|
|
|
|
"preset": newParameterPreset(),
|
|
|
|
}
|
2024-03-17 20:28:35 +05:00
|
|
|
getParams := func(parameters map[string]encoder2.ParameterContract) []string {
|
2024-04-28 14:43:18 +05:00
|
|
|
params := []string{"-c:v", "h264_nvenc"}
|
|
|
|
|
|
|
|
if parameters["preset"] != nil && parameters["preset"].IsEnabled() {
|
|
|
|
params = append(params, "-preset", parameters["preset"].Get())
|
|
|
|
}
|
|
|
|
|
|
|
|
return params
|
2024-03-17 20:28:35 +05:00
|
|
|
}
|
2024-03-07 22:18:35 +05:00
|
|
|
|
2024-03-17 20:28:35 +05:00
|
|
|
return encoder2.NewEncoder("h264_nvenc", parameters, getParams)
|
2024-03-07 22:18:35 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewData() encoder2.EncoderDataContract {
|
|
|
|
title := "h264_nvenc"
|
|
|
|
formats := []string{"mp4"}
|
|
|
|
fileType := encoder2.FileType(encoder2.Video)
|
|
|
|
return encoder2.NewData(title, formats, fileType, NewEncoder)
|
|
|
|
}
|
2024-04-28 14:43:18 +05:00
|
|
|
|
|
|
|
func newParameterPreset() encoder2.ParameterContract {
|
|
|
|
setParameter := func(s string) (string, error) {
|
|
|
|
for _, value := range Presets {
|
|
|
|
if value == s {
|
|
|
|
return value, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "", errors.New("preset not found")
|
|
|
|
}
|
|
|
|
return encoder2.NewParameter("preset", false, "default", setParameter)
|
|
|
|
}
|