mp4

package
v0.0.0-...-df8ff06 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2018 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDashFragment

func CreateDashFragment(mp4 map[string][]interface{}, fragmentNumber uint32, fragmentDuration uint32) (fmp4 map[string][]interface{})

func CreateDashFragmentWithConf

func CreateDashFragmentWithConf(dConf DashConfig, filename string, fragmentNumber uint32, fragmentDuration uint32) (fmp4 map[string][]interface{})

func CreateDashInit

func CreateDashInit(mp4 map[string][]interface{}) (mp4Init map[string][]interface{})

Create a DASH format mp4 Init header

func CreateDashInitWithConf

func CreateDashInitWithConf(dConf DashConfig) (mp4Init map[string][]interface{})

Create DASH init header with a config struct

func Debug

func Debug(mode bool)

func MapToBytes

func MapToBytes(mp4 map[string][]interface{}) (data []byte)

Types

type Avc1Box

type Avc1Box struct {
	Size     uint32
	Reserved [6]byte

	Version              uint16
	RevisionLevel        uint16
	Vendor               uint32
	TemporalQuality      uint32
	SpacialQuality       uint32
	Width                uint16
	Height               uint16
	HorizontalResolution uint32
	VerticalResolution   uint32
	EntryDataSize        uint32
	FramesPerSample      uint16
	CompressorName       [32]byte
	BitDepth             uint16
	ColorTableIndex      int16
	// contains filtered or unexported fields
}

func (Avc1Box) Bytes

func (avc1 Avc1Box) Bytes() (data []byte)

type AvcCBox

type AvcCBox struct {
	Size                 uint32
	ConfigurationVersion uint8 /* 1 */
	AVCProfileIndication uint8 /* profile idc in SPS */
	ProfileCompatibility uint8
	AVCLevelIndication   uint8  /* level idc in SPS */
	NalUnitSize          uint8  /* in bytes of the NALUnitLength field. upper 6-bits are reserved as 111111b aka | 0xfc */
	SPSEntryCount        uint8  /* Number of Sequence Parameter Set Entries */
	SPSSize              uint16 /* Sequence Parameter Set Size upper 3-bits are reserved as 111b aka | 0xe0 */
	SPSData              []byte /* Sequence Parameter Set Datas */
	PPSEntryCount        uint8  /* Number of Picture Parameter Set Entries */
	PPSSize              uint16 /* Picture Parameter Set Size */
	PPSData              []byte /* Picture Parameter Set Datas */
}

func (AvcCBox) Bytes

func (avcC AvcCBox) Bytes() (data []byte)

type BtrtBox

type BtrtBox struct {
	Size               uint32
	DecodingBufferSize uint32 /* the size of the decoding buffer for the elementary stream in bytes */
	MaxBitrate         uint32 /* the maximum rate in bits/second over any window of one second */
	AvgBitrate         uint32 /* the average rate in bits/second over the entire presentation */
}

MPEG-4 Bit Rate Box * This box signals the bit rate information of the AVC video stream.

func (BtrtBox) Bytes

func (btrt BtrtBox) Bytes() (data []byte)

type CttsBox

type CttsBox struct {
	Size       uint32
	Offset     int64
	Version    byte
	Reserved   [3]byte
	EntryCount uint32
	Entries    []CttsBoxEntry
}

func (CttsBox) Bytes

func (ctts CttsBox) Bytes() (data []byte)

type CttsBoxEntry

type CttsBoxEntry struct {
	SampleCount  uint32
	SampleOffset uint32
}

type DashAudioEntry

type DashAudioEntry struct {
	// Sound fields if Type == "audio"
	NumberOfChannels uint16 // MP4A MP4 Box Info (eg: 2)
	SampleSize       uint16 // MP4A MP4 Box Info (eg: 16)
	CompressionId    uint16 // MP4A MP4 Box Info (eg: 0)
	SampleRate       uint32 // MP4A MP4 Box Info (eg: 3145728000)
}

type DashConfig

type DashConfig struct {
	StszBoxOffset int64
	StszBoxSize   uint32
	MdatBoxOffset int64
	MdatBoxSize   uint32  // MDAT MP4 Box Size
	Type          string  // "audio" || "video
	Rate          int32   // Typically 0x00010000 (1.0)
	Volume        int16   // Typically 0x0100 (Full Volume)
	Duration      uint64  // MDHD MP4 Box info
	Timescale     uint32  // MDHD MP4 Box info (eg: for audio: 48000, for video: 60000)
	Language      [3]byte // ISO-639-2/T 3 letters code (eg: []byte{ 'e', 'n', 'g' }
	HandlerType   uint32  // HDLR MP4 Box info (eg: 1986618469)
	SampleDelta   uint32  // STTS MP4 Box SampleDelta via Entries[0] (eg: 1024)
	MediaTime     int64   // ELST MP4 Box MediaTime

	Audio *DashAudioEntry `json:",omitempty"`
	Video *DashVideoEntry `json:",omitempty"`
}

type DashVideoEntry

type DashVideoEntry struct {
	// Video fields if Type == "video"
	Width                uint16  // AVC1 MP4 Box info (eg: 426)
	Height               uint16  // AVC1 MP4 Box info (eg: 240)
	HorizontalResolution uint32  // AVC1 MP4 Box info (eg: 4718592)
	VerticalResolution   uint32  // AVC1 MP4 Box info (eg: 4718592)
	EntryDataSize        uint32  // AVC1 MP4 Box info (eg: 0)
	FramesPerSample      uint16  // AVC1 MP4 Box info (eg: 1)
	BitDepth             uint16  // AVC1 MP4 Box info (eg: 24)
	ColorTableIndex      int16   // AVC1 MP4 Box info (eg: -1)
	CodecInfo            [3]byte // AVCC MP4 Box AVC Profile/Comptaiblity/Level Information (eg: []byte{ 0x42, 0xC0, 0x1E }
	NalUnitSize          byte    // AVCC MP4 Box info NALUnitLength field. upper 6-bits are reserved as 111111b aka | 0xfc (eg: 0xFF)
	SPSEntryCount        uint8   // AVCC MP4 Box info (eg: 1)
	SPSSize              uint16  // AVCC MP4 Box info (eg: 23)
	SPSData              []byte  // AVCC MP4 Box info (eg: [103 66 192 30 219 2 128 191 229 192 68 0 0 15 164 0 7 83 0 60 88 187 128])
	PPSEntryCount        uint8   // AVCC MP4 Box info (eg: 1)
	PPSSize              uint16  // AVCC MP4 Box info (eg: 4)
	PPSData              []byte  // AVCC MP4 Box info (eg: 104 202 140 178)
	StssBoxOffset        int64
	StssBoxSize          uint32
	CttsBoxOffset        int64
	CttsBoxSize          uint32
}

type DrefBox

type DrefBox struct {
	Size       uint32
	Version    byte
	Reserved   [3]byte
	EntryCount uint32
	UrlBox     []DrefUrlBox
	UrnBox     []DrefUrnBox
}

func (DrefBox) Bytes

func (dref DrefBox) Bytes() (data []byte)

type DrefUrlBox

type DrefUrlBox struct {
	Size     uint32
	Location string
	Version  byte
	Flags    [3]byte
}

type DrefUrnBox

type DrefUrnBox struct {
	Size     uint32
	Name     string
	Location string
	Version  byte
	Flags    [3]byte
}

type ElstBox

type ElstBox struct {
	Size              uint32
	Version           byte
	Reserved          [3]byte
	EntryCount        uint32
	SegmentDuration   uint64
	MediaTime         int64
	MediaRateInteger  int16
	MediaRateFraction int16
}

type EsdsBox

type EsdsBox struct {
	Size    uint32
	Version uint32
	Data    []byte /* Unkown for the moment ??? */
}

func (EsdsBox) Bytes

func (esds EsdsBox) Bytes() (data []byte)

type FreeBox

type FreeBox struct {
	Size uint32
	Data []byte
}

func (FreeBox) Bytes

func (free FreeBox) Bytes() (data []byte)

type FrmaBox

type FrmaBox struct {
	Size       uint32
	DataFormat [4]byte
}

func (FrmaBox) Bytes

func (frma FrmaBox) Bytes() (data []byte)

type FtypBox

type FtypBox struct {
	Size             uint32
	MajorBrand       [4]byte
	MinorVersion     uint32
	CompatibleBrands [][4]byte
}

func (FtypBox) Bytes

func (ftyp FtypBox) Bytes() (data []byte)

type HdlrBox

type HdlrBox struct {
	Size        uint32
	Version     byte
	Reserved    [3]byte
	PreDefined  uint32
	HandlerType uint32
	Reserved2   [3]uint32
	Name        []byte
}

func (HdlrBox) Bytes

func (hdlr HdlrBox) Bytes() (data []byte)

type HmhdBox

type HmhdBox struct {
	Version    byte
	Reserved   [3]byte
	MaxPDUSize uint16
	AvgPDUSize uint16
	MaxBitrate uint32
	AvgBitrate uint32
	Reserved2  uint32
}

type JsonConfig

type JsonConfig struct {
	SegmentDuration uint32
	Tracks          map[string][]TrackEntry
}

type MdatBox

type MdatBox struct {
	Size     uint32
	Filename string
	Offset   int64
}

func (MdatBox) Bytes

func (mdat MdatBox) Bytes() (data []byte)

type MdhdBox

type MdhdBox struct {
	Size             uint32
	Version          byte
	Reserved         [3]byte
	CreationTime     uint64
	ModificationTime uint64
	Timescale        uint32
	Duration         uint64
	Language         uint16
	PreDefined       uint16
}

func (MdhdBox) Bytes

func (mdhd MdhdBox) Bytes() (data []byte)

type MehdBox

type MehdBox struct {
	Size             uint32
	Version          byte
	Reserved         [3]byte
	FragmentDuration uint64
}

func (MehdBox) Bytes

func (mehd MehdBox) Bytes() (data []byte)

type MfhdBox

type MfhdBox struct {
	Size           uint32
	Version        byte
	Reserved       [3]byte
	SequenceNumber uint32
}

MOOF SubBoxes

func (MfhdBox) Bytes

func (mfhd MfhdBox) Bytes() (data []byte)

type Mp4

type Mp4 struct {
	Filename string
	Language string
	IsVideo  bool
	IsAudio  bool
	Boxes    map[string][]interface{}
}

func ParseFile

func ParseFile(filename string, language string) (mp4 Mp4)

Parse the mp4 file header and return all decoded box data in a map[string][]interface{}

type Mp4aBox

type Mp4aBox struct {
	Size               uint32
	Reserved           [6]byte
	DataReferenceIndex uint16
	Version            uint16
	RevisionLevel      uint16
	Vendor             uint32
	NumberOfChannels   uint16
	SampleSize         uint16
	CompressionId      uint16
	Reserved2          uint16
	SampleRate         uint32
}

func (Mp4aBox) Bytes

func (mp4a Mp4aBox) Bytes() (data []byte)

type MvhdBox

type MvhdBox struct {
	Size             uint32
	Version          byte
	Reserved         [3]byte
	CreationTime     uint64
	ModificationTime uint64
	Timescale        uint32
	Duration         uint64
	Rate             int32
	Volume           int16
	Reserved2        uint16
	Reserved3        uint64
	Matrix           [9]int32
	PreDefined       [6]uint32
	NextTrackID      uint32
}

func (MvhdBox) Bytes

func (mvhd MvhdBox) Bytes() (data []byte)

type ParentBox

type ParentBox struct {
	Name [4]byte
	Size uint32
}

func (ParentBox) Bytes

func (parent ParentBox) Bytes() (data []byte)

type SchmBox

type SchmBox struct {
	Size          uint32
	Version       byte
	Flags         [3]byte
	SchemeType    [4]byte
	SchemeVersion uint32
	SchemeUri     string
}

func (SchmBox) Bytes

func (schm SchmBox) Bytes() (data []byte)

type SdtpBox

type SdtpBox struct {
	Size        uint32
	Version     byte
	SampleCount uint32
	Entries     []uint8
}

func (SdtpBox) Bytes

func (sdtp SdtpBox) Bytes() (data []byte)

type SmhdBox

type SmhdBox struct {
	Size      uint32
	Version   byte
	Reserved  [3]byte
	Balance   int16
	Reserved2 uint16
}

func (SmhdBox) Bytes

func (smhd SmhdBox) Bytes() (data []byte)

type StcoBox

type StcoBox struct {
	Size        uint32
	Version     byte
	Reserved    [3]byte
	EntryCount  uint32
	ChunkOffset []uint32
}

func (StcoBox) Bytes

func (stco StcoBox) Bytes() (data []byte)

type StscBox

type StscBox struct {
	Size       uint32
	Version    byte
	Flags      [3]byte
	EntryCount uint32
	Entries    []StscEntry
}

func (StscBox) Bytes

func (stsc StscBox) Bytes() (data []byte)

type StscEntry

type StscEntry struct {
	FirstChunk             uint32
	SamplesPerChunk        uint32
	SampleDescriptionIndex uint32
}

type StsdBox

type StsdBox struct {
	Size       uint32
	Version    byte
	Reserved   [3]byte
	EntryCount uint32
}

func (StsdBox) Bytes

func (stsd StsdBox) Bytes() (data []byte)

type StssBox

type StssBox struct {
	Size         uint32
	Offset       int64
	Version      byte
	Reserved     [3]byte
	EntryCount   uint32
	SampleNumber []uint32
}

func (StssBox) Bytes

func (stss StssBox) Bytes() (data []byte)

type StszBox

type StszBox struct {
	Size        uint32
	Offset      int64
	Version     byte
	Reserved    [3]byte
	SampleSize  uint32
	SampleCount uint32
	EntrySize   []uint32
}

func (StszBox) Bytes

func (stsz StszBox) Bytes() (data []byte)

type SttsBox

type SttsBox struct {
	Size       uint32
	Version    byte
	Reserved   [3]byte
	EntryCount uint32
	Entries    []SttsBoxEntry
}

func (SttsBox) Bytes

func (stts SttsBox) Bytes() (data []byte)

type SttsBoxEntry

type SttsBoxEntry struct {
	SampleCount uint32
	SampleDelta uint32
}

type StypBox

type StypBox struct {
	Size             uint32
	MajorBrand       [4]byte
	MinorVersion     uint32
	CompatibleBrands [][4]byte
}

func (StypBox) Bytes

func (styp StypBox) Bytes() (data []byte)

type TfdtBox

type TfdtBox struct {
	Size                uint32
	Version             byte // Must be 1
	Reserved            [3]byte
	BaseMediaDecodeTime uint64
}

func (TfdtBox) Bytes

func (tfdt TfdtBox) Bytes() (data []byte)

type TfhdBox

type TfhdBox struct {
	Size    uint32
	Version byte
	Flags   [3]byte
	TrackID uint32
	// All of the following are optional fields
	BaseDataOffset         uint64
	SampleDescriptionIndex uint32
	DefaultSampleDuration  uint32
	DefaultSampleSize      uint32
	DefaultSampleFlags     uint32
}

func (TfhdBox) Bytes

func (tfhd TfhdBox) Bytes() (data []byte)

type TkhdBox

type TkhdBox struct {
	Size             uint32
	Version          byte
	Flags            [3]byte
	CreationTime     uint64
	ModificationTime uint64
	TrackID          uint32
	Reserved         uint32
	Duration         uint64
	Reserved2        uint64
	Layer            int16
	AlternateGroup   int16
	Volume           int16
	Reserved3        uint16
	Matrix           [9]int32
	Width            uint32
	Height           uint32
}

func (TkhdBox) Bytes

func (tkhd TkhdBox) Bytes() (data []byte)

type TrackEntry

type TrackEntry struct {
	Name      string
	Bandwidth uint64
	File      string
	Lang      string
	Config    *DashConfig `json:",omitempty"`
}

type TrexBox

type TrexBox struct {
	Size                          uint32
	Version                       byte
	Reserved                      [3]byte
	TrackID                       uint32
	DefaultSampleDescriptionIndex uint32
	DefaultSampleDuration         uint32
	DefaultSampleSize             uint32
	DefaultSampleFlags            uint32
}

func (TrexBox) Bytes

func (trex TrexBox) Bytes() (data []byte)

type TrunBox

type TrunBox struct {
	Size        uint32
	Version     byte
	Flags       [3]byte
	SampleCount uint32
	// All of the following are optional fields
	DataOffset       int32
	FirstSampleFlags uint32
	Samples          []TrunBoxSample
}

func (TrunBox) Bytes

func (trun TrunBox) Bytes() (data []byte)

type TrunBoxSample

type TrunBoxSample struct {
	Duration              uint32
	Size                  uint32
	Flags                 uint32
	CompositionTimeOffset int64
}

type VmhdBox

type VmhdBox struct {
	Size         uint32
	Version      byte
	Reserved     [3]byte
	GraphicsMode uint16
	OpColor      [3]uint16
}

func (VmhdBox) Bytes

func (vmhd VmhdBox) Bytes() (data []byte)

Jump to

Keyboard shortcuts

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