ffmpeg_downloader

package module
v0.0.0-...-f66ce64 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 11 Imported by: 1

README

ffmpeg-downloader

A Go library to automatically download FFmpeg in your project.

⬇️ Installation

This library can be installed using Go modules. To do that, run the following command in your project's root directory:

$ go get github.com/vegidio/ffmpeg-downloader

🤖 Usage

ffpmeg-downloader exposes three functions to check the status of FFmpeg and manage its download:

  • IsSystemInstalled(): Checks whether FFmpeg is already installed on the system by the user. If it returns true, you likely don't need to download FFmpeg, as you can use the version available in the system's PATH.
  • IsStaticallyInstalled(<name>): Checks whether FFmpeg was previously installed using ffmpeg-downloader. It returns the installation path and true if found; otherwise, it returns an empty string and false.
  • Download(<name>): Downloads the latest version of FFmpeg to the system. If successful, it returns the installation path and nil; otherwise, it returns an empty string and an error.

  • GetFFmpegPath(<name>): Uses all the three functions above to return the path to the FFmpeg executable: it first checks if FFmpeg is installed in the system, then looks for a static installation. If neither is found, it returns an empty string.

You can find a working example in the example folder.

Where is FFmpeg installed?

The IsStaticallyInstalled(<name>) and Download(<name>) functions use the user's configuration directory to locate or install FFmpeg. The path to this config directory depends on the operating system:

  • Linux: /home/<username>/.config/<name>
  • macOS: /Users/<username>/Library/Application Support/<name>
  • Windows: C:\Users\<username>\AppData\Roaming\<name>

Here, <username> refers to the current user running the application, and <name> is the parameter you provide to the functions - typically your app's name. It’s essential to use the same <name> across both functions to ensure the library can correctly locate the FFmpeg installation.

📝 License

ffmpeg-downloader is released under the MIT License. See LICENSE for details.

👨🏾‍💻 Author

Vinicius Egidio (vinicius.io)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Download

func Download(configName string) (string, error)

Download downloads and installs FFmpeg to the specified configuration directory.

Parameters:

  • configName: The name of the configuration subdirectory where FFmpeg will be installed. This directory is created under the user's config directory (e.g., ~/.config/configName on Linux).

Returns:

  • string: The full path to the downloaded FFmpeg binary if successful.
  • error: An error if any step of the download or installation process fails, including network errors, file system errors, or extraction failures.

Example:

path, err := Download("my-app")
if err != nil {
    log.Fatalf("Failed to download FFmpeg: %v", err)
}

// Use the downloaded FFmpeg binary
cmd := exec.Command(path, "-i", "input.mp4", "output.mp4")

func GetFFmpegPath

func GetFFmpegPath(configName string) string

GetFFmpegPath retrieves the path to the FFmpeg binary, ensuring it's available for use.

This function implements a fallback strategy to locate or obtain FFmpeg:

  1. First checks if FFmpeg is installed system-wide
  2. If not found system-wide, checks for a statically installed version in the config directory
  3. If neither is found, downloads and installs FFmpeg to the config directory

When FFmpeg is found system-wide, it returns an empty string since the binary is accessible via the system PATH. For statically installed or downloaded versions, it returns the full path to the binary.

Parameters:

  • configName: The name of the configuration directory where FFmpeg will be stored if downloaded or where it should be looked for if statically installed.

Returns:

  • string: The full path to the FFmpeg binary if statically installed or downloaded, or an empty string if FFmpeg is available system-wide. Returns empty string if download fails.

Example:

path := GetFFmpegPath("my-app")
if path == "" {
    // FFmpeg is available system-wide, use "ffmpeg" command directly
    cmd := exec.Command("ffmpeg", "-version")
} else {
    // Use the specific path returned
    cmd := exec.Command(path, "-version")
}

func IsStaticallyInstalled

func IsStaticallyInstalled(configName string) (string, bool)

IsStaticallyInstalled checks if FFmpeg is installed in the specified configuration directory.

Parameters:

  • configName: The name of the configuration subdirectory where FFmpeg should be located. This directory is created under the user's config directory (e.g., ~/.config/configName on Linux).

Returns:

  • string: The full path to the FFmpeg binary if found and executable, empty string otherwise.
  • bool: true if FFmpeg is found and executable in the specified location, false otherwise.

Example:

path, installed := IsStaticallyInstalled("my-app")
if installed {
    // Use the statically installed FFmpeg
    cmd := exec.Command(path, "-i", "input.mp4", "output.mp4")
} else {
    // FFmpeg not found in static location
    fmt.Println("FFmpeg not statically installed")
}

func IsSystemInstalled

func IsSystemInstalled() bool

IsSystemInstalled checks if FFmpeg is installed and accessible system-wide.

Returns:

  • bool: true if FFmpeg is found and can be executed system-wide, otherwise false.

Example:

if IsSystemInstalled() {
    // FFmpeg is available system-wide
    cmd := exec.Command("ffmpeg", "-i", "input.mp4", "output.mp4")
} else {
    // Need to download or use statically installed version
    path := GetFFmpegPath("my-app")
}

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL