avi

package
v0.2.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: 5 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.

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalid reports a malformed file.
	ErrInvalid = errors.New("avi: invalid data")
	// ErrUnsupported reports a well-formed file this package does not read.
	ErrUnsupported = errors.New("avi: unsupported")
)

Functions

This section is empty.

Types

type BitmapInfo

type BitmapInfo struct {
	Width, Height int
	BitCount      int

	// Compression is the four-character code of the codec.
	Compression string

	// Extra is the codec data after the header, such as an MPEG-4 VOL.
	Extra []byte
}

BitmapInfo is the format of a video stream.

func ParseBitmapInfo

func ParseBitmapInfo(b []byte) (*BitmapInfo, error)

ParseBitmapInfo parses a BITMAPINFOHEADER, such as a Matroska VfW codec private.

type File

type File struct {
	// MicroSecPerFrame, Flags, Width and Height are from the main header.
	MicroSecPerFrame uint32
	Flags            uint32
	Width, Height    int

	// TotalFrames is the OpenDML frame count when present, else the main header's.
	TotalFrames uint32

	Streams []*Stream
	// contains filtered or unexported fields
}

File is an opened AVI file.

func Open

func Open(r io.ReaderAt, size int64) (*File, error)

Open indexes the file r of size bytes.

func (*File) Audio

func (f *File) Audio() *Stream

Audio is the first audio stream, or nil.

func (*File) Video

func (f *File) Video() *Stream

Video is the first video stream, or nil.

type Sample

type Sample struct {
	// Data is nil when the sample was looked up by [Stream.Info].
	Data []byte

	// Ticks is the sample's start in the stream's Scale/Rate units, Start included.
	Ticks int64

	// Key reports a keyframe; every chunk is key when the file has no index.
	Key bool

	// Offset and Size locate the chunk data in the file.
	Offset int64
	Size   int
}

Sample is one chunk of a stream.

type Stream

type Stream struct {
	// Type is "vids", "auds", "txts" or "mids", and Handler the stream header's codec code.
	Type, Handler string

	// Scale, Rate, Start, Length and SampleSize are from the stream header; Rate/Scale is ticks per second.
	Scale, Rate   uint32
	Start, Length uint32
	SampleSize    uint32

	// Name is the stream name, empty when there is none.
	Name string

	// Video is set for a video stream, Audio for an audio stream.
	Video *BitmapInfo
	Audio *WaveFormat

	// AspectX and AspectY are the display aspect from the OpenDML video properties, 0 when absent.
	AspectX, AspectY int
	// contains filtered or unexported fields
}

Stream is one stream of a file and the index of its chunks.

func (*Stream) Info

func (s *Stream) Info(i int) Sample

Info is sample i without its data. It panics unless 0 <= i < Len.

func (*Stream) Len

func (s *Stream) Len() int

Len is the number of samples in the stream, 0 for a nil stream.

func (*Stream) ReadSample

func (s *Stream) ReadSample(i int, buf []byte) (Sample, error)

ReadSample is sample i, its data read into buf when buf is large enough.

func (*Stream) Sample

func (s *Stream) Sample(i int) (Sample, error)

Sample is sample i with its data.

func (*Stream) SampleData

func (s *Stream) SampleData(i int, buf []byte) (data, config []byte, err error)

SampleData is the data of sample i, read into buf when it fits, and the codec data of the stream.

func (*Stream) SampleTime

func (s *Stream) SampleTime(i int) (time.Duration, bool)

SampleTime is the presentation time of sample i and whether it is a keyframe.

func (*Stream) Samples

func (s *Stream) Samples() iter.Seq2[Sample, error]

Samples yields every sample of the stream in file order.

func (*Stream) Time

func (s *Stream) Time(ticks int64) time.Duration

Time converts ticks of the stream to a duration.

type WaveFormat

type WaveFormat struct {
	// Tag is the format tag, taken from the subformat for WAVEFORMATEXTENSIBLE.
	Tag uint16

	Channels       int
	SampleRate     int
	AvgBytesPerSec int
	BlockAlign     int
	BitsPerSample  int

	// Extra is the data after the cbSize field.
	Extra []byte
}

WaveFormat is the format of an audio stream.

func ParseWaveFormat

func ParseWaveFormat(b []byte) (*WaveFormat, error)

ParseWaveFormat parses a WAVEFORMATEX, such as a Matroska ACM codec private.

Jump to

Keyboard shortcuts

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