Версия 1.0.0 #11
@ -5,13 +5,20 @@ import (
|
||||
"errors"
|
||||
"fyne.io/fyne/v2/lang"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/utils"
|
||||
"io"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ProgressContract interface {
|
||||
GetProtocole() string
|
||||
Run(stdOut io.ReadCloser, stdErr io.ReadCloser) error
|
||||
}
|
||||
|
||||
type FFmpegContract interface {
|
||||
GetPath() string
|
||||
GetEncoders(scanner func(scanner *bufio.Reader)) error
|
||||
RunConvert(setting ConvertSetting, progress ProgressContract, beforeWait func(cmd *exec.Cmd), afterWait func(cmd *exec.Cmd)) error
|
||||
}
|
||||
|
||||
type ffmpeg struct {
|
||||
@ -40,6 +47,51 @@ func (f *ffmpeg) GetPath() string {
|
||||
return f.path
|
||||
}
|
||||
|
||||
func (f *ffmpeg) RunConvert(setting ConvertSetting, progress ProgressContract, beforeWait func(cmd *exec.Cmd), afterWait func(cmd *exec.Cmd)) error {
|
||||
overwriteOutputFiles := "-n"
|
||||
if setting.OverwriteOutputFiles == true {
|
||||
overwriteOutputFiles = "-y"
|
||||
}
|
||||
args := []string{overwriteOutputFiles, "-i", setting.FileInput.Path}
|
||||
args = append(args, setting.Encoder.GetParams()...)
|
||||
args = append(args, "-progress", progress.GetProtocole(), setting.FileOut.Path)
|
||||
cmd := exec.Command(f.path, args...)
|
||||
utils.PrepareBackgroundCommand(cmd)
|
||||
|
||||
stdOut, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
stdErr, err := cmd.StderrPipe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if beforeWait != nil {
|
||||
beforeWait(cmd)
|
||||
}
|
||||
|
||||
errProgress := progress.Run(stdOut, stdErr)
|
||||
|
||||
err = cmd.Wait()
|
||||
if afterWait != nil {
|
||||
afterWait(cmd)
|
||||
}
|
||||
if errProgress != nil {
|
||||
return errProgress
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *ffmpeg) GetEncoders(scanner func(scanner *bufio.Reader)) error {
|
||||
cmd := exec.Command(f.path, "-encoders")
|
||||
utils.PrepareBackgroundCommand(cmd)
|
||||
|
Loading…
x
Reference in New Issue
Block a user