Giter VIP home page Giter VIP logo

go-matroska's Introduction

Golang implementation of Matroska and WebM media container formats

Build Status Coverage Status Go Report Card GoDoc

Installation

go get github.com/pixelbender/go-matroska/...

Usage

import (
    "os"
    "fmt"
    "github.com/pixelbender/go-matroska/matroska"
)

func main() {
    doc, err := matroska.Decode("example.mkv")
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println(doc.Segment.Info[0].Duration)
}

Specifications

go-matroska's People

Contributors

akyoto avatar pixelbender avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

go-matroska's Issues

Feature for examining audio block content

Thanks for the great work of crafting matroska format parser for golang.
The library is currently used to verify MediaRecorder from our team.
Now, I'm adding test for verifying whether the result mkv from MediaRecorder is muted.
Just curious about whether the library support examining the content of simple block of audio track.
I saw the information parsed from library can identify those audio blocks but the data field here:

//Data []byte

gets comment out.
I wonder if it's for fixing the OOM issue.
In that case, can we try to add lazy loading mechanism like adding offset and size fields of data to block then gets their value from Reader of Block's UnmarshalEBML method. With information of these 2 fields, the user can easily read the data after decoding.

fatal error: runtime: out of memory

it is possible to crash the document parser with an out of memory if io.Reader is corrupt. this is particularly problematic when handling user-supplied data (data streamed a socket for example). a user sending a specially crafted sequence of bytes will crash the go process because because the decoder naively allocates buffers of an arbitrary size:

   182:	}
   183:
   184:	// GetElementContent returns the element's data (if any)
   185:	// Data is present if the element's type is not Master
   186:	func (doc *Document) GetElementContent(el *Element) ([]byte, error) {
=> 187:		buf := make([]byte, el.Size)
   188:
   189:		_, err := io.ReadFull(doc.r, buf)
   190:		if err != nil {
   191:			return nil, err
   192:		}
(dlv) p el.Size
29055659576

The above condition leads to the following crash attempting to allocate 29GB of memory:

fatal error: runtime: out of memory

a simple solution would be to use a fixed buffer and refuse to process an element that is larger than the fixed buffer:

if el.Size > len(self.buffer) {
  return nil, errors.New("invalid size")
}

Error dec.buf.Discard undefined

After install and redme example have error
src/github.com/pixelbender/go-matroska/ebml/decode.go:172: dec.buf.Discard undefined (type *bufio.Reader has no field or method Truncate) src/github.com/pixelbender/go-matroska/ebml/decode.go:197: dec.buf.Discard undefined (type *bufio.Reader has no field or method Truncate) src/github.com/pixelbender/go-matroska/ebml/decode.go:225: dec.buf.Discard undefined (type *bufio.Reader has no field or method Discard) src/github.com/pixelbender/go-matroska/ebml/decode.go:313: dec.buf.Discard undefined (type *bufio.Reader has no field or method Truncate)

go version go1.3.3 linux/arm

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.