transcode

package
v0.0.0-...-e9ec87d Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AudioData

type AudioData struct {
	PCM        []float64       `json:"-"` // Raw PCM data
	SampleRate int             `json:"sample_rate"`
	Channels   int             `json:"channels"`
	Duration   time.Duration   `json:"duration"`
	Timestamp  time.Time       `json:"timestamp"`
	Metadata   *StreamMetadata `json:"metadata,omitempty"`
}

AudioData represents decoded audio data

type AudioMetadata

type AudioMetadata struct {
	SampleRate int     `json:"sample_rate"`
	Channels   int     `json:"channels"`
	Codec      string  `json:"codec"`
	Duration   float64 `json:"duration"`
	Bitrate    int     `json:"bitrate"`
	Format     string  `json:"format"`
}

AudioMetadata holds detected audio properties from FFprobe

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder handles audio decoding using FFmpeg

func NewDecoder

func NewDecoder(config *DecoderConfig) *Decoder

NewDecoder creates a new audio decoder

func NewNormalizingDecoder

func NewNormalizingDecoder(contentType string) *Decoder

func (*Decoder) Close

func (d *Decoder) Close() error

Close cleans up any resources (no-op for FFmpeg decoder)

func (*Decoder) DecodeBytes

func (d *Decoder) DecodeBytes(data []byte) (any, error)

DecodeBytes decodes audio from byte slice Returns AudioData (`any` is for package independence)

func (*Decoder) DecodeFile

func (d *Decoder) DecodeFile(filename string) (*AudioData, error)

DecodeFile decodes an audio file and returns PCM data

func (*Decoder) DecodeReader

func (d *Decoder) DecodeReader(reader io.Reader) (any, error)

DecodeReader decodes audio from an io.Reader Returns `AudioData` (`any` is for package independence)

func (*Decoder) DecodeURL

func (d *Decoder) DecodeURL(url string, duration time.Duration, streamType string) (*AudioData, error)

DecodeURL decodes audio directly from a URL using FFmpeg (for HLS, HTTP streams, etc.)

func (*Decoder) GetConfig

func (d *Decoder) GetConfig() map[string]any

GetConfig returns decoder configuration information

func (*Decoder) GetInfo

func (d *Decoder) GetInfo() map[string]any

GetInfo returns information about the audio decoder (alias for GetConfig)

func (*Decoder) GetSupportedFormats

func (d *Decoder) GetSupportedFormats() []string

GetSupportedFormats returns a list of formats supported by this decoder

func (*Decoder) ProbeURL

func (d *Decoder) ProbeURL(ctx context.Context, url string) (*AudioMetadata, error)

ProbeURL probes a URL to extract audio metadata without decoding the entire stream

func (*Decoder) ValidateConfig

func (d *Decoder) ValidateConfig() error

ValidateConfig validates the decoder configuration

type DecoderConfig

type DecoderConfig struct {
	TargetSampleRate int           `json:"target_sample_rate"`
	TargetChannels   int           `json:"target_channels"`
	OutputFormat     string        `json:"output_format"`
	MaxDuration      time.Duration `json:"max_duration"`
	ResampleQuality  string        `json:"resample_quality"` // "fast", "medium", "high"
	FFmpegPath       string        `json:"ffmpeg_path"`      // Path to ffmpeg binary
	FFprobePath      string        `json:"ffprobe_path"`     // Path to ffprobe binary
	Timeout          time.Duration `json:"timeout"`          // Timeout for ffmpeg operations
	// Normalization options
	EnableNormalization bool    `json:"enable_normalization"`
	NormalizationMethod string  `json:"normalization_method"` // "loudnorm", "dynaudnorm", "compand"
	TargetLUFS          float64 `json:"target_lufs"`          // -23.0 for broadcast, -16.0 for streaming
	TargetPeak          float64 `json:"target_peak"`          // -2.0
	LoudnessRange       float64 `json:"loudness_range"`       // 7.0 typical
}

DecoderConfig holds decoder configuration

func ContentOptimizedDecoderConfig

func ContentOptimizedDecoderConfig(contentType string) *DecoderConfig

ContentOptimizedDecoderConfig returns a decoder configuration based on the content type.

The main difference is in the normalization method:

func DefaultDecoderConfig

func DefaultDecoderConfig() *DecoderConfig

DefaultDecoderConfig returns default decoder configuration

type StreamMetadata

type StreamMetadata struct {
	URL         string            `json:"url"`
	Type        string            `json:"type"`
	Format      string            `json:"format"`
	Bitrate     int               `json:"bitrate,omitempty"`
	SampleRate  int               `json:"sample_rate,omitempty"`
	Channels    int               `json:"channels,omitempty"`
	Codec       string            `json:"codec,omitempty"`
	ContentType string            `json:"content_type,omitempty"`
	Title       string            `json:"title,omitempty"`
	Artist      string            `json:"artist,omitempty"`
	Genre       string            `json:"genre,omitempty"`
	Station     string            `json:"station,omitempty"`
	Headers     map[string]string `json:"headers,omitempty"`
	Timestamp   time.Time         `json:"timestamp"`
}

StreamMetadata represents metadata about the audio stream/file

Jump to

Keyboard shortcuts

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