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.
75 lines
1.3 KiB
Go
75 lines
1.3 KiB
Go
package ffmpeg
|
|
|
|
import (
|
|
"bufio"
|
|
"errors"
|
|
"fyne.io/fyne/v2/lang"
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/utils"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
type FFmpegContract interface {
|
|
GetPath() string
|
|
GetEncoders(scanner func(scanner *bufio.Reader)) error
|
|
}
|
|
|
|
type ffmpeg struct {
|
|
path string
|
|
}
|
|
|
|
func newFFmpeg(path string) (FFmpegContract, error) {
|
|
if path == "" {
|
|
return nil, errors.New(lang.L("errorFFmpeg"))
|
|
}
|
|
|
|
isCheck, err := checkFFmpegPath(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if isCheck == false {
|
|
return nil, errors.New(lang.L("errorFFmpeg"))
|
|
}
|
|
|
|
return &ffmpeg{
|
|
path: path,
|
|
}, nil
|
|
}
|
|
|
|
func (f *ffmpeg) GetPath() string {
|
|
return f.path
|
|
}
|
|
|
|
func (f *ffmpeg) GetEncoders(scanner func(scanner *bufio.Reader)) error {
|
|
cmd := exec.Command(f.path, "-encoders")
|
|
utils.PrepareBackgroundCommand(cmd)
|
|
|
|
stdOut, err := cmd.StdoutPipe()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = cmd.Start()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
scannerErr := bufio.NewReader(stdOut)
|
|
scanner(scannerErr)
|
|
|
|
return cmd.Wait()
|
|
}
|
|
|
|
func checkFFmpegPath(path string) (bool, error) {
|
|
cmd := exec.Command(path, "-version")
|
|
utils.PrepareBackgroundCommand(cmd)
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
if strings.Contains(strings.TrimSpace(string(out)), "ffmpeg") == false {
|
|
return false, nil
|
|
}
|
|
return true, nil
|
|
}
|