diff --git a/README.md b/README.md index 8fd328f..c59ae68 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Duration() float64 FPS() float64 Codec() string AudioCodec() string +PixFmt() string FrameBuffer() []byte SetFrameBuffer(buffer []byte) diff --git a/imageio.go b/imageio.go index d7ceccd..cbe7d5c 100644 --- a/imageio.go +++ b/imageio.go @@ -19,12 +19,17 @@ func Read(filename string) (int, int, []byte, error) { return 0, 0, nil, err } defer f.Close() + image, _, err := image.Decode(f) if err != nil { return 0, 0, nil, err } + bounds := image.Bounds().Max - data := make([]byte, bounds.Y*bounds.X*3) + size := bounds.X * bounds.Y * 3 + + data := make([]byte, size) + index := 0 for h := 0; h < bounds.Y; h++ { for w := 0; w < bounds.X; w++ { @@ -57,6 +62,7 @@ func Write(filename string, width, height int, data []byte) error { index += 3 } } + if strings.HasSuffix(filename, ".png") { if err := png.Encode(f, image); err != nil { return err diff --git a/video.go b/video.go index ab2a5ed..dd07657 100644 --- a/video.go +++ b/video.go @@ -69,6 +69,10 @@ func (video *Video) AudioCodec() string { return video.audioCodec } +func (video *Video) PixFmt() string { + return video.pixfmt +} + func (video *Video) FrameBuffer() []byte { return video.framebuffer }