GithubHelp home page GithubHelp logo

go-flac's Introduction

go-flac

Documentation Build Status Coverage Status

go library for manipulating FLAC metadata

Introduction

A FLAC(Free Lossless Audio Codec) stream generally consists of 3 parts: a "fLaC" header to mark the stream as an FLAC stream, followed by one or more metadata blocks which stores metadata and information regarding the stream, followed by one or more audio frames. This package encapsulated the operations that extract and split FLAC metadata blocks from a FLAC stream file and assembles them back after modification. this package only implemented parsing the essential StreamInfo metadata block by File#GetStreamInfo, other metadata block operations should be provided by other packages.

Usage

go-flac provided three APIs for reading FLAC files and returns a File struct:

  • ParseBytes for consuming a whole FLAC stream from an io.Reader.
  • ParseFile for consuming a whole FLAC stream from a file.
  • ParseMetadata for consuming only metadata from am io.Reader.

The File struct has two exported fields, Meta and Frames, the Frames consisted of raw stream data and the Meta field was a slice of all MetaDataBlocks present in the file. Other packages could parse/construct a MetadataBlock by inspecting its Type field and apply proper decoding/encoding on the Data field of the MetadataBlock. You can modify the elements in the Meta field of a File as you like, as long as the StreamInfo metadata block is the first element in Meta field, according to the specs of FLAC format.

Examples

The following example extracts the sample rate of a FLAC file.

package example

import (
    "github.com/go-flac/go-flac"
)

func getSampleRate(fileName string) int {
	f, err := flac.ParseFile(fileName)
	if err != nil {
		panic(err)
	}
	data, err := f.GetStreamInfo()
	if err != nil {
		panic(err)
	}
	return data.SampleRate
}

The following example adds a jpeg image as front cover to the FLAC metadata using flacpicture.

package example

import (
    "github.com/go-flac/flacpicture"
    "github.com/go-flac/go-flac"
)

func addFLACCover(fileName string, imgData []byte) {
	f, err := flac.ParseFile(fileName)
	if err != nil {
		panic(err)
	}
	picture, err := flacpicture.NewFromImageData(flacpicture.PictureTypeFrontCover, "Front cover", imgData, "image/jpeg")
	if err != nil {
		panic(err)
	}
	picturemeta := picture.Marshal()
	f.Meta = append(f.Meta, &picturemeta)
	f.Save(fileName)
}

go-flac's People

Contributors

eternal-flame-ad avatar timoknapp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.