ffmpeg

package
v0.9.0-dev.39 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package ffmpeg provides low-level ffmpeg/ffprobe subprocess wrappers for stream probing, subtitle extraction, and PCM audio extraction. This package is pure I/O — it does not depend on subsync's Cue type.

Index

Constants

View Source
const (
	CodecASS = "ass"
	CodecSSA = "ssa"
)

Codec name constants for the most commonly referenced subtitle formats.

View Source
const MaxExtractBytes = 50 * 1024 * 1024

MaxExtractBytes is the maximum size for ffmpeg stdout reads (subtitle extraction, ASS conversion). Prevents OOM from pathological streams.

View Source
const PCMSampleRate = 8000

PCMSampleRate is the sample rate used for PCM audio extraction.

Variables

This section is empty.

Functions

func Available

func Available() bool

Available checks if ffmpeg is on PATH.

func ExtractRawSubtitle

func ExtractRawSubtitle(ctx context.Context, videoPath string, streamIndex int) ([]byte, error)

ExtractRawSubtitle runs ffmpeg to extract a subtitle stream by index, converting to SRT format. Returns raw bytes (no parsing).

func ExtractSegmentPCM

func ExtractSegmentPCM(ctx context.Context, path string, startMs, durationMs int64) ([]int16, error)

ExtractSegmentPCM extracts raw PCM audio from a time range. Returns int16 samples at PCMSampleRate. durationMs=0 means no limit.

func NormalizeFFprobeLang

func NormalizeFFprobeLang(lang string, mapper LangMapper) string

NormalizeFFprobeLang resolves an ffprobe stream language tag onto subflux's internal code space via mapper, which owns canonicalization; this function contributes only the ffprobe-specific conventions.

ffprobe writes "und" (and some muxers "undetermined") for a track nobody tagged. Those are rejected here so an untagged track can never present itself as a language — the property FuzzNormalizeFFprobeLangUnd pins. mapper rejects them too, so the guard is redundant by construction and kept deliberately: this is where the container convention is documented, and it holds even if a caller injects a different mapper.

Everything else is mapper's call. This function previously truncated the tag at the first hyphen before consulting mapper, which discarded the region and collapsed a "pt-BR" audio track onto European Portuguese, and it returned an unrecognized three-letter code verbatim, putting it in a two-letter namespace. Both are gone: the whole tag reaches mapper, and an unresolvable tag yields "".

A nil mapper yields "" for any tag: with no canonicalizer there is nothing that could resolve one.

func ProbeVideoFPS

func ProbeVideoFPS(ctx context.Context, path string) float64

ProbeVideoFPS returns the video stream's frame rate, or 0 if unavailable.

Types

type LangMapper

type LangMapper func(string) string

LangMapper resolves a raw language identifier — an ffprobe stream tag in any published code system, with or without a region — onto the caller's internal code space, returning "" for anything it cannot represent. It is injected rather than imported so this package stays free of provider dependencies; subflux supplies classify.Alpha2FromAlpha3.

type Track

type Track struct {
	CodecName       string
	Language        string // extracted from tags
	Title           string // extracted from tags
	RFrameRate      string // raw r_frame_rate from ffprobe (e.g. "24000/1001")
	Index           int
	Forced          bool // from disposition
	HearingImpaired bool // from disposition
}

Track holds metadata for a single stream from ffprobe output.

func ParseProbeOutput

func ParseProbeOutput(data []byte) ([]Track, error)

ParseProbeOutput parses raw ffprobe JSON output into Track structs.

func ProbeStreams

func ProbeStreams(ctx context.Context, path, filterType string) ([]Track, error)

ProbeStreams runs ffprobe and returns parsed stream metadata. Filters by codec_type if filterType is non-empty (e.g. "subtitle", "audio").

func SelectBestSubTrack

func SelectBestSubTrack(tracks []Track, lang, excludeLang string, mapper LangMapper) *Track

SelectBestSubTrack picks the best text subtitle track from ffprobe output.

Jump to

Keyboard shortcuts

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