Skip to content

Commit

Permalink
Add support for checking ffmpeg availability
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jan 12, 2024
1 parent f86c542 commit b89d6e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
21 changes: 20 additions & 1 deletion ffmpeg/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit b89d6e1

Please sign in to comment.