encode-server properly uses build flags
This commit is contained in:
parent
6ea3e971bb
commit
6c20429b0d
|
@ -251,7 +251,7 @@ func main() {
|
|||
|
||||
stream := frameServerPool.GetFrames(startFrameNumber, endFrameNumber)
|
||||
|
||||
if encoder, err := libaom.NewEncoder(f, stream.Properties(), settings); err != nil {
|
||||
if encoder, err := libaom.NewEncoder(f, stream.Properties(), settings, log.Default()); err != nil {
|
||||
log.Panicf("could not create encoder for %s: %s", outputPath, err.Error())
|
||||
} else {
|
||||
defer encoder.Close()
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
//go:build cgo && !disable_library_libaom && !disable_library_libx264
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
|
21
cli/encode-server/encoder_libaom.go
Normal file
21
cli/encode-server/encoder_libaom.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
//go:build cgo && !disable_library_libaom
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/encoder"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/encoder/libaom"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/frame"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/utilities"
|
||||
"io"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Encoders = append(Encoders, EncoderEntry{
|
||||
Name: EncoderAOM,
|
||||
Version: libaom.Version,
|
||||
New: func(w io.Writer, properties frame.StreamProperties, settings map[string]any, logger utilities.Logger) (encoder.Encoder, error) {
|
||||
return libaom.NewEncoder(w, properties, settings, logger)
|
||||
},
|
||||
})
|
||||
}
|
21
cli/encode-server/encoder_libx264.go
Normal file
21
cli/encode-server/encoder_libx264.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
//go:build cgo && !disable_library_libx264
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/encoder"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/encoder/libx264"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/frame"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/utilities"
|
||||
"io"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Encoders = append(Encoders, EncoderEntry{
|
||||
Name: EncoderX264,
|
||||
Version: libx264.Version,
|
||||
New: func(w io.Writer, properties frame.StreamProperties, settings map[string]any, logger utilities.Logger) (encoder.Encoder, error) {
|
||||
return libx264.NewEncoder(w, properties, settings, logger)
|
||||
},
|
||||
})
|
||||
}
|
21
cli/encode-server/encoders.go
Normal file
21
cli/encode-server/encoders.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/encoder"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/frame"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/utilities"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
EncoderX264 = "libx264"
|
||||
EncoderAOM = "libaom"
|
||||
)
|
||||
|
||||
type EncoderEntry struct {
|
||||
Name string
|
||||
Version func() string
|
||||
New func(w io.Writer, properties frame.StreamProperties, settings map[string]any, logger utilities.Logger) (encoder.Encoder, error)
|
||||
}
|
||||
|
||||
var Encoders []EncoderEntry
|
|
@ -1,5 +1,3 @@
|
|||
//go:build cgo && !disable_library_libaom && !disable_library_libx264
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -8,8 +6,6 @@ import (
|
|||
"errors"
|
||||
encode_utils "git.gammaspectra.live/S.O.N.G/Ignite/cli/encode-utils"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/encoder"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/encoder/libaom"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/encoder/libx264"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/utilities"
|
||||
"io"
|
||||
"maps"
|
||||
|
@ -45,20 +41,18 @@ func (j *Job) Init(w io.Writer) error {
|
|||
// Do not modify original settings
|
||||
settings := maps.Clone(j.Config.Encoder.Settings)
|
||||
|
||||
switch j.Config.Encoder.Name {
|
||||
case encode_utils.EncoderX264:
|
||||
x264enc, err := libx264.NewEncoder(w, j.Config.Properties, settings, j.Logger)
|
||||
if err != nil {
|
||||
return err
|
||||
var err error
|
||||
|
||||
for _, e := range Encoders {
|
||||
if e.Name == j.Config.Encoder.Name {
|
||||
j.Encoder, err = e.New(w, j.Config.Properties, settings, j.Logger)
|
||||
}
|
||||
j.Encoder = x264enc
|
||||
case encode_utils.EncoderAOM:
|
||||
aomenc, err := libaom.NewEncoder(w, j.Config.Properties, settings)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
j.Encoder = aomenc
|
||||
default:
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if j.Encoder == nil {
|
||||
return errors.New("encoder not supported")
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
//go:build cgo && !disable_library_libaom && !disable_library_libx264
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
encode_utils "git.gammaspectra.live/S.O.N.G/Ignite/cli/encode-utils"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/encoder/libaom"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/encoder/libx264"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/utilities"
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
"github.com/shirou/gopsutil/host"
|
||||
|
@ -52,14 +48,12 @@ func main() {
|
|||
|
||||
var statusData encode_utils.StatusData
|
||||
|
||||
statusData.Encoders = append(statusData.Encoders, encode_utils.StatusEncoderData{
|
||||
Name: encode_utils.EncoderX264,
|
||||
Version: libx264.Version(),
|
||||
})
|
||||
statusData.Encoders = append(statusData.Encoders, encode_utils.StatusEncoderData{
|
||||
Name: encode_utils.EncoderAOM,
|
||||
Version: libaom.Version(),
|
||||
})
|
||||
for _, e := range Encoders {
|
||||
statusData.Encoders = append(statusData.Encoders, encode_utils.StatusEncoderData{
|
||||
Name: e.Name,
|
||||
Version: e.Version(),
|
||||
})
|
||||
}
|
||||
|
||||
cpuInfo, err := cpu.Info()
|
||||
if err != nil {
|
||||
|
|
|
@ -16,8 +16,3 @@ type JobConfig struct {
|
|||
TimecodesV1 string `json:"timecodes_v1" yaml:"timecodes_v1"`
|
||||
Timecodes utilities.Timecodes `json:"timecodes" yaml:"timecodes"`
|
||||
}
|
||||
|
||||
const (
|
||||
EncoderX264 = "libx264"
|
||||
EncoderAOM = "libaom"
|
||||
)
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"fmt"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/color"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/frame"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/utilities"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/utilities/obuwriter"
|
||||
"golang.org/x/exp/constraints"
|
||||
"io"
|
||||
|
@ -19,6 +20,7 @@ import (
|
|||
"maps"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"unsafe"
|
||||
)
|
||||
|
@ -33,6 +35,7 @@ type Encoder struct {
|
|||
framesIn, framesOut int
|
||||
frameStatistics frame.FrameStatistics
|
||||
resourcePinner runtime.Pinner
|
||||
logger utilities.Logger
|
||||
}
|
||||
|
||||
var libaomVersion = "libaom-av1 " + C.GoString(C.aom_codec_version_str()) + " ABI " + strconv.FormatUint(C.AOM_ENCODER_ABI_VERSION, 10)
|
||||
|
@ -47,9 +50,10 @@ const (
|
|||
UsageAllIntra = C.AOM_USAGE_ALL_INTRA
|
||||
)
|
||||
|
||||
func NewEncoder(w io.Writer, properties frame.StreamProperties, settings map[string]any) (*Encoder, error) {
|
||||
func NewEncoder(w io.Writer, properties frame.StreamProperties, settings map[string]any, logger utilities.Logger) (*Encoder, error) {
|
||||
e := &Encoder{
|
||||
frameStatistics: make(frame.FrameStatistics),
|
||||
logger: logger,
|
||||
}
|
||||
|
||||
clonedSettings := maps.Clone(settings)
|
||||
|
@ -475,6 +479,7 @@ func (e *Encoder) encodeFrame(pts, nextPts int64, raw *C.aom_image_t) (pkts int,
|
|||
|
||||
var quant64 C.int
|
||||
if e.framesIn >= int(e.cfg.g_lag_in_frames) {
|
||||
//TODO: maybe call this on new packets?
|
||||
if aomErr = C.aom_codec_control_intptr(&e.codec, C.AOME_GET_LAST_QUANTIZER_64, &quant64); aomErr != C.AOM_CODEC_OK {
|
||||
return 0, errors.New("error getting LAST_QUANTIZER_64")
|
||||
}
|
||||
|
@ -505,12 +510,31 @@ func (e *Encoder) encodeFrame(pts, nextPts int64, raw *C.aom_image_t) (pkts int,
|
|||
e.frameStatistics[frame.FrameStatisticsKeyIsKeyFrame] = false
|
||||
e.frameStatistics[frame.FrameStatisticsKeyIsIntraFrame] = false
|
||||
|
||||
var flagStr []string
|
||||
if flags&C.AOM_FRAME_IS_KEY > 0 {
|
||||
e.frameStatistics[frame.FrameStatisticsKeyIsKeyFrame] = true
|
||||
flagStr = append(flagStr, "K-Frame")
|
||||
}
|
||||
if flags&C.AOM_FRAME_IS_DROPPABLE > 0 {
|
||||
flagStr = append(flagStr, "droppable")
|
||||
}
|
||||
if flags&C.AOM_FRAME_IS_INTRAONLY > 0 {
|
||||
e.frameStatistics[frame.FrameStatisticsKeyIsIntraFrame] = true
|
||||
flagStr = append(flagStr, "I-Frame")
|
||||
}
|
||||
if flags&C.AOM_FRAME_IS_SWITCH > 0 {
|
||||
flagStr = append(flagStr, "S-Frame")
|
||||
}
|
||||
if flags&C.AOM_FRAME_IS_ERROR_RESILIENT > 0 {
|
||||
flagStr = append(flagStr, "resilient")
|
||||
}
|
||||
if flags&C.AOM_FRAME_IS_DELAYED_RANDOM_ACCESS_POINT > 0 {
|
||||
//Forward keyframe
|
||||
e.frameStatistics[frame.FrameStatisticsKeyIsKeyFrame] = true
|
||||
flagStr = append(flagStr, "delayedrandom")
|
||||
}
|
||||
|
||||
e.logger.Printf("libaom: partition = %d, n = %d, pts = %d, quant64 = %d, bytes = %d, flags = %s", partitionId, e.framesOut, packetPts, quant64, len(buf), strings.Join(flagStr, ", "))
|
||||
if err = e.w.WriteFrameBytes(packetPts, buf); err != nil {
|
||||
return pkts, err
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ package libaom
|
|||
import (
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/decoder/y4m"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/testdata"
|
||||
"git.gammaspectra.live/S.O.N.G/Ignite/utilities/testingutils"
|
||||
"os"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
@ -62,7 +63,7 @@ func testEncode(sample testdata.TestSample, t *testing.T) {
|
|||
settings["tile-columns"] = 1
|
||||
settings["tile-rows"] = 4
|
||||
|
||||
if encoder, err := NewEncoder(target, stream.Properties(), settings); err != nil {
|
||||
if encoder, err := NewEncoder(target, stream.Properties(), settings, testingutils.TestLogger(t)); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
defer encoder.Close()
|
||||
|
|
Loading…
Reference in a new issue