support for homebrew ffmpeg on macos (#649)

* support for homebrew ffmpeg on macos

* Add build instructions

* Revise README

* Detect homebrew and install ffmpeg with homebrew

---------

Co-authored-by: afkarxyz <mzamzamafkarhadiq@gmail.com>
This commit is contained in:
sh4tteredd
2026-03-24 15:00:31 +01:00
committed by GitHub
parent eb468b16df
commit ae2e4eb155
3 changed files with 156 additions and 15 deletions
+91
View File
@@ -81,6 +81,28 @@ func GetFFmpegPath() (string, error) {
return localPath, nil
}
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
homebrewPath := "/opt/homebrew/bin/" + ffmpegName
if _, err := os.Stat(homebrewPath); err == nil {
return homebrewPath, nil
}
} else if runtime.GOOS == "darwin" && runtime.GOARCH == "amd64" {
homebrewPath := "/usr/local/bin/" + ffmpegName
if _, err := os.Stat(homebrewPath); err == nil {
return homebrewPath, nil
}
}
if runtime.GOOS != "windows" {
path, err := exec.Command("which", ffmpegName).Output()
if err == nil {
trimmed := strings.TrimSpace(string(path))
if trimmed != "" {
return trimmed, nil
}
}
}
path, err := exec.LookPath(ffmpegName)
if err == nil {
return path, nil
@@ -105,6 +127,28 @@ func GetFFprobePath() (string, error) {
return localPath, nil
}
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
homebrewPath := "/opt/homebrew/bin/" + ffprobeName
if _, err := os.Stat(homebrewPath); err == nil {
return homebrewPath, nil
}
} else if runtime.GOOS == "darwin" && runtime.GOARCH == "amd64" {
homebrewPath := "/usr/local/bin/" + ffprobeName
if _, err := os.Stat(homebrewPath); err == nil {
return homebrewPath, nil
}
}
if runtime.GOOS != "windows" {
path, err := exec.Command("which", ffprobeName).Output()
if err == nil {
trimmed := strings.TrimSpace(string(path))
if trimmed != "" {
return trimmed, nil
}
}
}
path, err := exec.LookPath(ffprobeName)
if err == nil {
return path, nil
@@ -146,6 +190,53 @@ func IsFFmpegInstalled() (bool, error) {
return err == nil, nil
}
func GetBrewPath() string {
brewPaths := []string{
"/opt/homebrew/bin/brew",
"/usr/local/bin/brew",
}
for _, path := range brewPaths {
if _, err := os.Stat(path); err == nil {
return path
}
}
return ""
}
func IsBrewFFmpegInstalled() (bool, error) {
brewPath := GetBrewPath()
if brewPath == "" {
return false, nil
}
cmd := exec.Command(brewPath, "list", "ffmpeg")
setHideWindow(cmd)
err := cmd.Run()
return err == nil, nil
}
func InstallFFmpegWithBrew(progressCallback func(int, string)) error {
brewPath := GetBrewPath()
if brewPath == "" {
return fmt.Errorf("brew not found")
}
progressCallback(10, "Installing FFmpeg via Homebrew...")
cmd := exec.Command(brewPath, "install", "ffmpeg")
setHideWindow(cmd)
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("failed to install ffmpeg: %w - %s", err, string(output))
}
progressCallback(100, "done")
return nil
}
const (
ffmpegWindowsURL = "https://github.com/afkarxyz/ffmpeg-binaries/releases/download/v8.0/ffmpeg-windows-amd64.zip"
ffmpegLinuxURL = "https://github.com/afkarxyz/ffmpeg-binaries/releases/download/v8.0/ffmpeg-linux-amd64.tar.xz"