Define user-defined MP4 boxes
masterYou can extend the library by defining custom box types. This requires:
- Defining a
BoxTypeusingmp4.StrToBoxType. - Creating a struct that embeds
mp4.FullBox(or similar) and uses struct tags to define the layout. - Implementing the
GetType() BoxTypemethod on your struct. - Registering the box with
mp4.AddBoxDef(instance, offset)during initialization.
Example struct tags:
mp4:"0,extend"for a FullBox.mp4:"1,size=32"for a fixed-size field.mp4:"2,size=8,len=dynamic"for a dynamic byte array.
func BoxTypeXxxx() BoxType { return mp4.StrToBoxType("xxxx") }
func init() {
mp4.AddBoxDef(&Xxxx{}, 0)
}
type Xxxx struct {
FullBox `mp4:"0,extend"`
UI32 uint32 `mp4:"1,size=32"`
ByteArray []byte `mp4:"2,size=8,len=dynamic"`
}
func (*Xxxx) GetType() BoxType {
return BoxTypeXxxx()
}