Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ffmpeg binaries #12

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ffmpeg filter=lfs diff=lfs merge=lfs -text
ffprobe filter=lfs diff=lfs merge=lfs -text
73 changes: 73 additions & 0 deletions internal/ffmpeg/darwin.go
Original file line number Diff line number Diff line change
@@ -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))
}
}
3 changes: 3 additions & 0 deletions internal/ffmpeg/darwin_amd64/ffmpeg
Git LFS file not shown
3 changes: 3 additions & 0 deletions internal/ffmpeg/darwin_amd64/ffprobe
Git LFS file not shown
3 changes: 3 additions & 0 deletions internal/ffmpeg/darwin_arm64/ffmpeg
Git LFS file not shown
3 changes: 3 additions & 0 deletions internal/ffmpeg/darwin_arm64/ffprobe
Git LFS file not shown
52 changes: 52 additions & 0 deletions internal/ffmpeg/linux_amd64.go
Original file line number Diff line number Diff line change
@@ -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))
}
}
3 changes: 3 additions & 0 deletions internal/ffmpeg/linux_amd64/ffmpeg
Git LFS file not shown
3 changes: 3 additions & 0 deletions internal/ffmpeg/linux_amd64/ffprobe
Git LFS file not shown
52 changes: 52 additions & 0 deletions internal/ffmpeg/windows_amd64.go
Original file line number Diff line number Diff line change
@@ -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))
}
}
3 changes: 3 additions & 0 deletions internal/ffmpeg/windows_amd64/ffmpeg
Git LFS file not shown
3 changes: 3 additions & 0 deletions internal/ffmpeg/windows_amd64/ffprobe
Git LFS file not shown