mirror of
https://github.com/owncast/owncast.git
synced 2024-11-25 06:12:23 +03:00
Create explicit mapping between cpu use levels and codec presets. Closes #2610
This commit is contained in:
parent
748219d93e
commit
f4ed7d7453
1 changed files with 90 additions and 76 deletions
|
@ -31,8 +31,7 @@ var supportedCodecs = map[string]string{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Libx264Codec represents an instance of the Libx264 Codec.
|
// Libx264Codec represents an instance of the Libx264 Codec.
|
||||||
type Libx264Codec struct {
|
type Libx264Codec struct{}
|
||||||
}
|
|
||||||
|
|
||||||
// Name returns the codec name.
|
// Name returns the codec name.
|
||||||
func (c *Libx264Codec) Name() string {
|
func (c *Libx264Codec) Name() string {
|
||||||
|
@ -77,24 +76,26 @@ func (c *Libx264Codec) VariantFlags(v *HLSVariant) string {
|
||||||
|
|
||||||
// GetPresetForLevel returns the string preset for this codec given an integer level.
|
// GetPresetForLevel returns the string preset for this codec given an integer level.
|
||||||
func (c *Libx264Codec) GetPresetForLevel(l int) string {
|
func (c *Libx264Codec) GetPresetForLevel(l int) string {
|
||||||
presetMapping := []string{
|
presetMapping := map[int]string{
|
||||||
"ultrafast",
|
0: "ultrafast",
|
||||||
"superfast",
|
1: "superfast",
|
||||||
"veryfast",
|
2: "veryfast",
|
||||||
"faster",
|
3: "faster",
|
||||||
"fast",
|
4: "fast",
|
||||||
}
|
}
|
||||||
|
|
||||||
if l >= len(presetMapping) {
|
preset, ok := presetMapping[l]
|
||||||
return "superfast" //nolint:goconst
|
if !ok {
|
||||||
|
defaultPreset := presetMapping[1]
|
||||||
|
log.Errorf("Invalid level for x264 preset %d, defaulting to %s", l, defaultPreset)
|
||||||
|
return defaultPreset
|
||||||
}
|
}
|
||||||
|
|
||||||
return presetMapping[l]
|
return preset
|
||||||
}
|
}
|
||||||
|
|
||||||
// OmxCodec represents an instance of the Omx codec.
|
// OmxCodec represents an instance of the Omx codec.
|
||||||
type OmxCodec struct {
|
type OmxCodec struct{}
|
||||||
}
|
|
||||||
|
|
||||||
// Name returns the codec name.
|
// Name returns the codec name.
|
||||||
func (c *OmxCodec) Name() string {
|
func (c *OmxCodec) Name() string {
|
||||||
|
@ -135,24 +136,26 @@ func (c *OmxCodec) VariantFlags(v *HLSVariant) string {
|
||||||
|
|
||||||
// GetPresetForLevel returns the string preset for this codec given an integer level.
|
// GetPresetForLevel returns the string preset for this codec given an integer level.
|
||||||
func (c *OmxCodec) GetPresetForLevel(l int) string {
|
func (c *OmxCodec) GetPresetForLevel(l int) string {
|
||||||
presetMapping := []string{
|
presetMapping := map[int]string{
|
||||||
"ultrafast",
|
0: "ultrafast",
|
||||||
"superfast",
|
1: "superfast",
|
||||||
"veryfast",
|
2: "veryfast",
|
||||||
"faster",
|
3: "faster",
|
||||||
"fast",
|
4: "fast",
|
||||||
}
|
}
|
||||||
|
|
||||||
if l >= len(presetMapping) {
|
preset, ok := presetMapping[l]
|
||||||
return "superfast"
|
if !ok {
|
||||||
|
defaultPreset := presetMapping[1]
|
||||||
|
log.Errorf("Invalid level for omx preset %d, defaulting to %s", l, defaultPreset)
|
||||||
|
return defaultPreset
|
||||||
}
|
}
|
||||||
|
|
||||||
return presetMapping[l]
|
return preset
|
||||||
}
|
}
|
||||||
|
|
||||||
// VaapiCodec represents an instance of the Vaapi codec.
|
// VaapiCodec represents an instance of the Vaapi codec.
|
||||||
type VaapiCodec struct {
|
type VaapiCodec struct{}
|
||||||
}
|
|
||||||
|
|
||||||
// Name returns the codec name.
|
// Name returns the codec name.
|
||||||
func (c *VaapiCodec) Name() string {
|
func (c *VaapiCodec) Name() string {
|
||||||
|
@ -195,24 +198,26 @@ func (c *VaapiCodec) VariantFlags(v *HLSVariant) string {
|
||||||
|
|
||||||
// GetPresetForLevel returns the string preset for this codec given an integer level.
|
// GetPresetForLevel returns the string preset for this codec given an integer level.
|
||||||
func (c *VaapiCodec) GetPresetForLevel(l int) string {
|
func (c *VaapiCodec) GetPresetForLevel(l int) string {
|
||||||
presetMapping := []string{
|
presetMapping := map[int]string{
|
||||||
"ultrafast",
|
0: "ultrafast",
|
||||||
"superfast",
|
1: "superfast",
|
||||||
"veryfast",
|
2: "veryfast",
|
||||||
"faster",
|
3: "faster",
|
||||||
"fast",
|
4: "fast",
|
||||||
}
|
}
|
||||||
|
|
||||||
if l >= len(presetMapping) {
|
preset, ok := presetMapping[l]
|
||||||
return "superfast"
|
if !ok {
|
||||||
|
defaultPreset := presetMapping[1]
|
||||||
|
log.Errorf("Invalid level for vaapi preset %d, defaulting to %s", l, defaultPreset)
|
||||||
|
return defaultPreset
|
||||||
}
|
}
|
||||||
|
|
||||||
return presetMapping[l]
|
return preset
|
||||||
}
|
}
|
||||||
|
|
||||||
// NvencCodec represents an instance of the Nvenc Codec.
|
// NvencCodec represents an instance of the Nvenc Codec.
|
||||||
type NvencCodec struct {
|
type NvencCodec struct{}
|
||||||
}
|
|
||||||
|
|
||||||
// Name returns the codec name.
|
// Name returns the codec name.
|
||||||
func (c *NvencCodec) Name() string {
|
func (c *NvencCodec) Name() string {
|
||||||
|
@ -256,24 +261,26 @@ func (c *NvencCodec) VariantFlags(v *HLSVariant) string {
|
||||||
|
|
||||||
// GetPresetForLevel returns the string preset for this codec given an integer level.
|
// GetPresetForLevel returns the string preset for this codec given an integer level.
|
||||||
func (c *NvencCodec) GetPresetForLevel(l int) string {
|
func (c *NvencCodec) GetPresetForLevel(l int) string {
|
||||||
presetMapping := []string{
|
presetMapping := map[int]string{
|
||||||
"p1",
|
0: "p1",
|
||||||
"p2",
|
1: "p2",
|
||||||
"p3",
|
2: "p3",
|
||||||
"p4",
|
3: "p4",
|
||||||
"p5",
|
4: "p5",
|
||||||
}
|
}
|
||||||
|
|
||||||
if l >= len(presetMapping) {
|
preset, ok := presetMapping[l]
|
||||||
return "p3"
|
if !ok {
|
||||||
|
defaultPreset := presetMapping[2]
|
||||||
|
log.Errorf("Invalid level for nvenc preset %d, defaulting to %s", l, defaultPreset)
|
||||||
|
return defaultPreset
|
||||||
}
|
}
|
||||||
|
|
||||||
return presetMapping[l]
|
return preset
|
||||||
}
|
}
|
||||||
|
|
||||||
// QuicksyncCodec represents an instance of the Intel Quicksync Codec.
|
// QuicksyncCodec represents an instance of the Intel Quicksync Codec.
|
||||||
type QuicksyncCodec struct {
|
type QuicksyncCodec struct{}
|
||||||
}
|
|
||||||
|
|
||||||
// Name returns the codec name.
|
// Name returns the codec name.
|
||||||
func (c *QuicksyncCodec) Name() string {
|
func (c *QuicksyncCodec) Name() string {
|
||||||
|
@ -312,19 +319,22 @@ func (c *QuicksyncCodec) VariantFlags(v *HLSVariant) string {
|
||||||
|
|
||||||
// GetPresetForLevel returns the string preset for this codec given an integer level.
|
// GetPresetForLevel returns the string preset for this codec given an integer level.
|
||||||
func (c *QuicksyncCodec) GetPresetForLevel(l int) string {
|
func (c *QuicksyncCodec) GetPresetForLevel(l int) string {
|
||||||
presetMapping := []string{
|
presetMapping := map[int]string{
|
||||||
"ultrafast",
|
0: "ultrafast",
|
||||||
"superfast",
|
1: "superfast",
|
||||||
"veryfast",
|
2: "veryfast",
|
||||||
"faster",
|
3: "faster",
|
||||||
"fast",
|
4: "fast",
|
||||||
}
|
}
|
||||||
|
|
||||||
if l >= len(presetMapping) {
|
preset, ok := presetMapping[l]
|
||||||
return "superfast"
|
if !ok {
|
||||||
|
defaultPreset := presetMapping[1]
|
||||||
|
log.Errorf("Invalid level for quicksync preset %d, defaulting to %s", l, defaultPreset)
|
||||||
|
return defaultPreset
|
||||||
}
|
}
|
||||||
|
|
||||||
return presetMapping[l]
|
return preset
|
||||||
}
|
}
|
||||||
|
|
||||||
// Video4Linux represents an instance of the V4L Codec.
|
// Video4Linux represents an instance of the V4L Codec.
|
||||||
|
@ -367,24 +377,25 @@ func (c *Video4Linux) VariantFlags(v *HLSVariant) string {
|
||||||
|
|
||||||
// GetPresetForLevel returns the string preset for this codec given an integer level.
|
// GetPresetForLevel returns the string preset for this codec given an integer level.
|
||||||
func (c *Video4Linux) GetPresetForLevel(l int) string {
|
func (c *Video4Linux) GetPresetForLevel(l int) string {
|
||||||
presetMapping := []string{
|
presetMapping := map[int]string{
|
||||||
"ultrafast",
|
0: "ultrafast",
|
||||||
"superfast",
|
1: "superfast",
|
||||||
"veryfast",
|
2: "veryfast",
|
||||||
"faster",
|
3: "faster",
|
||||||
"fast",
|
4: "fast",
|
||||||
}
|
}
|
||||||
|
|
||||||
if l >= len(presetMapping) {
|
preset, ok := presetMapping[l]
|
||||||
return "superfast"
|
if !ok {
|
||||||
|
defaultPreset := presetMapping[1]
|
||||||
|
log.Errorf("Invalid level for v4l preset %d, defaulting to %s", l, defaultPreset)
|
||||||
|
return defaultPreset
|
||||||
}
|
}
|
||||||
|
return preset
|
||||||
return presetMapping[l]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// VideoToolboxCodec represents an instance of the VideoToolbox codec.
|
// VideoToolboxCodec represents an instance of the VideoToolbox codec.
|
||||||
type VideoToolboxCodec struct {
|
type VideoToolboxCodec struct{}
|
||||||
}
|
|
||||||
|
|
||||||
// Name returns the codec name.
|
// Name returns the codec name.
|
||||||
func (c *VideoToolboxCodec) Name() string {
|
func (c *VideoToolboxCodec) Name() string {
|
||||||
|
@ -435,19 +446,22 @@ func (c *VideoToolboxCodec) VariantFlags(v *HLSVariant) string {
|
||||||
|
|
||||||
// GetPresetForLevel returns the string preset for this codec given an integer level.
|
// GetPresetForLevel returns the string preset for this codec given an integer level.
|
||||||
func (c *VideoToolboxCodec) GetPresetForLevel(l int) string {
|
func (c *VideoToolboxCodec) GetPresetForLevel(l int) string {
|
||||||
presetMapping := []string{
|
presetMapping := map[int]string{
|
||||||
"ultrafast",
|
0: "ultrafast",
|
||||||
"superfast",
|
1: "superfast",
|
||||||
"veryfast",
|
2: "veryfast",
|
||||||
"faster",
|
3: "faster",
|
||||||
"fast",
|
4: "fast",
|
||||||
}
|
}
|
||||||
|
|
||||||
if l >= len(presetMapping) {
|
preset, ok := presetMapping[l]
|
||||||
return "superfast"
|
if !ok {
|
||||||
|
defaultPreset := presetMapping[1]
|
||||||
|
log.Errorf("Invalid level for videotoolbox preset %d, defaulting to %s", l, defaultPreset)
|
||||||
|
return defaultPreset
|
||||||
}
|
}
|
||||||
|
|
||||||
return presetMapping[l]
|
return preset
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCodecs will return the supported codecs available on the system.
|
// GetCodecs will return the supported codecs available on the system.
|
||||||
|
|
Loading…
Reference in a new issue