quicktime

package module
v0.0.0-...-5382555 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2018 License: MIT Imports: 7 Imported by: 5

README

go-quicktime

Codacy Badge GoDoc wercker status

quicktime is a simple Quicktime container parser written in Go.

Uses the io.ReaderAt interface for random access into the Quicktime file. Originally written for use with LazyFS

The core unit is an Atom which is a generic structure storing the the type, size, and location of each Atom. Each Atom can also optionally store its data as a byte slice. Atoms are arranged in a tree structure which reflects the structure of the file.

When the data is loaded, the Atom can be parsed into a named Atom type (e.g. MOOVAtom, FTYPAtom, etc). These structures break out the actual fields within the Atom. In some cases these named types do understand the Atom hierarchy.

Forked from here.

TODO

License

This library is under the MIT License

Documentation

Overview

Package quicktime provides primitives for loading the tree of Atoms from a Quicktime file, and reading a subset of the atoms.

Index

Constants

View Source
const AtomHeaderLength = 8

AtomHeaderLength is the length of a standard Atom header in bytes: a 4 byte atom size, and a 4 byte atom type.

View Source
const ExtendedHeaderLength = 16

ExtendedHeaderLength is the length of an extended Quicktime Header: 4 bytes of size == 1 for extended headers 4 bytes of atom type 8 bytes of extended size

View Source
const Version = "v0.1.0"

Version stores the version

Variables

This section is empty.

Functions

func DumpTree

func DumpTree(tree AtomArray)

DumpTree iterates over an AtomArray and prints each atom on a line

func PrintAtom

func PrintAtom(atom *Atom, indent int)

PrintAtom writes a short descriptive string for each Atom in an AtomArray to do this, it must parse the atom

Types

type Atom

type Atom struct {
	Offset   uint64
	Size     uint64
	DataSize uint64
	Type     string
	IsExt    bool

	Children AtomArray
	Data     []byte `json:"-"`
}

The Atom struct stores a generic (not-decoded) Atom, including its type, size and optionally its Children and Data as a slice of the original byte buffer. If read from an io.ReaderAt it will also store the offset of the atom within the file (see ReadAtomAt)

func ParseAtom

func ParseAtom(buffer []byte) (Atom, error)

ParseAtom reads the first 8 bytes of the buffer and returns the appropriate Atom. Note this function doesn't set Data or Children for the Atom -- see ReadData and BuildChildren.

func ReadAtomAt

func ReadAtomAt(r io.ReaderAt, offset uint64) (Atom, error)

ReadAtomAt reads the atom header from an io.ReaderAt and produces an Atom.

func (*Atom) BuildChildren

func (atom *Atom) BuildChildren()

BuildChildren adds children to an Atom after its data has been loaded. If the Atom already has children, behavior is undetermined.

func (Atom) FindAtom

func (atom Atom) FindAtom(typeStr string) *Atom

FindAtom looks through an Atom's children for a given type, returning the first instance or nil of not found

func (Atom) FindAtoms

func (atom Atom) FindAtoms(typeStr string) (out []*Atom)

FindAtoms looks through an Atom's children for a given type, returning an array of all instances. The array will be empty if not found.

func (Atom) HasData

func (atom Atom) HasData() bool

HasData is true if the Data field is set for the atom

func (*Atom) HeaderLength

func (atom *Atom) HeaderLength() uint64

HeaderLength returns the number of bytes in the header, depending on whether the header is extended or not.

func (*Atom) IsContainer

func (atom *Atom) IsContainer() bool

IsContainer returns true if a given atom type is a container, rather than a leaf. This is done using a switch ... if I've missed an atom, send me a pull request!

func (Atom) IsType

func (atom Atom) IsType(typeStr string) bool

IsType returns true if the Atom's type matches the argument.

func (*Atom) ReadChildren

func (atom *Atom) ReadChildren(r io.ReaderAt)

ReadChildren adds children to an Atom by reading from a ReaderAt.

func (*Atom) ReadData

func (atom *Atom) ReadData(r io.ReaderAt) (err error)

ReadData populates the atom's Data member from the reader. Assumes it is the same reader used to populate the original Atom. If Atom.Children is set, it also sets the Data for its children (recursively).

func (*Atom) SetData

func (atom *Atom) SetData(buf []byte)

SetData sets the atom's Data field from the byte slice. The slice must start at the beginning of this atom's header. If the Atom has children, it will set the data for the Children (recursively).

type AtomArray

type AtomArray []*Atom

AtomArray is used to store the topmost level when building the atom tree ... there is no master top-level Atom in Quicktime.

func BuildTree

func BuildTree(r io.ReaderAt, filesize uint64, options ...func(*BuildTreeConfig)) (AtomArray, error)

BuildTree builds a tree of Atoms from an io.ReaderAt. Rather than check for EOF, requires the io length to be pre-determined. Takes a list of configuration closures, each of which is passed the BuildTreeConfig. Returns the top-level AtomArray. On an error, this AtomArray will contain atoms up to the error.

func (AtomArray) FindAtom

func (atoms AtomArray) FindAtom(typeStr string) *Atom

FindAtom looks through an AtomArray for a given type, returning the first instance or nil of not found

func (AtomArray) FindAtoms

func (atoms AtomArray) FindAtoms(typeStr string) AtomArray

FindAtoms looks through an AtomArray for a given type, returning an array of all instances. The array will be empty if not found.

type BuildTreeConfig

type BuildTreeConfig struct {
	// List of Atom types which should be eager-loaded while building the tree.
	EagerloadTypes StringList
}

BuildTreeConfig stores parameters for the BuildTree function.

type CO64Atom

type CO64Atom struct {
	Atom         *Atom
	ChunkOffsets []int64
}

A CO64Atom is a table of 64bit chunk offsets For simplicity, I internally convert STCO atoms to CO64, rather than duplicating functionality

func ParseSTCO

func ParseSTCO(atom *Atom) (CO64Atom, error)

ParseSTCO converts a generic "stco" or "co64" atom to a CO64Atom struct

func (CO64Atom) ChunkOffset

func (stco CO64Atom) ChunkOffset(chunk int) int64

ChunkOffset gives the offset for a given chunk (remember that chunks are enumerated base-1)

type FTYPAtom

type FTYPAtom struct {
	Atom         *Atom
	MajorBrand   uint32
	MinorVersion uint32
}

A FTYPAtom stores versioning information about the Atom tree

func ParseFTYP

func ParseFTYP(atom *Atom) (FTYPAtom, error)

ParseFTYP converts a generic "ftyp" atom to an FTYPAtom

type MDIAAtom

type MDIAAtom struct {
	Minf MINFAtom
}

A MDIAAtom ...

type MINFAtom

type MINFAtom struct {
	Stbl STBLAtom
}

A MINFAtom is ...

type MVHDAtom

type MVHDAtom struct {
	Atom                                        *Atom
	CreationTime, ModTime, TimeScale, TimeTicks uint32
}

A MVHDAtom stores timing information about the movie

func ParseMVHD

func ParseMVHD(atom *Atom) (MVHDAtom, error)

ParseMVHD converts a generic "mvhd" atom to an MVHDAtom

func (MVHDAtom) Duration

func (mvhd MVHDAtom) Duration() time.Duration

Duration returns the movie duration stored in an MVHDAtom

type STBLAtom

type STBLAtom struct {
	Stsz STSZAtom
	Stco CO64Atom
	Stsc STSCAtom
}

A STBLAtom stores the three Atoms requires to look up the file offset of an individual frame ("sample") in the file: STSZ (sample size), STCO or CO64 (chunk offset) and STSC (samples per chunk)

func ParseSTBL

func ParseSTBL(atom *Atom) (STBLAtom, error)

ParseSTBL converts a generic Atom containing a "stbl" to a STBLAtom.

func (STBLAtom) NumFrames

func (stbl STBLAtom) NumFrames() uint64

NumFrames returns the number of samples (frames) in the stbl

func (STBLAtom) SampleOffset

func (stbl STBLAtom) SampleOffset(sample int) (int64, error)

SampleOffset calculates the byte offset of a given sample within the quicktime file

func (STBLAtom) SampleOffsetSize

func (stbl STBLAtom) SampleOffsetSize(sample int) (int64, int, error)

SampleOffsetSize calculates both the offset and size of a sample

type STSCAtom

type STSCAtom struct {
	Atom    *Atom
	Entries []stscEntry
}

A STSCAtom stores a table of samples per chunk

func ParseSTSC

func ParseSTSC(atom *Atom) (STSCAtom, error)

ParseSTSC converts a generic "stsc" Atom to a STSCAtom

func (STSCAtom) SampleChunk

func (stsc STSCAtom) SampleChunk(s int) (chunk int, chunkStart int, offset int, err error)

SampleChunk converts a sample number to a chunk, chunk offset, and offset with the chunk

type STSZAtom

type STSZAtom struct {
	Atom        *Atom
	SampleSze   int32
	SampleSizes []int32
}

A STSZAtom stores a table of sample sizes

func ParseSTSZ

func ParseSTSZ(atom *Atom) (STSZAtom, error)

ParseSTSZ converts a generic "stsz" Atom to a STSZAtom

func (STSZAtom) NumSamples

func (stsz STSZAtom) NumSamples() uint64

NumSamples returns the number of samples in an STSZAtom

func (STSZAtom) SampleSize

func (stsz STSZAtom) SampleSize(sample int) int

SampleSize looks up the size of a given sample in the STSZAtom

type StringList

type StringList []string

StringList stores a slice of Strings for BuildTreeConfig

type TKHDAtom

type TKHDAtom struct {
	Atom          *Atom
	Height, Width float32
}

A TKHDAtom ...

func ParseTKHD

func ParseTKHD(atom *Atom) (TKHDAtom, error)

ParseTKHD converts a generic "tkhd" Atom to a TKHD atom

type TRAKAtom

type TRAKAtom struct {
	Tkhd TKHDAtom
	Mdia MDIAAtom
}

A TRAKAtom ...

func ParseTRAK

func ParseTRAK(atom *Atom) (TRAKAtom, error)

ParseTRAK converts a generic "trak" Atom to a TRAKAtom

Directories

Path Synopsis
cmd
dump_mov_tree command

Jump to

Keyboard shortcuts

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