From c4438180900814ed6e09cd17bd77705225a6b011 Mon Sep 17 00:00:00 2001 From: Dominik Polakovics Date: Fri, 8 Nov 2024 11:47:33 +0100 Subject: [PATCH] feat: add ffmpeg binaries --- .gitattributes | 2 + internal/ffmpeg/darwin.go | 73 +++++++++++++++++++++++++++ internal/ffmpeg/darwin_amd64/ffmpeg | 3 ++ internal/ffmpeg/darwin_amd64/ffprobe | 3 ++ internal/ffmpeg/darwin_arm64/ffmpeg | 3 ++ internal/ffmpeg/darwin_arm64/ffprobe | 3 ++ internal/ffmpeg/linux_amd64.go | 52 +++++++++++++++++++ internal/ffmpeg/linux_amd64/ffmpeg | 3 ++ internal/ffmpeg/linux_amd64/ffprobe | 3 ++ internal/ffmpeg/windows_amd64.go | 52 +++++++++++++++++++ internal/ffmpeg/windows_amd64/ffmpeg | 3 ++ internal/ffmpeg/windows_amd64/ffprobe | 3 ++ 12 files changed, 203 insertions(+) create mode 100644 .gitattributes create mode 100644 internal/ffmpeg/darwin.go create mode 100755 internal/ffmpeg/darwin_amd64/ffmpeg create mode 100755 internal/ffmpeg/darwin_amd64/ffprobe create mode 100755 internal/ffmpeg/darwin_arm64/ffmpeg create mode 100755 internal/ffmpeg/darwin_arm64/ffprobe create mode 100644 internal/ffmpeg/linux_amd64.go create mode 100755 internal/ffmpeg/linux_amd64/ffmpeg create mode 100755 internal/ffmpeg/linux_amd64/ffprobe create mode 100644 internal/ffmpeg/windows_amd64.go create mode 100644 internal/ffmpeg/windows_amd64/ffmpeg create mode 100644 internal/ffmpeg/windows_amd64/ffprobe diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..c0351f8 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +ffmpeg filter=lfs diff=lfs merge=lfs -text +ffprobe filter=lfs diff=lfs merge=lfs -text diff --git a/internal/ffmpeg/darwin.go b/internal/ffmpeg/darwin.go new file mode 100644 index 0000000..00241d5 --- /dev/null +++ b/internal/ffmpeg/darwin.go @@ -0,0 +1,73 @@ +//go:build darwin +// +build darwin + +package ffmpeg + +import ( + _ "embed" + "fmt" + "os" + "runtime" +) + +//go:embed darwin_amd64/ffmpeg +var ffmpegAmd64 []byte +//go:embed darwin_amd64/ffprobe +var ffprobeAmd64 []byte + +//go:embed darwin_arm64/ffmpeg +var ffmpegArm64 []byte +//go:embed darwin_arm64/ffprobe +var ffprobeArm64 []byte + +func writeTempExec(pattern string, binary []byte) (string, error) { + f, err := os.CreateTemp("", pattern) + if err != nil { + return "", fmt.Errorf("failed to create temp file: %v", err) + } + defer f.Close() + _, err = f.Write(binary) + if err != nil { + return "", fmt.Errorf("fail to write executable: %v", err) + } + if err := f.Chmod(os.ModePerm); err != nil { + return "", fmt.Errorf("fail to chmod: %v", err) + } + return f.Name(), nil +} + +var ( + ffmpegPath string + ffprobePath string +) + +func FFmpegPath() string { return ffmpegPath } + +func FFprobePath() string { return ffprobePath } + +func init() { + var err error + + switch runtime.GOARCH { + case "amd64": + ffmpegPath, err = writeTempExec("ffmpeg_linux_amd64", ffmpegAmd64) + if err != nil { + panic(fmt.Errorf("failed to write ffmpeg_linux_amd64: %v", err)) + } + ffprobePath, err = writeTempExec("ffprobe_linux_amd64", ffprobeAmd64) + if err != nil { + panic(fmt.Errorf("failed to write ffprobe_linux_amd64: %v", err)) + } + case "arm64": + ffmpegPath, err = writeTempExec("ffmpeg_linux_amd64", ffmpegArm64) + if err != nil { + panic(fmt.Errorf("failed to write ffmpeg_linux_amd64: %v", err)) + } + ffprobePath, err = writeTempExec("ffprobe_linux_amd64", ffprobeArm64) + if err != nil { + panic(fmt.Errorf("failed to write ffprobe_linux_amd64: %v", err)) + } + default: + panic(fmt.Errorf("Running on an unknown architecture: %s\n", runtime.GOARCH)) + } +} diff --git a/internal/ffmpeg/darwin_amd64/ffmpeg b/internal/ffmpeg/darwin_amd64/ffmpeg new file mode 100755 index 0000000..843cb9b --- /dev/null +++ b/internal/ffmpeg/darwin_amd64/ffmpeg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:31b54ce40088787bc967d9938863a28a6bed0fdf54c42f51f04e1e178b35d536 +size 79556888 diff --git a/internal/ffmpeg/darwin_amd64/ffprobe b/internal/ffmpeg/darwin_amd64/ffprobe new file mode 100755 index 0000000..adf89d6 --- /dev/null +++ b/internal/ffmpeg/darwin_amd64/ffprobe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:63910b412203b41fed26b8c515c15fd2fefb4fc8eed54ea9521031c385e39df1 +size 79470088 diff --git a/internal/ffmpeg/darwin_arm64/ffmpeg b/internal/ffmpeg/darwin_arm64/ffmpeg new file mode 100755 index 0000000..ea33fd0 --- /dev/null +++ b/internal/ffmpeg/darwin_arm64/ffmpeg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:326895b16940f238d76e902fc71150f10c388c281985756f9850ff800a2f1499 +size 49056648 diff --git a/internal/ffmpeg/darwin_arm64/ffprobe b/internal/ffmpeg/darwin_arm64/ffprobe new file mode 100755 index 0000000..2adb619 --- /dev/null +++ b/internal/ffmpeg/darwin_arm64/ffprobe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:307e09bc01bd72bde5f441a1a6df68769da3b2b6e431accfbfc9cf3893ad00c4 +size 48998536 diff --git a/internal/ffmpeg/linux_amd64.go b/internal/ffmpeg/linux_amd64.go new file mode 100644 index 0000000..69ce2ae --- /dev/null +++ b/internal/ffmpeg/linux_amd64.go @@ -0,0 +1,52 @@ +//go:build linux && amd64 + +package ffmpeg + +import ( + _ "embed" + "fmt" + "os" +) + +//go:embed linux_amd64/ffmpeg +var ffmpeg []byte + +//go:embed linux_amd64/ffprobe +var ffprobe []byte + +func writeTempExec(pattern string, binary []byte) (string, error) { + f, err := os.CreateTemp("", pattern) + if err != nil { + return "", fmt.Errorf("failed to create temp file: %v", err) + } + defer f.Close() + _, err = f.Write(binary) + if err != nil { + return "", fmt.Errorf("fail to write executable: %v", err) + } + if err := f.Chmod(os.ModePerm); err != nil { + return "", fmt.Errorf("fail to chmod: %v", err) + } + return f.Name(), nil +} + +var ( + ffmpegPath string + ffprobePath string +) + +func FFmpegPath() string { return ffmpegPath } + +func FFprobePath() string { return ffprobePath } + +func init() { + var err error + ffmpegPath, err = writeTempExec("ffmpeg_linux_amd64", ffmpeg) + if err != nil { + panic(fmt.Errorf("failed to write ffmpeg_linux_amd64: %v", err)) + } + ffprobePath, err = writeTempExec("ffprobe_linux_amd64", ffprobe) + if err != nil { + panic(fmt.Errorf("failed to write ffprobe_linux_amd64: %v", err)) + } +} diff --git a/internal/ffmpeg/linux_amd64/ffmpeg b/internal/ffmpeg/linux_amd64/ffmpeg new file mode 100755 index 0000000..f6a8f74 --- /dev/null +++ b/internal/ffmpeg/linux_amd64/ffmpeg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e7e7fb30477f717e6f55f9180a70386c62677ef8a4d4d1a5d948f4098aa3eb99 +size 79826272 diff --git a/internal/ffmpeg/linux_amd64/ffprobe b/internal/ffmpeg/linux_amd64/ffprobe new file mode 100755 index 0000000..0c4bc66 --- /dev/null +++ b/internal/ffmpeg/linux_amd64/ffprobe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4f231a1960d83e403d08f7971e271707bec278a9ae18e21b8b5b03186668450d +size 79665792 diff --git a/internal/ffmpeg/windows_amd64.go b/internal/ffmpeg/windows_amd64.go new file mode 100644 index 0000000..6fbe9a7 --- /dev/null +++ b/internal/ffmpeg/windows_amd64.go @@ -0,0 +1,52 @@ +//go:build windows && amd64 + +package ffmpeg + +import ( + _ "embed" + "fmt" + "os" +) + +//go:embed windows_amd64/ffmpeg +var ffmpeg []byte + +//go:embed windows_amd64/ffprobe +var ffprobe []byte + +func writeTempExec(pattern string, binary []byte) (string, error) { + f, err := os.CreateTemp("", pattern) + if err != nil { + return "", fmt.Errorf("failed to create temp file: %v", err) + } + defer f.Close() + _, err = f.Write(binary) + if err != nil { + return "", fmt.Errorf("fail to write executable: %v", err) + } + if err := f.Chmod(os.ModePerm); err != nil { + return "", fmt.Errorf("fail to chmod: %v", err) + } + return f.Name(), nil +} + +var ( + ffmpegPath string + ffprobePath string +) + +func FFmpegPath() string { return ffmpegPath } + +func FFprobePath() string { return ffprobePath } + +func init() { + var err error + ffmpegPath, err = writeTempExec("ffmpeg_windows_amd64", ffmpeg) + if err != nil { + panic(fmt.Errorf("failed to write ffmpeg_windows_amd64: %v", err)) + } + ffprobePath, err = writeTempExec("ffprobe_windows_amd64", ffprobe) + if err != nil { + panic(fmt.Errorf("failed to write ffprobe_windows_amd64: %v", err)) + } +} diff --git a/internal/ffmpeg/windows_amd64/ffmpeg b/internal/ffmpeg/windows_amd64/ffmpeg new file mode 100644 index 0000000..960fabe --- /dev/null +++ b/internal/ffmpeg/windows_amd64/ffmpeg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:36a59b638b49f8e6c622f4de7c4c8aaf8442f30138a58882ee2af3f410e5fd5c +size 148103168 diff --git a/internal/ffmpeg/windows_amd64/ffprobe b/internal/ffmpeg/windows_amd64/ffprobe new file mode 100644 index 0000000..bf6b6e5 --- /dev/null +++ b/internal/ffmpeg/windows_amd64/ffprobe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5de9d7a6e30b24d84f7a8d98a01698b2592463f75660853d182d1b00fb8c2ddc +size 147965440