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
- func Available() bool
- func ExtractRawSubtitle(ctx context.Context, videoPath string, streamIndex int) ([]byte, error)
- func ExtractSegmentPCM(ctx context.Context, path string, startMs, durationMs int64) ([]int16, error)
- func NormalizeFFprobeLang(lang string, mapper LangMapper) string
- func ProbeVideoFPS(ctx context.Context, path string) float64
- type LangMapper
- type Track
Constants ¶
const ( CodecASS = "ass" CodecSSA = "ssa" )
Codec name constants for the most commonly referenced subtitle formats.
const MaxExtractBytes = 50 * 1024 * 1024
MaxExtractBytes is the maximum size for ffmpeg stdout reads (subtitle extraction, ASS conversion). Prevents OOM from pathological streams.
const PCMSampleRate = 8000
PCMSampleRate is the sample rate used for PCM audio extraction.
Variables ¶
This section is empty.
Functions ¶
func ExtractRawSubtitle ¶
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.
Types ¶
type LangMapper ¶
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 ¶
ParseProbeOutput parses raw ffprobe JSON output into Track structs.
func ProbeStreams ¶
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.