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
- Variables
- func FindSystem() []string
- func Install(ctx context.Context, src *mirror.Client, dir string, b Build, ...) (string, error)
- func Remove(dir string) error
- func RenderCaptions(cues []Cue, width, height int, duration float64, fonts []string, dir string) (string, int, error)
- func Verify(dir string, b Build) error
- type Asset
- type Build
- type BurnOptions
- type Chapter
- type ChecksumError
- type Cue
- type DecodeOptions
- type EncodeOptions
- type Frame
- type MuxOptions
- type NoEncoderError
- type Probe
- type RunError
- type Stream
- type SubtitleTrack
- type Tool
- func (t *Tool) Burn(ctx context.Context, o BurnOptions, progress func(float64)) error
- func (t *Tool) CanBurn() bool
- func (t *Tool) CanEncode(format string) bool
- func (t *Tool) DecodeAudio(ctx context.Context, o DecodeOptions, progress func(float64)) error
- func (t *Tool) EncodeAudio(ctx context.Context, o EncodeOptions, progress func(float64)) error
- func (t *Tool) HasEncoder(name string) bool
- func (t *Tool) HasFilter(name string) bool
- func (t *Tool) Mux(ctx context.Context, o MuxOptions, progress func(float64)) error
- func (t *Tool) Probe(ctx context.Context, path string) (Probe, error)
- func (t *Tool) Thumbnails(ctx context.Context, input string, times []float64, outputs []string, ...) ([]Frame, error)
- func (t *Tool) Transcode(ctx context.Context, o TranscodeOptions, progress func(float64)) error
- type Track
- type TranscodeOptions
Constants ¶
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 ¶
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.
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.
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.
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 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).
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.
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.
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 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 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 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 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 ¶
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 ¶
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 ¶
Burn writes o.Output: the video re-encoded with its subtitles drawn in, and the chosen audio in AAC.
func (*Tool) CanBurn ¶
CanBurn reports whether this ffmpeg can burn subtitles in: with libass (the subtitles filter), or the captions AudioSmith draws (overlay).
func (*Tool) DecodeAudio ¶
DecodeAudio writes the audio of o.Input as WAV.
func (*Tool) EncodeAudio ¶
EncodeAudio writes o.Input in o.Format.
func (*Tool) HasEncoder ¶
HasEncoder reports an encoder ("libmp3lame", "h264_videotoolbox").