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:
@@ -10,8 +10,9 @@ import (
|
||||
type AppContract interface {
|
||||
FyneApp() fyne.App
|
||||
GetSetting() setting.SettingContract
|
||||
GetProgressBarService() ProgressBarContract
|
||||
GetProgressBarService() convertor.ProgressBarContract
|
||||
GetFFmpegService() ffmpeg.UtilitiesContract
|
||||
GetConvertorService() convertor.ConvertorContract
|
||||
GetItemsToConvert() convertor.ItemsToConvertContract
|
||||
GetQueueService() convertor.QueueListContract
|
||||
Run()
|
||||
@@ -20,19 +21,21 @@ type AppContract interface {
|
||||
type application struct {
|
||||
fyneApp fyne.App
|
||||
setting setting.SettingContract
|
||||
progressBarService ProgressBarContract
|
||||
progressBarService convertor.ProgressBarContract
|
||||
ffmpegService ffmpeg.UtilitiesContract
|
||||
itemsToConvert convertor.ItemsToConvertContract
|
||||
queueService convertor.QueueListContract
|
||||
convertorService convertor.ConvertorContract
|
||||
}
|
||||
|
||||
func NewApp(
|
||||
fyneApp fyne.App,
|
||||
setting setting.SettingContract,
|
||||
progressBarService ProgressBarContract,
|
||||
progressBarService convertor.ProgressBarContract,
|
||||
ffmpegService ffmpeg.UtilitiesContract,
|
||||
itemsToConvert convertor.ItemsToConvertContract,
|
||||
queueService convertor.QueueListContract,
|
||||
convertorService convertor.ConvertorContract,
|
||||
) AppContract {
|
||||
return &application{
|
||||
fyneApp: fyneApp,
|
||||
@@ -41,6 +44,7 @@ func NewApp(
|
||||
ffmpegService: ffmpegService,
|
||||
itemsToConvert: itemsToConvert,
|
||||
queueService: queueService,
|
||||
convertorService: convertorService,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +56,7 @@ func (a *application) GetSetting() setting.SettingContract {
|
||||
return a.setting
|
||||
}
|
||||
|
||||
func (a *application) GetProgressBarService() ProgressBarContract {
|
||||
func (a *application) GetProgressBarService() convertor.ProgressBarContract {
|
||||
return a.progressBarService
|
||||
}
|
||||
|
||||
@@ -68,6 +72,10 @@ func (a *application) GetQueueService() convertor.QueueListContract {
|
||||
return a.queueService
|
||||
}
|
||||
|
||||
func (a *application) GetConvertorService() convertor.ConvertorContract {
|
||||
return a.convertorService
|
||||
}
|
||||
|
||||
func (a *application) Run() {
|
||||
a.fyneApp.Run()
|
||||
}
|
||||
|
54
internal/application/convertor/convertor.go
Normal file
54
internal/application/convertor/convertor.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package convertor
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application/convertor/encoder"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ConvertorContract interface {
|
||||
GetSupportFormats() (encoder.ConvertorFormatsContract, error)
|
||||
}
|
||||
|
||||
type convertor struct {
|
||||
ffmpegService ffmpeg.UtilitiesContract
|
||||
}
|
||||
|
||||
func NewConvertor(
|
||||
ffmpegService ffmpeg.UtilitiesContract,
|
||||
) ConvertorContract {
|
||||
return &convertor{
|
||||
ffmpegService: ffmpegService,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *convertor) GetSupportFormats() (encoder.ConvertorFormatsContract, error) {
|
||||
var err error
|
||||
|
||||
formats := encoder.NewConvertorFormats()
|
||||
ffmpeg, err := c.ffmpegService.GetFFmpeg()
|
||||
if err != nil {
|
||||
return formats, err
|
||||
}
|
||||
err = ffmpeg.GetEncoders(func(scanner *bufio.Reader) {
|
||||
for {
|
||||
line, _, err := scanner.ReadLine()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
continue
|
||||
}
|
||||
text := strings.Split(strings.TrimSpace(string(line)), " ")
|
||||
encoderType := string(text[0][0])
|
||||
if len(text) < 2 || (encoderType != "V" && encoderType != "A") {
|
||||
continue
|
||||
}
|
||||
formats.NewEncoder(text[1])
|
||||
}
|
||||
})
|
||||
|
||||
return formats, err
|
||||
}
|
84
internal/application/convertor/encoder/encoder.go
Normal file
84
internal/application/convertor/encoder/encoder.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package encoder
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder"
|
||||
)
|
||||
|
||||
type ConvertorFormatContract interface {
|
||||
GetTitle() string
|
||||
AddEncoder(encoder encoder.EncoderDataContract)
|
||||
GetFileType() encoder.FileTypeContract
|
||||
GetEncoders() map[int]encoder.EncoderDataContract
|
||||
}
|
||||
|
||||
type ConvertorFormat struct {
|
||||
title string
|
||||
fileType encoder.FileTypeContract
|
||||
encoders map[int]encoder.EncoderDataContract
|
||||
}
|
||||
|
||||
func NewConvertorFormat(title string, fileType encoder.FileTypeContract) ConvertorFormatContract {
|
||||
return &ConvertorFormat{
|
||||
title: title,
|
||||
fileType: fileType,
|
||||
encoders: map[int]encoder.EncoderDataContract{},
|
||||
}
|
||||
}
|
||||
|
||||
func (f *ConvertorFormat) GetTitle() string {
|
||||
return f.title
|
||||
}
|
||||
|
||||
func (f *ConvertorFormat) AddEncoder(encoder encoder.EncoderDataContract) {
|
||||
f.encoders[len(f.encoders)] = encoder
|
||||
}
|
||||
|
||||
func (f *ConvertorFormat) GetEncoders() map[int]encoder.EncoderDataContract {
|
||||
return f.encoders
|
||||
}
|
||||
|
||||
func (f *ConvertorFormat) GetFileType() encoder.FileTypeContract {
|
||||
return f.fileType
|
||||
}
|
||||
|
||||
type ConvertorFormatsContract interface {
|
||||
NewEncoder(encoderName string) bool
|
||||
GetFormats() map[string]ConvertorFormatContract
|
||||
GetFormat(format string) (ConvertorFormatContract, error)
|
||||
}
|
||||
|
||||
type ConvertorFormats struct {
|
||||
formats map[string]ConvertorFormatContract
|
||||
}
|
||||
|
||||
func NewConvertorFormats() ConvertorFormatsContract {
|
||||
return &ConvertorFormats{
|
||||
formats: map[string]ConvertorFormatContract{},
|
||||
}
|
||||
}
|
||||
|
||||
func (f *ConvertorFormats) NewEncoder(encoderName string) bool {
|
||||
if supportEncoders[encoderName] == nil {
|
||||
return false
|
||||
}
|
||||
data := supportEncoders[encoderName]()
|
||||
for _, format := range data.GetFormats() {
|
||||
if f.formats[format] == nil {
|
||||
f.formats[format] = NewConvertorFormat(format, data.GetFileType())
|
||||
}
|
||||
f.formats[format].AddEncoder(data)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (f *ConvertorFormats) GetFormats() map[string]ConvertorFormatContract {
|
||||
return f.formats
|
||||
}
|
||||
|
||||
func (f *ConvertorFormats) GetFormat(format string) (ConvertorFormatContract, error) {
|
||||
if f.formats[format] == nil {
|
||||
return &ConvertorFormat{}, errors.New("not found ConvertorFormat")
|
||||
}
|
||||
return f.formats[format], nil
|
||||
}
|
74
internal/application/convertor/encoder/encoders.go
Normal file
74
internal/application/convertor/encoder/encoders.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package encoder
|
||||
|
||||
import (
|
||||
encoder2 "git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/apng"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/bmp"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/flv"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/gif"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/h264_nvenc"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/libmp3lame"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/libshine"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/libtwolame"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/libvpx"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/libvpx_vp9"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/libwebp"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/libwebp_anim"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/libx264"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/libx265"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/libxvid"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/mjpeg"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/mp2"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/mp2fixed"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/mpeg1video"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/mpeg2video"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/mpeg4"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/msmpeg4"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/msmpeg4v2"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/msvideo1"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/png"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/qtrle"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/sgi"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/tiff"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/wmav1"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/wmav2"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/wmv1"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/wmv2"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/encoder/xbm"
|
||||
)
|
||||
|
||||
var supportEncoders = map[string]func() encoder2.EncoderDataContract{
|
||||
"libx264": libx264.NewData,
|
||||
"h264_nvenc": h264_nvenc.NewData,
|
||||
"libx265": libx265.NewData,
|
||||
"png": png.NewData,
|
||||
"gif": gif.NewData,
|
||||
"flv": flv.NewData,
|
||||
"apng": apng.NewData,
|
||||
"bmp": bmp.NewData,
|
||||
"mjpeg": mjpeg.NewData,
|
||||
"mpeg1video": mpeg1video.NewData,
|
||||
"mpeg2video": mpeg2video.NewData,
|
||||
"mpeg4": mpeg4.NewData,
|
||||
"libxvid": libxvid.NewData,
|
||||
"msmpeg4v2": msmpeg4v2.NewData,
|
||||
"msmpeg4": msmpeg4.NewData,
|
||||
"msvideo1": msvideo1.NewData,
|
||||
"qtrle": qtrle.NewData,
|
||||
"tiff": tiff.NewData,
|
||||
"sgi": sgi.NewData,
|
||||
"libvpx": libvpx.NewData,
|
||||
"libvpx-vp9": libvpx_vp9.NewData,
|
||||
"libwebp_anim": libwebp_anim.NewData,
|
||||
"libwebp": libwebp.NewData,
|
||||
"wmv1": wmv1.NewData,
|
||||
"wmv2": wmv2.NewData,
|
||||
"xbm": xbm.NewData,
|
||||
"mp2": mp2.NewData,
|
||||
"mp2fixed": mp2fixed.NewData,
|
||||
"libtwolame": libtwolame.NewData,
|
||||
"libmp3lame": libmp3lame.NewData,
|
||||
"libshine": libshine.NewData,
|
||||
"wmav1": wmav1.NewData,
|
||||
"wmav2": wmav2.NewData,
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package application
|
||||
package convertor
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
Reference in New Issue
Block a user