ffmpeg

package
v0.5.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 32 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ffmpeg runs an optional ffmpeg (and ffprobe) for what AVFoundation, which the engine uses, cannot do: MP3, Opus and FLAC output, WebM/MKV/VP9/AV1 input, burnt-in subtitles. AudioSmith works without it: callers check Tool's capabilities and say what is missing.

Where it comes from (M7a decision: AVFoundation first, ffmpeg on demand): a pinned static build the user chooses to download (Pinned, checked by SHA-256, into the app's data folder), an ffmpeg already on the Mac (Homebrew, MacPorts, the PATH: FindSystem), or a file the user picks. It runs as a separate process; nothing links to it.

Imports: nothing internal (leaf).

Index

Constants

View Source
const (
	MP3  = "mp3"
	Opus = "opus" // Ogg Opus
	FLAC = "flac"
	OGG  = "ogg" // Ogg Vorbis
	M4A  = "m4a" // AAC in MP4 (the engine makes these too)
	WAV  = "wav"
)

Audio output formats ffmpeg adds.

Variables

View Source
var (
	// ErrNotFound: no ffmpeg is set up.
	ErrNotFound = errors.New("ffmpeg is not set up")
	// ErrNoProbe: the ffmpeg in use has no ffprobe beside it.
	ErrNoProbe = errors.New("ffprobe is missing beside ffmpeg")
)

Errors.

View Source
var MacFonts = []string{
	"/System/Library/Fonts/Helvetica.ttc",
	"/System/Library/Fonts/PingFang.ttc",
	"/System/Library/Fonts/Hiragino Sans GB.ttc",
	"/System/Library/Fonts/STHeiti Medium.ttc",
	"/System/Library/Fonts/AppleSDGothicNeo.ttc",
	"/System/Library/Fonts/Supplemental/Arial Unicode.ttf",
}

MacFonts are the fonts captions use on a Mac, in order: a bold Latin face, then faces covering Chinese, Japanese and Korean.

View Source
var Pinned = Build{
	Name:    "shaka-project/static-ffmpeg-binaries",
	Home:    "https://github.com/shaka-project/static-ffmpeg-binaries/releases/tag/n8.1.2-1",
	Version: "n8.1.2",
	Licence: "GPL-3.0",
	FFmpeg: Asset{
		Path:   "/shaka-project/static-ffmpeg-binaries/releases/download/n8.1.2-1/ffmpeg-osx-arm64",
		SHA256: "e7b9fcd97f95f333512d6e8b8ac24d9dbc08f189f36047695499bd7b57214b22",
		Size:   34074040,
	},
	FFprobe: Asset{
		Path:   "/shaka-project/static-ffmpeg-binaries/releases/download/n8.1.2-1/ffprobe-osx-arm64",
		SHA256: "ded4c698b8ff38d0bc1fd30fcc5e768dc46f58bc15a8dfd61f98615ba49cde5c",
		Size:   33882408,
	},
}

Pinned is the build "Download ffmpeg" fetches: static macOS arm64 binaries that need only system frameworks, built from source in public CI by Google's shaka-project (GitHub release n8.1.2-1, digests from the release's assets, checked against the binaries).

No reputable LGPL-only static arm64 build exists (checked 2026-10-14: BtbN has no macOS builds; evermeet, OSXExperts, Martin Riedl, Tyrrrz, eugeneware and shaka all enable GPL parts such as x264). This one is GPL-3.0: AudioSmith does not ship or link it — it is downloaded when the user asks, from the publisher's GitHub release or from the ActNow mirror of it (whether the mirror carries ffmpeg is the user's call; without it, the download comes from GitHub), and AudioSmith runs it as a separate program. Either way the file must match the digest below. Update all fields together, after checking the new digests.

View Source
var SystemPaths = []string{"/opt/homebrew/bin/ffmpeg", "/usr/local/bin/ffmpeg", "/opt/local/bin/ffmpeg"}

SystemPaths are where ffmpeg is looked for on a Mac: Homebrew (Apple silicon, then Intel), MacPorts. Apps started from the Finder do not get the shell's PATH, so these are checked first.

Functions

func FindSystem

func FindSystem() []string

FindSystem lists the ffmpeg executables on this Mac outside the app.

func Install

func Install(ctx context.Context, src *mirror.Client, dir string, b Build, progress func(done, total int64)) (string, error)

Install downloads b into dir as "ffmpeg" and "ffprobe" from the fastest of src's sources (nil: github.com and the ActNow mirror), checks both against their digests (a source that serves anything else is left for the next one), makes them executable and returns ffmpeg's path. progress gets the bytes done of the total. Files are written under temporary names and renamed only once checked; a failure leaves what was there before. When only wrong files came, the error is a *ChecksumError.

func Remove

func Remove(dir string) error

Remove deletes a build Install put in dir.

func RenderCaptions

func RenderCaptions(cues []Cue, width, height int, duration float64, fonts []string, dir string) (string, int, error)

RenderCaptions draws cues for a width × height video of duration seconds into dir and returns the ffconcat list and the strips' height (they go at the bottom of the picture).

func Verify

func Verify(dir string, b Build) error

Verify checks installed files against b's digests.

Types

type Asset

type Asset struct {
	// Path is the file under a source of GitHub releases
	// ("/owner/repo/releases/download/tag/asset"): github.com or the
	// ActNow mirror (actnowkit's mirror package).
	Path   string
	SHA256 string
	Size   int64
}

Asset is one downloadable file of a build.

func (Asset) URL

func (a Asset) URL() string

URL is the asset on github.com.

type Build

type Build struct {
	Name    string // who builds it
	Home    string // its page
	Version string // ffmpeg's version
	// Licence of the binaries (shown before the download).
	Licence string
	FFmpeg  Asset
	FFprobe Asset
}

Build is a downloadable static ffmpeg build.

func (Build) Size

func (b Build) Size() int64

Size is the download's size in bytes.

type BurnOptions

type BurnOptions struct {
	Video string
	// Audio replaces the video's sound ("" keeps it).
	Audio string
	// Subtitles is an SRT or ASS file for libass; Cues the same lines,
	// drawn by AudioSmith when this ffmpeg has no libass.
	Subtitles string
	Cues      []Cue
	// Fonts to draw Cues with, in order of preference (TrueType or
	// OpenType files or collections); a built-in Latin font comes last.
	Fonts    []string
	Output   string
	Duration float64 // the video's length (seconds)
	Width    int     // the video's size, for the drawn captions
	Height   int
}

BurnOptions make an MP4 with subtitles drawn into the picture.

type Chapter

type Chapter struct {
	Title      string
	Start, End float64
}

Chapter is a chapter mark, seconds.

type ChecksumError

type ChecksumError struct{ URL, Got string }

ChecksumError: a download did not match its pinned digest.

func (*ChecksumError) Error

func (e *ChecksumError) Error() string

type Cue

type Cue struct {
	Start, End float64
	Text       string
}

Cue is a subtitle: a time range and its text (lines separated by \n).

type DecodeOptions

type DecodeOptions struct {
	Input, Output string
	SampleRate    int     // 0 keeps the source's
	Channels      int     // 0 keeps the source's
	Bits          int     // 16 (default), 24, 32 (float)
	Start         float64 // seconds
	Duration      float64 // seconds, 0 = to the end
	Track         int     // the audio stream's index
	Total         float64 // the source's length, for progress (0 = unknown)
}

DecodeOptions decode (a window of) a file's audio to WAV.

type EncodeOptions

type EncodeOptions struct {
	Input, Output string
	Format        string // MP3, Opus, FLAC, OGG, M4A, WAV
	Bitrate       int    // bits per second, 0 = the format's default
	SampleRate    int    // 0 keeps the input's (Opus resamples to 48 kHz)
	Channels      int    // 0 keeps the input's
	// Metadata: "title", "artist", "album", "album_artist", "composer",
	// "date", "genre", "comment".
	Metadata map[string]string
	Chapters []Chapter
	Cover    string  // PNG or JPEG (MP3, M4A, FLAC)
	Duration float64 // the input's length, for progress
}

EncodeOptions encode a WAV into Format.

type Frame

type Frame struct {
	Time          float64
	Path          string
	Width, Height int
}

Frame is a thumbnail written.

type MuxOptions

type MuxOptions struct {
	Video     string
	KeepAudio bool // the source's own audio, first
	// CopyVideo keeps the video as it is (H.264/HEVC); otherwise it is
	// encoded to H.264 (VP9, AV1 and others in an MP4 play nowhere).
	CopyVideo bool
	Audio     []Track
	Subtitles []SubtitleTrack
	Output    string
	Duration  float64
}

MuxOptions make an MP4 of Video's video with audio tracks and soft subtitles.

type NoEncoderError

type NoEncoderError struct{ Format string }

NoEncoderError: the ffmpeg in use cannot write a format.

func (*NoEncoderError) Error

func (e *NoEncoderError) Error() string

type Probe

type Probe struct {
	Format   string  // container names, "matroska,webm"
	Duration float64 // seconds
	Audio    []Stream
	Video    []Stream
}

Probe describes a media file (ffprobe).

type RunError

type RunError struct {
	Err  error
	Tail string
}

RunError is a failed ffmpeg run: its exit and the last lines it wrote.

func (*RunError) Error

func (e *RunError) Error() string

func (*RunError) Unwrap

func (e *RunError) Unwrap() error

type Stream

type Stream struct {
	Codec      string
	SampleRate int
	Channels   int
	Bits       int // PCM bit depth (0 for compressed audio)
	BitRate    int
	Width      int
	Height     int
	FPS        float64
}

Stream is one audio or video stream.

type SubtitleTrack

type SubtitleTrack struct {
	Path     string
	Language string // ISO 639-2
	Title    string
	Default  bool
}

SubtitleTrack is a soft subtitle track (SRT or WebVTT).

type Tool

type Tool struct {
	FFmpeg  string // the executable
	FFprobe string // ffprobe beside it, "" when there is none
	Version string // "8.1.2", "n8.1.2", "6.1.1-3ubuntu5"…
	// Licence is how it was built: "LGPL", "GPL" or "nonfree" (not
	// redistributable), from its configuration.
	Licence string
	Config  string // the configure line
	// contains filtered or unexported fields
}

Tool is an ffmpeg executable and what it can do.

func Inspect

func Inspect(ctx context.Context, path string) (*Tool, error)

Inspect asks the ffmpeg at path for its version, licence, encoders and filters (a second or so), and looks for ffprobe beside it.

func (*Tool) Burn

func (t *Tool) Burn(ctx context.Context, o BurnOptions, progress func(float64)) error

Burn writes o.Output: the video re-encoded with its subtitles drawn in, and the chosen audio in AAC.

func (*Tool) CanBurn

func (t *Tool) CanBurn() bool

CanBurn reports whether this ffmpeg can burn subtitles in: with libass (the subtitles filter), or the captions AudioSmith draws (overlay).

func (*Tool) CanEncode

func (t *Tool) CanEncode(format string) bool

CanEncode reports whether this ffmpeg writes an audio format.

func (*Tool) DecodeAudio

func (t *Tool) DecodeAudio(ctx context.Context, o DecodeOptions, progress func(float64)) error

DecodeAudio writes the audio of o.Input as WAV.

func (*Tool) EncodeAudio

func (t *Tool) EncodeAudio(ctx context.Context, o EncodeOptions, progress func(float64)) error

EncodeAudio writes o.Input in o.Format.

func (*Tool) HasEncoder

func (t *Tool) HasEncoder(name string) bool

HasEncoder reports an encoder ("libmp3lame", "h264_videotoolbox").

func (*Tool) HasFilter

func (t *Tool) HasFilter(name string) bool

HasFilter reports a filter ("subtitles", "overlay").

func (*Tool) Mux

func (t *Tool) Mux(ctx context.Context, o MuxOptions, progress func(float64)) error

Mux writes o.Output.

func (*Tool) Probe

func (t *Tool) Probe(ctx context.Context, path string) (Probe, error)

Probe asks ffprobe about path.

func (*Tool) Thumbnails

func (t *Tool) Thumbnails(ctx context.Context, input string, times []float64, outputs []string, width int) ([]Frame, error)

Thumbnails writes one image per time into outputs (JPEG or PNG by extension), width wide (0 = the video's).

func (*Tool) Transcode

func (t *Tool) Transcode(ctx context.Context, o TranscodeOptions, progress func(float64)) error

Transcode writes a preview MP4 the web view plays.

type Track

type Track struct {
	Path     string
	Language string // ISO 639-2 ("spa"), as MP4 wants
	Title    string
	Default  bool
	Bitrate  int // b/s, 0 = 192 kb/s
}

Track is an audio track to add to a video.

type TranscodeOptions

type TranscodeOptions struct {
	Input, Output string
	MaxHeight     int // 0 = 720
	NoAudio       bool
	Duration      float64 // for progress
}

TranscodeOptions make an H.264 + AAC MP4 preview.

Jump to

Keyboard shortcuts

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