Documentation
¶
Overview ¶
Package ffmpeg runs the user's FFmpeg for Media Preview (SPEC §10.37 "Video", D53): it finds ffmpeg and ffprobe, checks the version, probes a video, and decodes its frames (RGBA) and its sound (32-bit floats, 48 kHz, stereo) through pipes. Every process runs in a process group of its own and is ended with its context; the last 4 KiB of what it writes on stderr make its errors, with the codec named when FFmpeg cannot decode it. Emetos links no decoder and stays cgo-free.
Index ¶
Constants ¶
const ( SoundRate = 48000 SoundChannels = 2 )
SoundRate is the sample rate of Sound, and SoundChannels its channels.
const MinVersion = "4.4"
MinVersion is the oldest FFmpeg accepted.
const PathSetting = "mediaPreview.ffmpegPath"
PathSetting is the setting that names the ffmpeg program.
Variables ¶
var HomebrewDirs = []string{"/opt/homebrew/bin", "/usr/local/bin"}
HomebrewDirs are the folders searched after PATH: an app started from the macOS Finder has a short PATH.
Functions ¶
func CompareVersions ¶
CompareVersions compares dotted versions number by number: -1, 0 or 1.
func ParseVersion ¶
ParseVersion finds the version in what ffmpeg -version printed; false for a build that names none.
func UnsupportedCodec ¶
UnsupportedCodec finds in what FFmpeg wrote on stderr the codec it cannot decode.
Types ¶
type FindOptions ¶
type FindOptions struct {
// Setting is the value of PathSetting: a path, or a name looked for in the folders; empty looks in PATH and HomebrewDirs.
Setting string
// Path is the value of PATH.
Path string
// Extra are the folders searched after PATH; HomebrewDirs when nil.
Extra []string
}
FindOptions say where to look.
type FrameOptions ¶
type FrameOptions struct {
// From is the time of the first frame.
From time.Duration
// Width and Height are the size of the frames in pixels; Rate the frames per second.
Width, Height int
Rate float64
}
FrameOptions say which frames Frames decodes.
type FrameReader ¶
type FrameReader struct {
// contains filtered or unexported fields
}
FrameReader reads the frames of a video, each Width x Height x 4 bytes of RGBA.
func Frames ¶
func Frames(ctx context.Context, progs Programs, path string, opts FrameOptions) (*FrameReader, error)
Frames starts decoding the frames of the video at path. It fails with FFmpegStartFailed when ffmpeg cannot be started, and with FFmpegFramesInvalid for a size or a rate that is not positive.
func (*FrameReader) FrameSize ¶
func (r *FrameReader) FrameSize() int
FrameSize is the size of a frame in bytes.
func (*FrameReader) Next ¶
func (r *FrameReader) Next(buf []byte) (bool, error)
Next reads the next frame into buf, which has FrameSize bytes. It reports false at the end of the video, and fails with the error of FFmpeg (FFmpegCodecUnsupported, FFmpegDecodeFailed), FFmpegStopped when the context ended it, and FFmpegFrameCut for a last frame that is not whole.
type Info ¶
type Info struct {
// Duration is the length of the file; 0 when it is not known (a stream).
Duration time.Duration
// HasVideo and HasAudio tell the streams it has; VideoCodec and AudioCodec name their codecs (h264, opus).
HasVideo, HasAudio bool
VideoCodec, AudioCodec string
// Width and Height are the size of the picture; Rate its frames per second.
Width, Height int
Rate float64
}
Info is what ffprobe tells of a video.
func Probe ¶
Probe asks ffprobe what the file holds: its duration and its first video and audio streams (a cover picture is not a video). It fails with FFprobeFailed when ffprobe cannot read the file (its message: "Invalid data found when processing input"), and with FFprobeOutputInvalid when what it printed is not its JSON.
type Programs ¶
type Programs struct {
// FFmpeg and FFprobe are the paths of the programs; Version is FFmpeg's version ("6.1.1"), empty when it could not be read (a
// build from git says "N-113672-g...").
FFmpeg, FFprobe, Version string
// FromSetting tells that PathSetting named the program.
FromSetting bool
}
Programs are the FFmpeg programs found.
func Find ¶
func Find(ctx context.Context, opts FindOptions) (Programs, error)
Find finds ffmpeg and the ffprobe beside it, and checks that the version is MinVersion or newer. A setting that is set is the only place looked at. It fails with FFmpegPathInvalid for a setting that names no program, FFmpegNotFound when ffmpeg is nowhere, FFprobeNotFound when the folder of ffmpeg has no ffprobe, FFmpegVersionFailed when -version cannot be run, and FFmpegTooOld.
type SoundReader ¶
type SoundReader struct {
// contains filtered or unexported fields
}
SoundReader reads the sound of a video: 32-bit little-endian floats, SoundChannels interleaved, SoundRate a second.