Added the ability to get the FFmpeg version.

This commit is contained in:
Leonid Nikitin 2025-06-09 23:19:48 +05:00
parent c49957e583
commit c8619cdc7f
Signed by: kor-elf
GPG Key ID: DAB5355A11C22541
2 changed files with 27 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import (
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/utils" "git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/utils"
"io" "io"
"os/exec" "os/exec"
"regexp"
"strings" "strings"
) )
@ -17,6 +18,7 @@ type ProgressContract interface {
type FFmpegContract interface { type FFmpegContract interface {
GetPath() string GetPath() string
GetFFmpegVersion() (string, error)
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 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 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 { func (f *ffmpeg) RunConvert(setting ConvertSetting, progress ProgressContract, beforeWait func(cmd *exec.Cmd), afterWait func(cmd *exec.Cmd)) error {
overwriteOutputFiles := "-n" overwriteOutputFiles := "-n"
if setting.OverwriteOutputFiles == true { if setting.OverwriteOutputFiles == true {

View File

@ -24,6 +24,7 @@ type UtilitiesContract interface {
UtilityCheck() bool UtilityCheck() bool
GetFFmpeg() (FFmpegContract, error) GetFFmpeg() (FFmpegContract, error)
GetFFmpegVersion() string
GetFFmpegPath() string GetFFmpegPath() string
ChangeFFmpeg(path string) error ChangeFFmpeg(path string) error
@ -82,6 +83,19 @@ func (u *utilities) GetFFmpeg() (FFmpegContract, error) {
return u.ffmpeg, nil 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 { func (u *utilities) GetFFmpegPath() string {
ffmpegService, err := u.GetFFmpeg() ffmpegService, err := u.GetFFmpeg()
if err != nil { if err != nil {