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.
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
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
|
|
}
|