mpeg4

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

mpeg4

Status Go Reference

MPEG-4 Part 2 video decoder in pure Go (DivX, Xvid, H.263), with an AVI demuxer. No CGo, no dependencies.

Usage

Decode a raw MPEG-4 stream:

d := mpeg4.NewDecoder("")

pics, err := d.Decode(data)
...

pics = d.Flush()

Decode the video track of an AVI file:

f, err := avi.Open(r, size)
v, err := mpeg4.NewVideo(f.Video(), f.Video().Handler)

for {
    pic, pts, err := v.Next()
    ...
}

Pictures come back in display order and stay valid until the next Decode or Next. NewVideo takes any track that implements mpeg4.Samples.

Supported

  • Simple and Advanced Simple profiles, and baseline H.263
  • I, P and B-VOPs, quarter sample motion, GMC and interlaced video
  • Data partitioning, RVLC and video packets
  • DivX packed bitstreams
  • AVI, including OpenDML

License

MIT, see LICENSE. The decoder is a port of OxideAV. This software is based in part on the work of the Independent JPEG Group.

The MPEG-4 Visual patents have expired; the last one in the licensing pool ran out in July 2026.

Documentation

Overview

Package mpeg4 implements an MPEG-4 Part 2 Visual decoder.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalid reports malformed data.
	ErrInvalid = errors.New("mpeg4: invalid data")
	// ErrUnsupported reports a well-formed stream that uses a tool this package does not decode.
	ErrUnsupported = errors.New("mpeg4: unsupported")
)

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder decodes an MPEG-4 Part 2 Visual elementary stream.

func NewDecoder

func NewDecoder(fourcc string) *Decoder

NewDecoder returns a decoder; fourcc is the container's codec tag, or empty.

func (*Decoder) Decode

func (d *Decoder) Decode(data []byte) ([]*Picture, error)

Decode decodes the headers and VOPs in data and returns the pictures it completes.

func (*Decoder) Flush

func (d *Decoder) Flush() []*Picture

Flush returns the picture held back for reordering, if any.

type Picture

type Picture struct {
	// Width and Height are the displayed size.
	Width, Height int

	Y, Cb, Cr        []uint8
	StrideY, StrideC int

	// SARWidth and SARHeight are the pixel aspect ratio, 0 when unknown.
	SARWidth, SARHeight int
}

Picture is a decoded picture in 8-bit 4:2:0.

type Samples

type Samples interface {
	Len() int
	SampleTime(i int) (pts time.Duration, key bool)
	SampleData(i int, buf []byte) (data, config []byte, err error)
}

Samples is a track of MPEG-4 Visual samples, as a container indexes it.

type Video

type Video struct {
	// Decoder decodes the samples.
	Decoder *Decoder
	// contains filtered or unexported fields
}

Video decodes a track of samples into pictures in display order.

func NewVideo

func NewVideo(s Samples, fourcc string) (*Video, error)

NewVideo prepares s for decoding; fourcc is the container's codec tag, or empty.

func (*Video) Next

func (v *Video) Next() (*Picture, time.Duration, error)

Next is the next picture and its presentation time; io.EOF after the last.

func (*Video) Seek

func (v *Video) Seek(t time.Duration) error

Seek makes Next continue with the first picture at or after t.

Directories

Path Synopsis
Package avi reads RIFF AVI files, including OpenDML files larger than 1 GB.
Package avi reads RIFF AVI files, including OpenDML files larger than 1 GB.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL