Add RunConvert
method to FFmpegContract
and implementation
Extend `FFmpegContract` with `RunConvert` for handling file conversion, including progress tracking and callback support before and after execution.
This commit is contained in:
parent
eb43669ae7
commit
1b1cdd5c22
@ -5,13 +5,20 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fyne.io/fyne/v2/lang"
|
"fyne.io/fyne/v2/lang"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/utils"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/utils"
|
||||||
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ProgressContract interface {
|
||||||
|
GetProtocole() string
|
||||||
|
Run(stdOut io.ReadCloser, stdErr io.ReadCloser) error
|
||||||
|
}
|
||||||
|
|
||||||
type FFmpegContract interface {
|
type FFmpegContract interface {
|
||||||
GetPath() string
|
GetPath() string
|
||||||
GetEncoders(scanner func(scanner *bufio.Reader)) error
|
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 {
|
type ffmpeg struct {
|
||||||
@ -40,6 +47,51 @@ func (f *ffmpeg) GetPath() string {
|
|||||||
return f.path
|
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 {
|
func (f *ffmpeg) GetEncoders(scanner func(scanner *bufio.Reader)) error {
|
||||||
cmd := exec.Command(f.path, "-encoders")
|
cmd := exec.Command(f.path, "-encoders")
|
||||||
utils.PrepareBackgroundCommand(cmd)
|
utils.PrepareBackgroundCommand(cmd)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user