2024-03-07 22:18:35 +05:00
|
|
|
package libx264
|
|
|
|
|
2024-03-17 20:28:35 +05:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
encoder2 "git.kor-elf.net/kor-elf/gui-for-ffmpeg/encoder"
|
|
|
|
)
|
2024-03-07 22:18:35 +05:00
|
|
|
|
2024-03-17 20:28:35 +05:00
|
|
|
var Presets = []string{
|
|
|
|
"ultrafast",
|
|
|
|
"superfast",
|
|
|
|
"veryfast",
|
|
|
|
"faster",
|
|
|
|
"fast",
|
|
|
|
"medium",
|
|
|
|
"slow",
|
|
|
|
"slower",
|
|
|
|
"veryslow",
|
|
|
|
"placebo",
|
2024-03-07 22:18:35 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewEncoder() encoder2.EncoderContract {
|
2024-03-17 20:28:35 +05:00
|
|
|
parameters := map[string]encoder2.ParameterContract{
|
|
|
|
"preset": newParameterPreset(),
|
|
|
|
}
|
|
|
|
getParams := func(parameters map[string]encoder2.ParameterContract) []string {
|
|
|
|
params := []string{"-c:v", "libx264"}
|
|
|
|
|
|
|
|
if parameters["preset"] != nil && parameters["preset"].IsEnabled() {
|
|
|
|
params = append(params, "-preset", parameters["preset"].Get())
|
|
|
|
}
|
|
|
|
|
|
|
|
return params
|
|
|
|
}
|
2024-03-07 22:18:35 +05:00
|
|
|
|
2024-03-17 20:28:35 +05:00
|
|
|
return encoder2.NewEncoder("libx264", parameters, getParams)
|
2024-03-07 22:18:35 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewData() encoder2.EncoderDataContract {
|
|
|
|
title := "libx264"
|
|
|
|
formats := []string{"mp4"}
|
|
|
|
fileType := encoder2.FileType(encoder2.Video)
|
|
|
|
return encoder2.NewData(title, formats, fileType, NewEncoder)
|
|
|
|
}
|
2024-03-17 20:28:35 +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, "medium", setParameter)
|
|
|
|
}
|