diff --git a/internal/ffmpeg/ffmpeg.go b/internal/ffmpeg/ffmpeg.go index b303182..515e180 100644 --- a/internal/ffmpeg/ffmpeg.go +++ b/internal/ffmpeg/ffmpeg.go @@ -7,6 +7,7 @@ import ( "git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/utils" "io" "os/exec" + "regexp" "strings" ) @@ -17,6 +18,7 @@ type ProgressContract interface { type FFmpegContract interface { GetPath() string + GetFFmpegVersion() (string, error) GetEncoders(scanner func(scanner *bufio.Reader)) error RunConvert(setting ConvertSetting, progress ProgressContract, beforeWait func(cmd *exec.Cmd), afterWait func(cmd *exec.Cmd)) error } @@ -47,6 +49,17 @@ func (f *ffmpeg) GetPath() string { return f.path } +func (f *ffmpeg) GetFFmpegVersion() (string, error) { + cmd := exec.Command(f.path, "-version") + utils.PrepareBackgroundCommand(cmd) + out, err := cmd.CombinedOutput() + if err != nil { + return "", err + } + text := regexp.MustCompile("\r?\n").Split(strings.TrimSpace(string(out)), -1) + return text[0], nil +} + 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 { diff --git a/internal/ffmpeg/utilities.go b/internal/ffmpeg/utilities.go index 214f862..61b680b 100644 --- a/internal/ffmpeg/utilities.go +++ b/internal/ffmpeg/utilities.go @@ -24,6 +24,7 @@ type UtilitiesContract interface { UtilityCheck() bool GetFFmpeg() (FFmpegContract, error) + GetFFmpegVersion() string GetFFmpegPath() string ChangeFFmpeg(path string) error @@ -82,6 +83,19 @@ func (u *utilities) GetFFmpeg() (FFmpegContract, error) { return u.ffmpeg, nil } +func (u *utilities) GetFFmpegVersion() string { + ffmpegService, err := u.GetFFmpeg() + if err != nil { + return lang.L("errorFFmpegVersion") + } + + version, err := ffmpegService.GetFFmpegVersion() + if err != nil { + return lang.L("errorFFmpegVersion") + } + return version +} + func (u *utilities) GetFFmpegPath() string { ffmpegService, err := u.GetFFmpeg() if err != nil {