Giter VIP home page Giter VIP logo

codec's Introduction

codec

Golang aac/h264 encoder and decoder.

H264 encoding example:

w := 400
h := 400
var nal [][]byte 

c, _ := codec.NewH264Encoder(w, h, image.YCbCrSubsampleRatio420)
nal = append(nal, c.Header)

for i := 0; i < 60; i++ {
	img := image.NewYCbCr(image.Rect(0,0,w,h), image.YCbCrSubsampleRatio420)
	p, _ := c.Encode(img)
	if len(p.Data) > 0 {
		nal = append(nal, p.Data)
	}
}
for {
	// flush encoder
	p, err := c.Encode(nil)
	if err != nil {
		break
	}
	nal = append(nal, p.Data)
}

H264 decoding example:

dec, err := codec.NewH264Decoder(nal[0])
for i, n := range nal[1:] {
	img, err := dec.Decode(n)
	if err == nil {
		fp, _ := os.Create(fmt.Sprintf("/tmp/dec-%d.jpg", i))
		jpeg.Encode(fp, img, nil)
		fp.Close()
	}
}

AAC encoding example:

var pkts [][]byte 

c, _ := codec.NewAACEncoder()
pkts = append(pkts, c.Header)

for i := 0; i < 60; i++ {
	var sample [8192]byte
	p, _ := c.Encode(sample)
	if len(p) > 0 {
		pkts = append(pkts, p)
	}
}

AAC decoding example:

dec, _ := codec.NewAACDecoder(pkts[0])
for _, p := range pkts[1:] {
	sample, err := dec.Decode(p)
}

codec's People

Contributors

attilaolah avatar cfanfrank 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.