Documentation
¶
Overview ¶
Package mpeg returns information about MPEG (and specifically MP3) audio files.
Index ¶
- Constants
- func ComputeAudioSHA1(f *os.File, fi os.FileInfo, headerLen, footerLen int64) (string, error)
- func GetID3v2TextFrame(gen taglib.GenericTag, id string) (string, error)
- func GetID3v2UniqueFileIdentifiers(gen taglib.GenericTag) (map[string]string, error)
- type EncodingMethod
- type FrameInfo
- type ID3v1Tag
- type Time
- type TimeType
- type VBRHeaderID
- type VBRInfo
Constants ¶
const ID3v1Length = 128
ID3v1Length is the length in bytes of an ID3v1 tag.
Variables ¶
This section is empty.
Functions ¶
func ComputeAudioSHA1 ¶
ComputeAudioSHA1 returns a SHA1 hash of the audio (i.e. non-metadata) portion of f.
func GetID3v2TextFrame ¶
func GetID3v2TextFrame(gen taglib.GenericTag, id string) (string, error)
GetID3v2TextFrame returns the first ID3v2 text frame with the supplied ID from gen. If the frame isn't present, an empty string and nil error are returned.
The taglib library has built-in support for some frames ("TPE1", "TIT2", "TALB", etc.) and provides generic support for custom "TXXX" frames, but it doesn't seem to provide an easy way to read other well-known frames like "TPE2".
func GetID3v2UniqueFileIdentifiers ¶
func GetID3v2UniqueFileIdentifiers(gen taglib.GenericTag) (map[string]string, error)
GetID3v2UniqueFileIdentifiers returns unique file IDs from gen keyed by URLs of database owners, e.g. "http://musicbrainz.org". Errors are ignored.
Types ¶
type EncodingMethod ¶
type EncodingMethod int
EncodingMethod describes the encoding method used for the file.
const ( UnknownMethod EncodingMethod = 0 CBR EncodingMethod = 1 ABR EncodingMethod = 2 VBR1 EncodingMethod = 3 // Lame: VBR old / VBR RH VBR2 EncodingMethod = 4 // Lame: VBR MTRH VBR3 EncodingMethod = 5 // LAME: VBR MT VBR4 EncodingMethod = 6 CBR2Pass EncodingMethod = 8 ABR2Pass EncodingMethod = 9 )
func (EncodingMethod) String ¶
func (m EncodingMethod) String() string
type FrameInfo ¶
type FrameInfo struct { KbitRate int // in 1000 bits per second (not 1024) SampleRate int // in hertz SamplesPerFrame int ChannelMode uint8 // 0x0 stereo, 0x1 joint stereo, 0x2 dual channel, 0x3 single channel HasCRC bool // 16-bit CRC follows header HasPadding bool // frame is padded with one extra bit }
FrameInfo contains information about an MPEG (MP3?) audio frame header.
func ReadFrameInfo ¶
ReadFrameInfo reads an MPEG audio frame header at the specified offset in f. Format details at http://www.codeproject.com/Articles/8295/MPEG-Audio-Frame-Header.
type ID3v1Tag ¶
ID3v1Tag contains information from an ID3v1 footer at the end of an MP3 file. ID3v1 is a terrible format: https://id3.org/ID3v1
type Time ¶
type Time struct {
// contains filtered or unexported fields
}
Time contains a UTC timestamp (including date) read from an MP3 ID3v2 tag. Individual components of the timestamp may be unset.
func GetID3v2Time ¶
func GetID3v2Time(tag taglib.GenericTag, typ TimeType) (Time, error)
GetID3v2Time returns the requested timestamp from tag. ID3 v2.4 frames are preferred before falling back to v2.3 frames. If the requested timestamp time is not set, an empty time is returned. A non-nil error is only returned if an error was encountered while reading the tag.
func ParseID3v23Time ¶
ParseID3v23Time parses the supplied ID3 v2.3 timestamp as split across YYYY, DDMM, and HHMM strings. See "4.2.1. Text information frames - details" in https://id3.org/id3v2.3.0. Empty or invalid strings are omitted from the returned Time object. If none of the strings can be parsed, an empty Time is returned.
func ParseID3v24Time ¶
ParseID3v24Time parses the supplied ID3 v2.4 variable-precision timestamp, e.g. "2021", "2021-04-10", or "2021-04-10T15:06:47". See "4. ID3v2 frame overview" in https://id3.org/id3v2.4.0-structure. If the timestamp is empty or invalid, an empty Time object is returned.
type VBRHeaderID ¶
type VBRHeaderID string
VBRHeaderID describes the type of header used to fill a VBRInfo.
const ( // XingID typically indicates a VBR or ABR stream. XingID VBRHeaderID = "Xing" // InfoID typically indicates a CBR stream. InfoID VBRHeaderID = "Info" )
type VBRInfo ¶
type VBRInfo struct { // ID contains the ID from the beginning of the header. ID VBRHeaderID // Frames contains the number of audio frames in the file. Frames uint32 // Bytes contains the number of bytes of audio data in the file. Bytes uint32 // Quality contains a poorly-defined quality indicator in the range [0, 100]. Quality int // Encoder describes the encoder version, e.g. "LAME3.90a". Encoder string // Method describes how the audio was encoded. Method EncodingMethod }
VBRInfo contains information from an Xing (or Info) header in the first frame. See https://www.codeproject.com/Articles/8295/MPEG-Audio-Frame-Header#XINGHeader.
func ComputeAudioDuration ¶
func ComputeAudioDuration(f *os.File, fi os.FileInfo, headerLen, footerLen int64) (time.Duration, *VBRInfo, error)
ComputeAudioDuration reads an Xing header from the frame at headerLen in f to return the audio length. If no Xing header is present, it assumes that the file has a constant bitrate and returns a nil VBRInfo struct. Only supports MPEG Audio 1, Layer 3. TODO: Consider adding support for VBRI headers, apparently only written by the Fraunhofer encoder: https://www.codeproject.com/Articles/8295/MPEG-Audio-Frame-Header#VBRIHeader