Add initial implementations for encoder handling and conversion logic
Introduce encoder modules for various codecs and formats (e.g., h264_nvenc, libx264, libmp3lame). Add `Convertor` logic to retrieve supported formats via FFmpeg utilities and manage encoders for audio, video, and image processing.
This commit is contained in:
169
internal/ffmpeg/encoder/encoder.go
Normal file
169
internal/ffmpeg/encoder/encoder.go
Normal file
@@ -0,0 +1,169 @@
|
||||
package encoder
|
||||
|
||||
import "errors"
|
||||
|
||||
type EncoderContract interface {
|
||||
GetName() string
|
||||
GetParams() []string
|
||||
GetParameter(name string) (ParameterContract, error)
|
||||
}
|
||||
|
||||
type ParameterContract interface {
|
||||
GetName() string
|
||||
Set(string) error
|
||||
Get() string
|
||||
IsEnabled() bool
|
||||
SetEnable()
|
||||
SetDisable()
|
||||
}
|
||||
|
||||
type EncoderDataContract interface {
|
||||
GetTitle() string
|
||||
GetFormats() []string
|
||||
GetFileType() FileTypeContract
|
||||
NewEncoder() EncoderContract
|
||||
}
|
||||
|
||||
type data struct {
|
||||
title string
|
||||
formats []string
|
||||
fileType FileTypeContract
|
||||
encoder func() EncoderContract
|
||||
}
|
||||
|
||||
func NewData(title string, formats []string, fileType FileTypeContract, encoder func() EncoderContract) EncoderDataContract {
|
||||
return &data{
|
||||
title: title,
|
||||
formats: formats,
|
||||
fileType: fileType,
|
||||
encoder: encoder,
|
||||
}
|
||||
}
|
||||
|
||||
func (data *data) GetTitle() string {
|
||||
return data.title
|
||||
}
|
||||
|
||||
func (data *data) GetFormats() []string {
|
||||
return data.formats
|
||||
}
|
||||
|
||||
func (data *data) NewEncoder() EncoderContract {
|
||||
return data.encoder()
|
||||
}
|
||||
|
||||
func (data *data) GetFileType() FileTypeContract {
|
||||
return data.fileType
|
||||
}
|
||||
|
||||
type FileTypeContract interface {
|
||||
Name() string
|
||||
Ordinal() int
|
||||
}
|
||||
|
||||
const (
|
||||
Video = iota
|
||||
Audio
|
||||
Image
|
||||
)
|
||||
|
||||
type FileType uint
|
||||
|
||||
var fileTypeStrings = []string{
|
||||
"video",
|
||||
"audio",
|
||||
"image",
|
||||
}
|
||||
|
||||
func (fileType FileType) Name() string {
|
||||
return fileTypeStrings[fileType]
|
||||
}
|
||||
|
||||
func (fileType FileType) Ordinal() int {
|
||||
return int(fileType)
|
||||
}
|
||||
|
||||
func GetListFileType() []FileTypeContract {
|
||||
return []FileTypeContract{
|
||||
FileType(Video),
|
||||
FileType(Audio),
|
||||
FileType(Image),
|
||||
}
|
||||
}
|
||||
|
||||
type encoder struct {
|
||||
name string
|
||||
parameters map[string]ParameterContract
|
||||
getParams func(parameters map[string]ParameterContract) []string
|
||||
}
|
||||
|
||||
func NewEncoder(name string, parameters map[string]ParameterContract, getParams func(parameters map[string]ParameterContract) []string) EncoderContract {
|
||||
return &encoder{
|
||||
name: name,
|
||||
parameters: parameters,
|
||||
getParams: getParams,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *encoder) GetName() string {
|
||||
return e.name
|
||||
}
|
||||
|
||||
func (e *encoder) GetParams() []string {
|
||||
return e.getParams(e.parameters)
|
||||
}
|
||||
|
||||
func (e *encoder) GetParameter(name string) (ParameterContract, error) {
|
||||
if e.parameters[name] == nil {
|
||||
return nil, errors.New("parameter not found")
|
||||
}
|
||||
|
||||
return e.parameters[name], nil
|
||||
}
|
||||
|
||||
type parameter struct {
|
||||
name string
|
||||
isEnabled bool
|
||||
parameter string
|
||||
setParameter func(string) (string, error)
|
||||
}
|
||||
|
||||
func NewParameter(name string, isEnabled bool, defaultParameter string, setParameter func(string) (string, error)) ParameterContract {
|
||||
return ¶meter{
|
||||
name: name,
|
||||
isEnabled: isEnabled,
|
||||
parameter: defaultParameter,
|
||||
setParameter: setParameter,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *parameter) GetName() string {
|
||||
return p.name
|
||||
}
|
||||
|
||||
func (p *parameter) Set(s string) (err error) {
|
||||
if p.setParameter != nil {
|
||||
s, err = p.setParameter(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
p.parameter = s
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *parameter) Get() string {
|
||||
return p.parameter
|
||||
}
|
||||
|
||||
func (p *parameter) IsEnabled() bool {
|
||||
return p.isEnabled
|
||||
}
|
||||
|
||||
func (p *parameter) SetEnable() {
|
||||
p.isEnabled = true
|
||||
}
|
||||
|
||||
func (p *parameter) SetDisable() {
|
||||
p.isEnabled = false
|
||||
}
|
Reference in New Issue
Block a user