diff --git a/CHANGELOG.md b/CHANGELOG.md index 7026f12..94b7512 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ queries and scanning results. * *(exsync)* Added generic `Set` utility that wraps a valueless map with a mutex. * *(exerrors)* Added `Must` helper to turn `(T, error)` returns into `T` or panic. +* *(ffmpeg)* Added `Supported` and `SetPath` for checking if ffmpeg is available + and overriding the binary path respectively. # v0.2.1 (2023-11-16) diff --git a/ffmpeg/convert.go b/ffmpeg/convert.go index e403da9..4152f79 100644 --- a/ffmpeg/convert.go +++ b/ffmpeg/convert.go @@ -22,6 +22,25 @@ import ( var ffmpegDefaultParams = []string{"-hide_banner", "-loglevel", "warning"} +var ffmpegPath string + +func init() { + ffmpegPath, _ = exec.LookPath("ffmpeg") +} + +// Supported returns whether ffmpeg is available on the system. +// +// ffmpeg is considered to be available if a binary called ffmpeg is found in $PATH, +// or if [SetPath] has been called explicitly with a non-empty path. +func Supported() bool { + return ffmpegPath != "" +} + +// SetPath overrides the path to the ffmpeg binary. +func SetPath(path string) { + ffmpegPath = path +} + // ConvertPath converts a media file on the disk using ffmpeg. // // Args: @@ -42,7 +61,7 @@ func ConvertPath(ctx context.Context, inputFile string, outputExtension string, args = append(args, outputArgs...) args = append(args, outputFilename) - cmd := exec.CommandContext(ctx, "ffmpeg", args...) + cmd := exec.CommandContext(ctx, ffmpegPath, args...) ctxLog := zerolog.Ctx(ctx).With().Str("command", "ffmpeg").Logger() logWriter := exzerolog.NewLogWriter(ctxLog).WithLevel(zerolog.WarnLevel) cmd.Stdout = logWriter