Go bindings for opusfile. With this library you can decode opus files (including seeking support).
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).
$ go get -u github.com/binozo/go-opusfilepackage 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())
}