bmff

package
v0.0.0-...-2148625 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2023 License: Apache-2.0 Imports: 8 Imported by: 9

Documentation

Overview

Package bmff reads ISO BMFF boxes, as used by HEIF, etc.

This is not so much as a generic BMFF reader as it is a BMFF reader as needed by HEIF, though that may change in time. For now, only boxes necessary for the go4.org/media/heif package have explicit parsers.

This package makes no API compatibility promises; it exists primarily for use by the go4.org/media/heif package.

Index

Constants

This section is empty.

Variables

View Source
var (
	TypeFtyp = BoxType{'f', 't', 'y', 'p'}
	TypeMeta = BoxType{'m', 'e', 't', 'a'}
)

Common box types.

View Source
var ErrUnknownBox = errors.New("heif: unknown box")

ErrUnknownBox is returned by Box.Parse for unrecognized box types.

Functions

This section is empty.

Types

type Box

type Box interface {
	Size() int64 // 0 means unknown (will read to end of file)
	Type() BoxType

	// Parses parses the box, populating the fields
	// in the returned concrete type.
	//
	// If Parse has already been called, Parse returns nil.
	// If the box type is unknown, the returned error is ErrUnknownBox
	// and it's guaranteed that no bytes have been read from the box.
	Parse() (Box, error)

	// Body returns the inner bytes of the box, ignoring the header.
	// The body may start with the 4 byte header of a "Full Box" if the
	// box's type derives from a full box. Most users will use Parse
	// instead.
	// Body will return a new reader at the beginning of the box if the
	// outer box has already been parsed.
	Body() io.Reader
}

Box represents a BMFF box.

type BoxType

type BoxType [4]byte

func (BoxType) EqualString

func (t BoxType) EqualString(s string) bool

func (BoxType) String

func (t BoxType) String() string

type DataInformationBox

type DataInformationBox struct {
	Children []Box
	// contains filtered or unexported fields
}

a "dinf" box

func (DataInformationBox) Body

func (b DataInformationBox) Body() io.Reader

func (DataInformationBox) Parse

func (b DataInformationBox) Parse() (Box, error)

func (DataInformationBox) Size

func (b DataInformationBox) Size() int64

func (DataInformationBox) Type

func (b DataInformationBox) Type() BoxType

type DataReferenceBox

type DataReferenceBox struct {
	FullBox
	EntryCount uint32
	Children   []Box
}

a "dref" box.

func (DataReferenceBox) Body

func (b DataReferenceBox) Body() io.Reader

func (DataReferenceBox) Parse

func (b DataReferenceBox) Parse() (Box, error)

func (DataReferenceBox) Size

func (b DataReferenceBox) Size() int64

func (DataReferenceBox) Type

func (b DataReferenceBox) Type() BoxType

type FileTypeBox

type FileTypeBox struct {
	MajorBrand   string   // 4 bytes
	MinorVersion string   // 4 bytes
	Compatible   []string // all 4 bytes
	// contains filtered or unexported fields
}

func (FileTypeBox) Body

func (b FileTypeBox) Body() io.Reader

func (FileTypeBox) Parse

func (b FileTypeBox) Parse() (Box, error)

func (FileTypeBox) Size

func (b FileTypeBox) Size() int64

func (FileTypeBox) Type

func (b FileTypeBox) Type() BoxType

type FullBox

type FullBox struct {
	Version uint8
	Flags   uint32 // 24 bits
	// contains filtered or unexported fields
}

func (FullBox) Body

func (b FullBox) Body() io.Reader

func (FullBox) Parse

func (b FullBox) Parse() (Box, error)

func (FullBox) Size

func (b FullBox) Size() int64

func (FullBox) Type

func (b FullBox) Type() BoxType

type HandlerBox

type HandlerBox struct {
	FullBox
	HandlerType string // always 4 bytes; usually "pict" for iOS Camera images
	Name        string
}

a "hdlr" box.

func (HandlerBox) Body

func (b HandlerBox) Body() io.Reader

func (HandlerBox) Parse

func (b HandlerBox) Parse() (Box, error)

func (HandlerBox) Size

func (b HandlerBox) Size() int64

func (HandlerBox) Type

func (b HandlerBox) Type() BoxType

type ImageRotation

type ImageRotation struct {
	Angle uint8 // 1 means 90 degrees counter-clockwise, 2 means 180 counter-clockwise
	// contains filtered or unexported fields
}

ImageRotation is a HEIF "irot" rotation property.

func (ImageRotation) Body

func (b ImageRotation) Body() io.Reader

func (ImageRotation) Parse

func (b ImageRotation) Parse() (Box, error)

func (ImageRotation) Size

func (b ImageRotation) Size() int64

func (ImageRotation) Type

func (b ImageRotation) Type() BoxType

type ImageSpatialExtentsProperty

type ImageSpatialExtentsProperty struct {
	FullBox
	ImageWidth  uint32
	ImageHeight uint32
}

func (ImageSpatialExtentsProperty) Body

func (b ImageSpatialExtentsProperty) Body() io.Reader

func (ImageSpatialExtentsProperty) Parse

func (b ImageSpatialExtentsProperty) Parse() (Box, error)

func (ImageSpatialExtentsProperty) Size

func (b ImageSpatialExtentsProperty) Size() int64

func (ImageSpatialExtentsProperty) Type

func (b ImageSpatialExtentsProperty) Type() BoxType

type ItemInfoBox

type ItemInfoBox struct {
	FullBox
	Count     uint16
	ItemInfos []*ItemInfoEntry
}

ItemInfoBox represents an "iinf" box.

func (ItemInfoBox) Body

func (b ItemInfoBox) Body() io.Reader

func (ItemInfoBox) Parse

func (b ItemInfoBox) Parse() (Box, error)

func (ItemInfoBox) Size

func (b ItemInfoBox) Size() int64

func (ItemInfoBox) Type

func (b ItemInfoBox) Type() BoxType

type ItemInfoEntry

type ItemInfoEntry struct {
	FullBox

	ItemID          uint16
	ProtectionIndex uint16
	ItemType        string // always 4 bytes

	Name string

	// If Type == "mime":
	ContentType     string
	ContentEncoding string

	// If Type == "uri ":
	ItemURIType string
}

ItemInfoEntry represents an "infe" box.

TODO: currently only parses Version 2 boxes.

func (ItemInfoEntry) Body

func (b ItemInfoEntry) Body() io.Reader

func (ItemInfoEntry) Parse

func (b ItemInfoEntry) Parse() (Box, error)

func (ItemInfoEntry) Size

func (b ItemInfoEntry) Size() int64

func (ItemInfoEntry) Type

func (b ItemInfoEntry) Type() BoxType

type ItemLocationBox

type ItemLocationBox struct {
	FullBox

	ItemCount uint16
	Items     []ItemLocationBoxEntry
	// contains filtered or unexported fields
}

box "iloc"

func (ItemLocationBox) Body

func (b ItemLocationBox) Body() io.Reader

func (ItemLocationBox) Parse

func (b ItemLocationBox) Parse() (Box, error)

func (ItemLocationBox) Size

func (b ItemLocationBox) Size() int64

func (ItemLocationBox) Type

func (b ItemLocationBox) Type() BoxType

type ItemLocationBoxEntry

type ItemLocationBoxEntry struct {
	ItemID             uint16
	ConstructionMethod uint8 // actually uint4
	DataReferenceIndex uint16
	BaseOffset         uint64 // uint32 or uint64, depending on encoding
	ExtentCount        uint16
	Extents            []OffsetLength
}

not a box

type ItemPropertiesBox

type ItemPropertiesBox struct {
	PropertyContainer *ItemPropertyContainerBox
	Associations      []*ItemPropertyAssociation // at least 1
	// contains filtered or unexported fields
}

HEIF: iprp

func (ItemPropertiesBox) Body

func (b ItemPropertiesBox) Body() io.Reader

func (ItemPropertiesBox) Parse

func (b ItemPropertiesBox) Parse() (Box, error)

func (ItemPropertiesBox) Size

func (b ItemPropertiesBox) Size() int64

func (ItemPropertiesBox) Type

func (b ItemPropertiesBox) Type() BoxType

type ItemProperty

type ItemProperty struct {
	Essential bool
	Index     uint16
}

not a box

type ItemPropertyAssociation

type ItemPropertyAssociation struct {
	FullBox
	EntryCount uint32
	Entries    []ItemPropertyAssociationItem
}

func (ItemPropertyAssociation) Body

func (b ItemPropertyAssociation) Body() io.Reader

func (ItemPropertyAssociation) Parse

func (b ItemPropertyAssociation) Parse() (Box, error)

func (ItemPropertyAssociation) Size

func (b ItemPropertyAssociation) Size() int64

func (ItemPropertyAssociation) Type

func (b ItemPropertyAssociation) Type() BoxType

type ItemPropertyAssociationItem

type ItemPropertyAssociationItem struct {
	ItemID            uint32
	AssociationsCount int            // as declared
	Associations      []ItemProperty // as parsed
}

not a box

type ItemPropertyContainerBox

type ItemPropertyContainerBox struct {
	Properties []Box // of ItemProperty or ItemFullProperty
	// contains filtered or unexported fields
}

HEIF: ipco

func (ItemPropertyContainerBox) Body

func (b ItemPropertyContainerBox) Body() io.Reader

func (ItemPropertyContainerBox) Parse

func (b ItemPropertyContainerBox) Parse() (Box, error)

func (ItemPropertyContainerBox) Size

func (b ItemPropertyContainerBox) Size() int64

func (ItemPropertyContainerBox) Type

func (b ItemPropertyContainerBox) Type() BoxType

type MetaBox

type MetaBox struct {
	FullBox
	Children []Box
}

func (MetaBox) Body

func (b MetaBox) Body() io.Reader

func (MetaBox) Parse

func (b MetaBox) Parse() (Box, error)

func (MetaBox) Size

func (b MetaBox) Size() int64

func (MetaBox) Type

func (b MetaBox) Type() BoxType

type OffsetLength

type OffsetLength struct {
	Offset, Length uint64
}

type PrimaryItemBox

type PrimaryItemBox struct {
	FullBox
	ItemID uint16
}

"pitm" box

func (PrimaryItemBox) Body

func (b PrimaryItemBox) Body() io.Reader

func (PrimaryItemBox) Parse

func (b PrimaryItemBox) Parse() (Box, error)

func (PrimaryItemBox) Size

func (b PrimaryItemBox) Size() int64

func (PrimaryItemBox) Type

func (b PrimaryItemBox) Type() BoxType

type Reader

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

func NewReader

func NewReader(r io.Reader) *Reader

func (*Reader) ReadAndParseBox

func (r *Reader) ReadAndParseBox(typ BoxType) (Box, error)

ReadAndParseBox wraps the ReadBox method, ensuring that the read box is of type typ and parses successfully. It returns the parsed box.

func (*Reader) ReadBox

func (r *Reader) ReadBox() (Box, error)

ReadBox reads the next box.

If the previously read box was not read to completion, ReadBox consumes the rest of its data.

At the end, the error is io.EOF.

Jump to

Keyboard shortcuts

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