ffmpeg

package
v0.10.0-dev.53 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package ffmpeg is subflux's one ffmpeg and ffprobe runner. Every call has a deadline and a stdout cap, keeps only a bounded tail of stderr, kills its child when the call ends early, and hands the child the video as an open file, never as a path.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnavailable means the ffmpeg or ffprobe binary is not there.
	ErrUnavailable = errors.New("ffmpeg: not available")
	// ErrOutputCap means the child wrote past its call's cap and was stopped there.
	ErrOutputCap = errors.New("ffmpeg: output over its cap")
)

Functions

This section is empty.

Types

type Runner

type Runner struct{ FFmpeg, FFprobe string }

Runner runs ffmpeg and ffprobe. Its zero value runs them from PATH; FFmpeg and FFprobe name other binaries.

func (Runner) ExtractSubtitle

func (r Runner) ExtractSubtitle(ctx context.Context, video *os.File, index int, keepASS bool) ([]byte, error)

ExtractSubtitle returns stream index of video as an ASS document when keepASS is set (the stream is copied, so it must be ASS or SSA), else converted to SRT; over maxExtractBytes is ErrOutputCap.

func (Runner) PCM

func (r Runner) PCM(ctx context.Context, video *os.File, maxFrames int, frame func([]int16) error) error

PCM decodes video's first audio stream to 8 kHz mono and calls frame with each 80-sample (10 ms) frame in order; the slice is reused, so frame must not keep it. It returns frame's first error, or nil once the stream ends or maxFrames frames (at most 500,000) were passed, the child then killed. A trailing part frame is dropped.

func (Runner) Preview

func (r Runner) Preview(ctx context.Context, video *os.File, from time.Duration) (io.ReadCloser, error)

Preview streams a fragmented MP4 of video from from: 360p H.264 ultrafast with AAC stereo, at most timing.PreviewSpan long, its timestamps starting at 0. The stream ends at maxPreviewBytes or previewTimeout; a read returns the child's failure, if any, in place of io.EOF. Close kills the child and is safe while a Read is blocked.

func (Runner) Probe

func (r Runner) Probe(ctx context.Context, video *os.File) ([]Stream, error)

Probe lists video's streams through ffprobe.

type Stream

type Stream struct {
	Type            string // subtitle, video, audio
	Codec           string // ffprobe's codec_name
	Language        string
	Title           string
	FrameRate       float64 // video streams; 0 unknown
	Index           int
	Forced          bool
	HearingImpaired bool
}

Stream is one stream of a probed video.

Directories

Path Synopsis
Package ffmpegtest lets a test binary stand in for ffmpeg and ffprobe.
Package ffmpegtest lets a test binary stand in for ffmpeg and ffprobe.

Jump to

Keyboard shortcuts

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