Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeFrame(r io.Reader) (frame []byte, err error)
- type AudioApplication
- type DCAMetadata
- type DCAToolMetadata
- type Decoder
- type EncodeOptions
- type EncodeSession
- func (e *EncodeSession) Cleanup()
- func (e *EncodeSession) Error() error
- func (e *EncodeSession) FFMPEGMessages() string
- func (e *EncodeSession) FrameDuration() time.Duration
- func (e *EncodeSession) Options() *EncodeOptions
- func (e *EncodeSession) OpusFrame() (frame []byte, err error)
- func (e *EncodeSession) Read(p []byte) (n int, err error)
- func (e *EncodeSession) ReadFrame() (frame []byte, err error)
- func (e *EncodeSession) Running() (running bool)
- func (e *EncodeSession) Stats() *EncodeStats
- func (e *EncodeSession) Stop() error
- func (e *EncodeSession) Truncate()
- type EncodeStats
- type ExtraMetadata
- type FFprobeFormat
- type FFprobeMetadata
- type FFprobeTags
- type Frame
- type Metadata
- type OpusMetadata
- type OpusReader
- type OriginMetadata
- type SongMetadata
Constants ¶
const ( // The current version of the DCA format FormatVersion int8 = 1 // The current version of the DCA program LibraryVersion string = "0.0.5" // The URL to the GitHub repository of DCA GitHubRepositoryURL string = "https://github.com/jonas747/dca" )
Define constants
Variables ¶
var ( ErrNotDCA = errors.New("DCA Magic header not found, either not dca or raw dca frames") ErrNotFirstFrame = errors.New("Metadata can only be found in the first frame") )
var (
ErrBadFrame = errors.New("Bad Frame")
)
var (
ErrNegativeFrameSize = errors.New("Frame size is negative, possibly corrupted.")
)
var Logger *log.Logger
var StdEncodeOptions = &EncodeOptions{ Volume: 256, Channels: 2, FrameRate: 48000, FrameDuration: 20, Bitrate: 64, Application: AudioApplicationAudio, CompressionLevel: 10, PacketLoss: 1, BufferedFrames: 100, VBR: true, StartTime: 0, }
StdEncodeOptions is the standard options for encoding
Functions ¶
Types ¶
type AudioApplication ¶
type AudioApplication string
AudioApplication is an application profile for opus encoding
var ( AudioApplicationVoip AudioApplication = "voip" // Favor improved speech intelligibility. AudioApplicationAudio AudioApplication = "audio" // Favor faithfulness to the input AudioApplicationLowDelay AudioApplication = "lowdelay" // Restrict to only the lowest delay modes. )
type DCAMetadata ¶
type DCAMetadata struct { Version int8 `json:"version"` Tool *DCAToolMetadata `json:"tool"` }
DCA metadata struct
Contains the DCA version.
type DCAToolMetadata ¶
type DCAToolMetadata struct { Name string `json:"name"` Version string `json:"version"` Url string `json:"url"` Author string `json:"author"` }
DCA tool metadata struct
Contains the Git revisions, commit author etc.
type Decoder ¶
type Decoder struct { Metadata *Metadata FormatVersion int // contains filtered or unexported fields }
func (*Decoder) FrameDuration ¶
FrameDuration implements OpusReader, returnining the specified duration per frame
func (*Decoder) OpusFrame ¶
OpusFrame returns the next audio frame If this is the first frame it will also check for metadata in it
func (*Decoder) ReadMetadata ¶
ReadMetadata reads the first metadata frame OpusFrame will call this automatically if
type EncodeOptions ¶
type EncodeOptions struct { Volume int // change audio volume (256=normal) Channels int // audio channels FrameRate int // audio sampling rate (ex 48000) FrameDuration int // audio frame duration can be 20, 40, or 60 (ms) Bitrate int // audio encoding bitrate in kb/s can be 8 - 128 PacketLoss int // expected packet loss percentage RawOutput bool // Raw opus output (no metadata or magic bytes) Application AudioApplication // Audio application CoverFormat string // Format the cover art will be encoded with (ex "jpeg) CompressionLevel int // Compression level, higher is better qualiy but slower encoding (0 - 10) BufferedFrames int // How big the frame buffer should be VBR bool // Wether vbr is used or not (variable bitrate) Threads int // Number of threads to use, 0 for auto StartTime int // Start Time of the input stream in seconds // The ffmpeg audio filters to use, see https://ffmpeg.org/ffmpeg-filters.html#Audio-Filters for more info // Leave empty to use no filters. AudioFilter string Comment string // Leave a comment in the metadata }
EncodeOptions is a set of options for encoding dca
func (EncodeOptions) PCMFrameLen ¶
func (e EncodeOptions) PCMFrameLen() int
func (*EncodeOptions) Validate ¶
func (opts *EncodeOptions) Validate() error
Validate returns an error if the options are not correct
type EncodeSession ¶
func EncodeFile ¶
func EncodeFile(path string, options *EncodeOptions) (session *EncodeSession, err error)
EncodeFile encodes the file/url/other in path
func EncodeMem ¶
func EncodeMem(r io.Reader, options *EncodeOptions) (session *EncodeSession, err error)
EncodedMem encodes data from memory
func (*EncodeSession) Cleanup ¶
func (e *EncodeSession) Cleanup()
Cleanup cleans up the encoding session, throwring away all unread frames and stopping ffmpeg ensuring that no ffmpeg processes starts piling up on your system You should always call this after it's done
func (*EncodeSession) Error ¶
func (e *EncodeSession) Error() error
Error returns any error that occured during the encoding process
func (*EncodeSession) FFMPEGMessages ¶
func (e *EncodeSession) FFMPEGMessages() string
FFMPEGMessages returns messages printed by ffmpeg to stderr, you can use this to see what ffmpeg is saying if your encoding fails
func (*EncodeSession) FrameDuration ¶
func (e *EncodeSession) FrameDuration() time.Duration
FrameDuration implements OpusReader, retruning the duratio of each frame
func (*EncodeSession) Options ¶
func (e *EncodeSession) Options() *EncodeOptions
Options returns the options used
func (*EncodeSession) OpusFrame ¶
func (e *EncodeSession) OpusFrame() (frame []byte, err error)
OpusFrame implements OpusReader, returning the next opus frame
func (*EncodeSession) Read ¶
func (e *EncodeSession) Read(p []byte) (n int, err error)
Read implements io.Reader, n == len(p) if err == nil, otherwise n contains the number bytes read before an error occured
func (*EncodeSession) ReadFrame ¶
func (e *EncodeSession) ReadFrame() (frame []byte, err error)
ReadFrame blocks until a frame is read or there are no more frames Note: If rawoutput is not set, the first frame will be a metadata frame
func (*EncodeSession) Running ¶
func (e *EncodeSession) Running() (running bool)
Running returns true if running
func (*EncodeSession) Stats ¶
func (e *EncodeSession) Stats() *EncodeStats
Stats returns ffmpeg stats, NOTE: this is not playback stats but transcode stats. To get how far into playback you are you have to track the number of frames sent to discord youself
func (*EncodeSession) Truncate ¶
func (e *EncodeSession) Truncate()
Truncate is deprecated, use Cleanup instead this will be removed in a future version
type EncodeStats ¶
EncodeStats is transcode stats reported by ffmpeg
type FFprobeFormat ¶
type FFprobeFormat struct { FileName string `json:"filename"` NumStreams int `json:"nb_streams"` NumPrograms int `json:"nb_programs"` FormatName string `json:"format_name"` FormatLongName string `json:"format_long_name"` StartTime string `json:"start_time"` Duration string `json:"duration"` Size string `json:"size"` Bitrate string `json:"bit_rate"` ProbeScore int `json:"probe_score"` Tags *FFprobeTags `json:"tags"` }
type FFprobeMetadata ¶
type FFprobeMetadata struct {
Format *FFprobeFormat `json:"format"`
}
type FFprobeTags ¶
type Metadata ¶
type Metadata struct { Dca *DCAMetadata `json:"dca"` Opus *OpusMetadata `json:"opus"` SongInfo *SongMetadata `json:"info"` Origin *OriginMetadata `json:"origin"` Extra *ExtraMetadata `json:"extra"` }
Base metadata struct
https://github.com/bwmarrin/dca/issues/5#issuecomment-189713886
type OpusMetadata ¶
type OpusMetadata struct { Bitrate int `json:"abr"` SampleRate int `json:"sample_rate"` Application string `json:"mode"` FrameSize int `json:"frame_size"` Channels int `json:"channels"` VBR bool `json:"vbr"` }
Opus metadata struct
Contains information about how the file was encoded with Opus.
type OpusReader ¶
type OriginMetadata ¶
type OriginMetadata struct { Source string `json:"source"` Bitrate int `json:"abr"` Channels int `json:"channels"` Encoding string `json:"encoding"` Url string `json:"url"` }
Origin information metadata struct
Contains information about where the song came from, audio bitrate, channels and original encoding.
type SongMetadata ¶
type SongMetadata struct { Title string `json:"title"` Artist string `json:"artist"` Album string `json:"album"` Genre string `json:"genre"` Comments string `json:"comments"` Cover *string `json:"cover"` }
Song Information metadata struct
Contains information about the song that was encoded.