Skip to content

Binozo/go-opusfile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-opusfile

Go bindings for opusfile. With this library you can decode opus files (including seeking support).

Requirements

CGO needs to be enabled (CGO_ENABLED=1 go build ...).

Also you need to install opusfile headers for compiling (apt install libopusfile-dev) and the libopusfile shared library needs to be installed on your system for executing your program (apt install libopusfile0).

Install

$ go get -u github.com/binozo/go-opusfile

Example

cli.go:

package main

import (
	"flag"
	"fmt"
	"log"
	"os"
	"path/filepath"

	"github.com/binozo/go-opusfile"
)

func main() {
	var filePath string
	flag.StringVar(&filePath, "f", "file.opus", "filepath to opus file")
	flag.Parse()

	musicFile, err := os.Open(filePath)
	if err != nil {
		log.Fatalf("Failed to open file: %s\n", err.Error())
	}
	defer musicFile.Close()

	opusFile, err := opusfile.Open(musicFile)
	if err != nil {
		log.Fatalf("Failed to open opus on file: %s\n", err.Error())
	}
	defer opusFile.Close()

	opusHead := opusFile.Head()
	fmt.Printf("File '%s':\n", filepath.Base(filePath))
	fmt.Printf("Opus version: %d\n", opusHead.Version)
	fmt.Printf("Channel count: %d\n", opusFile.ChannelCount())
	fmt.Printf("Total length: %d pcm samples\n", opusFile.PCMTotal())
	fmt.Printf("Link count: %d\n", opusFile.LinkCount())
	fmt.Printf("Current link serial no: %d\n", opusFile.SerialNo())
	fmt.Printf("Tags: %v\n", opusFile.Tags())
}