bmff

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 29, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package bmff reads ISOBMFF boxes, as used by HEIF, AVIF, CR3, etc. and other riff based files

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBrandNotSupported = errors.New("error brand not supported")
	ErrWrongBoxType      = errors.New("error wrong box type")
	ErrNoMoreBoxes       = errors.New("no more boxes to be parsed")
)

Common Errors

View Source
var (
	ErrBufLength                = errors.New("insufficient buffer length")
	ErrItemTypeWS               = errors.New("bufReader error: itemType doesn't end on whitespace")
	ErrRemainLengthInsufficient = errors.New("bufReader error: remain length insufficient")
	ErrBufReaderFlags           = errors.New("bufReader error: failed to read 4 bytes of Flags")
	ErrItemTypeLength           = errors.New("bufReader: insufficient itemType Length")
)

Errors

View Source
var (

	// CR3MetaBoxUUID is the uuid that corresponds with Canon CR3 Metadata.
	CR3MetaBoxUUID = meta.UUIDFromString("85c0b687-820f-11e0-8111-f4ce462b6a48")

	// CR3XPacketUUID is the uuid that corresponds with Canon CR3 xpacket data
	CR3XPacketUUID = meta.UUIDFromString("be7acfcb-97a9-42e8-9c71-999491e3afac")

	// CR3PreviewDataUUID is the uuid that corresponds with Canon CR3 Perview Data
	CR3PreviewDataUUID = meta.UUIDFromString("eaf42b5e-1c98-4b88-b9fb-b7dc406e4d16")

	// CR3CMTAUUID is the uuid that corresponds with Canon CR3 CMTA box
	CR3CMTAUUID = meta.UUIDFromString("5766b829-bb6a-47c5-bcfb-8b9f2260d06d")

	// CR3CNOPUUID is the uuid that corresponds with Canon CR3 CNOP "Optional data"
	CR3CNOPUUID = meta.UUIDFromString("210f1687-9149-11e4-8111-00242131fce4")
)
View Source
var (

	// ErrItemNotFound is returned as en error when an Item was not Found.
	ErrItemNotFound = errors.New("item not found")

	// ErrInfeVersionNotSupported is returned when an infe box with an unsupported was found.
	ErrInfeVersionNotSupported = errors.New("infe box version not supported")
)
View Source
var (
	ItemTypeInfe    = itemType([]byte("infe"))
	ItemTypeMime    = itemType([]byte("mime"))
	ItemTypeURI     = itemType([]byte("uri "))
	ItemTypeAv01    = itemType([]byte("av01"))
	ItemTypeHvc1    = itemType([]byte("hvc1"))
	ItemTypeGrid    = itemType([]byte("grid"))
	ItemTypeExif    = itemType([]byte("Exif"))
	ItemTypeUnknown = itemType([]byte{0, 0, 0, 0})
)

Common ItemTypes

View Source
var MinorVersionNul = [4]byte{}

Functions

func DebugLogger

func DebugLogger(logger Logger)

DebugLogger sets the debug logger TODO: rewrite

Types

type Box

type Box interface {
	Type() BoxType
}

Box is an interface for different BMFF boxes.

type BoxType

type BoxType uint8

BoxType is an ISOBMFF box

const (
	TypeUnknown BoxType = iota
	TypeAuxC            // 'auxC'
	TypeAuxl            // 'auxl'
	TypeAv01            // 'av01'
	TypeAv1C            // 'av1C'
	TypeAvcC            // 'avcC'
	TypeCCDT            // 'CCDT'
	TypeCCTP            // 'CCTP'
	TypeCdsc            // 'cdsc'
	TypeClap            // 'clap'
	TypeCMT1            // 'CMT1'
	TypeCMT2            // 'CMT2'
	TypeCMT3            // 'CMT3'
	TypeCMT4            // 'CMT4'
	TypeCNCV            // 'CNCV'
	TypeCo64            // 'co64'
	TypeColr            // 'colr'
	TypeCRAW            // 'CRAW'
	TypeCrtt            // 'crtt'
	TypeCTBO            // 'CTBO'
	TypeCTMD            // 'CTMD'
	TypeDimg            // 'dimg'
	TypeDinf            // 'dinf'
	TypeDref            // 'dref'
	TypeEtyp            // 'etyp'
	TypeFree            // 'free'
	TypeFtyp            // 'ftyp'
	TypeGrpl            // 'grpl'
	TypeHdlr            // 'hdlr'
	TypeHvcC            // 'hvcC'
	TypeIdat            // 'idat'
	TypeIinf            // 'iinf'
	TypeIloc            // 'iloc'
	TypeImir            // 'imir'
	TypeInfe            // 'infe'
	TypeIovl            // 'iovl'
	TypeIpco            // 'ipco
	TypeIpma            // 'ipma'
	TypeIprp            // 'iprp'
	TypeIref            // 'iref'
	TypeIrot            // 'irot'
	TypeIspe            // 'ispe'
	TypeLhvC            // 'lhvC'
	TypeMdat            // 'mdat'
	TypeMdft            // 'mdft'
	TypeMdhd            // 'mdhd'
	TypeMdia            // 'mdia'
	TypeMeta            // 'meta'
	TypeMinf            // 'minf'
	TypeMoov            // 'moov'
	TypeMvhd            // 'mvhd'
	TypeNmhd            // 'nmhd'
	TypeOinf            // 'oinf'
	TypePasp            // 'pasp'
	TypePitm            // 'pitm'
	TypePixi            // 'pixi'
	TypePRVW            // 'PRVW'
	TypeStbl            // 'stbl'
	TypeStsc            // 'stsc'
	TypeStsd            // 'stsd'
	TypeStsz            // 'stsz'
	TypeStts            // 'stts'
	TypeThmb            // 'thmb'
	TypeTHMB            // 'THMB'
	TypeTkhd            // 'tkhd'
	TypeTols            // 'tols'
	TypeTrak            // 'trak'
	TypeUUID            // 'uuid'
	TypeVmhd            // 'vmhd'
)

Common box types.

func (BoxType) String

func (t BoxType) String() string

type Brand

type Brand uint8

Brand of ISOBMFF ftyp

func (Brand) String

func (b Brand) String() string

type CNCVBox

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

CNCVBox is Canon Compressor Version box CaNon Codec Version?

func (CNCVBox) String

func (cncv CNCVBox) String() string

type CR3MetaBox

type CR3MetaBox struct {
	//CCTP CCTPBox
	//THMB THMBBox
	CNCV CNCVBox
	CTBO CTBOBox
	Exif [4]meta.ExifHeader
}

CR3MetaBox is a uuidBox that contains Metadata for CR3 files

func (CR3MetaBox) XPacketData

func (cr3 CR3MetaBox) XPacketData() (offset, length uint32, err error)

XPacketData returns CTBO[0] which corresponds to XPacket data First 24 bytes are a UUID box. uuid = be7acfcb-97a9-42e8-9c71-999491e3afac

type CR3Trak

type CR3Trak struct {
	Width, Height     uint16
	Depth, ImageType  uint16
	ImageSize, Offset uint32
}

CR3Trak is a Canon CR3 Trak box

func ParseCrxTrak

func ParseCrxTrak(trak *box) (t CR3Trak, err error)

type CTBOBox

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

CTBOBox is a Canon tracks base offsets Box?

func (CTBOBox) String

func (ctbo CTBOBox) String() string

type CrxMoovBox

type CrxMoovBox struct {
	Meta CR3MetaBox
	Trak [4]CR3Trak
}

CrxMoovBox is a Canon Raw Moov Box

type DataInformationBox

type DataInformationBox struct {
	Children []Box
}

DataInformationBox is a "dinf" box

func (DataInformationBox) Type

func (dinf DataInformationBox) Type() BoxType

Type returns TypeDinf

type FileTypeBox

type FileTypeBox struct {
	Compatible   [brandCount]Brand // all 4 bytes
	MinorVersion [4]byte           // 4 bytes
	MajorBrand   Brand             // 4 bytes
}

FileTypeBox is a BMFF FileTypeBox

func (FileTypeBox) IsCR3

func (ftyp FileTypeBox) IsCR3() bool

IsCR3 returns true if major brand is crx (Canon CR3)

func (FileTypeBox) String

func (ftyp FileTypeBox) String() string

type Flags

type Flags uint32

Flags for a FullBox 8 bits -> Version 24 bits -> Flags

func (Flags) Flags

func (f Flags) Flags() uint32

Flags returns underlying Flags after removing version. Flags are 24 bits.

func (Flags) String

func (f Flags) String() string

func (Flags) Version

func (f Flags) Version() uint8

Version returns a uint8 version.

type HandlerBox

type HandlerBox struct {
	Flags Flags

	//Name        string
	HandlerType HandlerType
	// contains filtered or unexported fields
}

HandlerBox is a "hdlr" box.

Handler box hdlr tells the metadata type. For HEIF, it is always ’pict’.

func (HandlerBox) Type

func (hdlr HandlerBox) Type() BoxType

Type returns TypeHdlr.

type HandlerType

type HandlerType uint8

HandlerType always 4 bytes; usually "pict" for HEIF images.

func (HandlerType) String

func (ht HandlerType) String() string

type ImageRotation

type ImageRotation uint8

ImageRotation is an "irot" - image rotation property. Represents the Image Rotation Angle at 90 degree intervals.

func (ImageRotation) String

func (irot ImageRotation) String() string

func (ImageRotation) Type

func (irot ImageRotation) Type() BoxType

Type returns TypeIrot

type ImageSpatialExtentsProperty

type ImageSpatialExtentsProperty struct {
	Flags
	W uint32
	H uint32
}

ImageSpatialExtentsProperty is an "ispe" Property

func (ImageSpatialExtentsProperty) String

func (ispe ImageSpatialExtentsProperty) String() string

func (ImageSpatialExtentsProperty) Type

Type returns TypeIspe

type IndexOffset

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

IndexOffset has an offset and a length.

type ItemInfoBox

type ItemInfoBox struct {
	//size int64
	//Flags Flags
	//Count uint16
	ItemInfos []ItemInfoEntry
}

ItemInfoBox represents an "iinf" box.

func (ItemInfoBox) ItemByID

func (iinf ItemInfoBox) ItemByID(itemID uint16) (ItemInfoEntry, error)

ItemByID returns the Item of a given ID. If the ItemID is not found, the returned error is ErrItemNotFound.

func (ItemInfoBox) LastItemByType

func (iinf ItemInfoBox) LastItemByType(itemType ItemType) (ItemInfoEntry, error)

LastItemByType returns the Last Item of a given Type. If the ItemType is not found, the returned error is ErrItemNotFound.

func (ItemInfoBox) String

func (iinf ItemInfoBox) String() string

func (ItemInfoBox) Type

func (iinf ItemInfoBox) Type() BoxType

Type returns TypeIinf

type ItemInfoEntry

type ItemInfoEntry struct {
	//Flags           Flags
	ItemID          uint16
	ProtectionIndex uint16

	ItemType ItemType
	// contains filtered or unexported fields
}

ItemInfoEntry represents an "infe" box.

TODO: currently only parses Version 2 boxes.

func (ItemInfoEntry) String

func (infe ItemInfoEntry) String() string

func (ItemInfoEntry) Type

func (infe ItemInfoEntry) Type() BoxType

Type returns TypeInfe

type ItemLocationBox

type ItemLocationBox struct {
	Items     []ItemLocationBoxEntry
	ItemCount uint16
	// contains filtered or unexported fields
}

ItemLocationBox is a "iloc" box

func (ItemLocationBox) EntryByID

func (iloc ItemLocationBox) EntryByID(id uint16) (ItemLocationBoxEntry, error)

EntryByID returns the last Item Location Box Entry for the given ID. If the ID is not found returns ErrItemNotFound.

func (ItemLocationBox) String

func (iloc ItemLocationBox) String() string

func (ItemLocationBox) Type

func (iloc ItemLocationBox) Type() BoxType

Type returns TypeIloc

type ItemLocationBoxEntry

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

ItemLocationBoxEntry is not a box

func (ItemLocationBoxEntry) String

func (ilbe ItemLocationBoxEntry) String() string

type ItemPropertiesBox

type ItemPropertiesBox struct {
	PropertyContainer ItemPropertyContainerBox
	//Associations      []ItemPropertyAssociation // at least 1
	Associations ItemPropertyAssociation
}

ItemPropertiesBox is an ISOBMFF "iprp" box

func (ItemPropertiesBox) ContainerByID

func (iprp ItemPropertiesBox) ContainerByID(id uint16, boxType BoxType) (Box, error)

ContainerByID returns a Box for the given id and boxType.

func (ItemPropertiesBox) String

func (iprp ItemPropertiesBox) String() string

func (ItemPropertiesBox) Type

func (iprp ItemPropertiesBox) Type() BoxType

Type returns TypeIprp

type ItemProperty

type ItemProperty struct {
	Essential bool
	Index     uint16
}

ItemProperty is not a box

type ItemPropertyAssociation

type ItemPropertyAssociation struct {
	//Flags      Flags
	//EntryCount uint32
	Entries []ItemPropertyAssociationItem
}

ItemPropertyAssociation is an ISOBMFF "ipma" box

func (ItemPropertyAssociation) Type

func (ipma ItemPropertyAssociation) Type() BoxType

Type returns TypeIpma

type ItemPropertyAssociationItem

type ItemPropertyAssociationItem struct {
	ItemID       uint32
	Associations [6]uint16
}

ItemPropertyAssociationItem is not a box

func (ItemPropertyAssociationItem) String

func (ipai ItemPropertyAssociationItem) String() string

type ItemPropertyContainerBox

type ItemPropertyContainerBox struct {
	Properties []Box // of ItemProperty or ItemFullProperty
}

ItemPropertyContainerBox is an ISOBMFF "ipco" box

func (ItemPropertyContainerBox) Type

func (ipco ItemPropertyContainerBox) Type() BoxType

Type returns TypeIpco

type ItemType

type ItemType [4]byte

ItemType is always 4 bytes

func (ItemType) String

func (it ItemType) String() string

type ItemTypeReferenceBox

type ItemTypeReferenceBox struct {
	Flags Flags
	// contains filtered or unexported fields
}

ItemTypeReferenceBox is an "iref" box.

Item Reference box iref enables creating directional links from an item to one or several other items. Item references are extensively used by HEIF. For instance, thumbnail images are recognized from a thumbnail type reference which links from the thumbnail image to the master image.

func (ItemTypeReferenceBox) Type

func (iref ItemTypeReferenceBox) Type() BoxType

Type returns TypeIref.

type Logger

type Logger interface {
	Debug(format string, args ...interface{})
}

Logger is a logging Interface

type MetaBox

type MetaBox struct {
	//size  uint32
	Flags Flags

	Handler    HandlerBox
	Primary    PrimaryItemBox
	ItemInfo   ItemInfoBox
	Properties ItemPropertiesBox
	Location   ItemLocationBox
	Children   []Box
}

MetaBox is a 'meta' box

func (MetaBox) String

func (mb MetaBox) String() string

func (MetaBox) Type

func (mb MetaBox) Type() BoxType

Type returns TypeMeta

type MoovBox

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

MoovBox is a 'moov' box

func (MoovBox) Size

func (moov MoovBox) Size() int64

Size returns the size of the MoovBox

func (MoovBox) Type

func (moov MoovBox) Type() BoxType

Type returns TypeMoov

type OffsetLength

type OffsetLength struct {
	Offset, Length uint64
}

OffsetLength contains an offset and length

func (OffsetLength) String

func (ol OffsetLength) String() string

type PrimaryItemBox

type PrimaryItemBox struct {
	Flags  Flags
	ItemID uint16
}

PrimaryItemBox is a "pitm" box.

Primary Item Reference pitm allows setting one image as the primary item.

func (PrimaryItemBox) String

func (pitm PrimaryItemBox) String() string

func (PrimaryItemBox) Type

func (pitm PrimaryItemBox) Type() BoxType

Type returns TypePitm

type Reader

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

Reader is a BMFF reader

func NewReader

func NewReader(r io.Reader) Reader

NewReader returns a new bmff.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) ReadCrxMoovBox

func (r *Reader) ReadCrxMoovBox() (cmb CrxMoovBox, err error)

ReadCrxMoovBox is a performance focused method for parsing the moov box from a .CR3 file.

func (*Reader) ReadFtypBox

func (r *Reader) ReadFtypBox() (FileTypeBox, error)

ReadFtypBox reads an 'ftyp' box from a BMFF file.

This should be the first read function called.

func (*Reader) ReadMetaBox

func (r *Reader) ReadMetaBox() (mb MetaBox, err error)

ReadMetaBox reads a 'meta' box from a BMFF file.

This should be called in order. First call ReadFtypBox

func (*Reader) ReadMoovBox

func (r *Reader) ReadMoovBox() (moov MoovBox, err error)

ReadMoovBox reads a 'moov' box from a BMFF file.

This should be called in order. First call ReadFtypBox

type STDLogger

type STDLogger struct {
}

STDLogger is the Standard Logger

func (STDLogger) Debug

func (std STDLogger) Debug(format string, args ...interface{})

Debug logs debug information

type UUIDBox

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

UUIDBox is a special type of Box that contains a uuid

func (UUIDBox) String

func (uuidBox UUIDBox) String() string

type UnknownBox

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

UnknownBox is a box that was unable to be parsed.

func (UnknownBox) Size

func (ub UnknownBox) Size() int64

Size returns the Size of the UnknownBox

func (UnknownBox) String

func (ub UnknownBox) String() string

func (UnknownBox) Type

func (ub UnknownBox) Type() BoxType

Type returns the BoxType of the UnknownBox

Jump to

Keyboard shortcuts

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