ffmpeg

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 13 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 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

View Source
const (
	SoundRate     = 48000
	SoundChannels = 2
)

SoundRate is the sample rate of Sound, and SoundChannels its channels.

View Source
const MinVersion = "4.4"

MinVersion is the oldest FFmpeg accepted.

View Source
const PathSetting = "mediaPreview.ffmpegPath"

PathSetting is the setting that names the ffmpeg program.

Variables

View Source
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

func CompareVersions(a, b string) int

CompareVersions compares dotted versions number by number: -1, 0 or 1.

func ParseVersion

func ParseVersion(output string) (string, bool)

ParseVersion finds the version in what ffmpeg -version printed; false for a build that names none.

func UnsupportedCodec

func UnsupportedCodec(stderr string) (string, bool)

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) Close

func (r *FrameReader) Close() error

Close ends ffmpeg.

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.

func (*FrameReader) Pid

func (r *FrameReader) Pid() int

Pid is the id of the ffmpeg process.

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

func Probe(ctx context.Context, progs Programs, path string) (Info, error)

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.

func Sound

func Sound(ctx context.Context, progs Programs, path string, from time.Duration) (*SoundReader, error)

Sound starts decoding the sound of the video at path from a time. It fails with FFmpegStartFailed when ffmpeg cannot be started.

func (*SoundReader) Close

func (r *SoundReader) Close() error

Close ends ffmpeg.

func (*SoundReader) Pid

func (r *SoundReader) Pid() int

Pid is the id of the ffmpeg process.

func (*SoundReader) Read

func (r *SoundReader) Read(b []byte) (int, error)

Read implements io.Reader: io.EOF at the end of the sound, else the error of FFmpeg as Next gives it.

Jump to

Keyboard shortcuts

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