mp4e

package
v1.30.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptFile added in v1.26.0

func DecryptFile(src, dst string, scheme CryptScheme, key, iv []byte, initSeg ...string) error

DecryptFile decrypts an encrypted fMP4 file and writes the cleartext to dst. It dispatches to the appropriate decryption method based on the scheme:

  • cenc/cbcs: mp4ff ISO BMFF Common Encryption (sample-level). For DASH media segments (.m4s) that lack a moov box, pass the init segment path as initSeg so the decryption metadata can be extracted.
  • aes-128: AES-CBC whole-file decryption (HLS-style, PKCS7 padded)

func DecryptReader added in v1.26.0

func DecryptReader(r io.Reader, scheme CryptScheme, key, iv []byte) (io.Reader, error)

DecryptReader decrypts an encrypted fMP4 from a reader and returns the cleartext as a reader. Same dispatch logic as DecryptFile.

func LevelName added in v1.30.0

func LevelName(codecID string, levelIDC int) string

LevelName returns a human-readable level string for the given codec 4CC and level IDC value, e.g. LevelName("avc1", 40) == "4.0". Returns an empty string if the codec has no level IDC or the value is zero.

AVC level_idc is defined in ISO/IEC 14496-10 Table A-1: level = level_idc / 10. HEVC general_level_idc is defined in ISO/IEC 23008-2 Table A-1: level = general_level_idc / 30.

func ProfileName added in v1.30.0

func ProfileName(codecID string, profileIDC int) string

ProfileName returns a human-readable profile name for the given codec 4CC and profile IDC value, e.g. ProfileName("avc1", 100) == "High". Returns an empty string if the codec or profile IDC is not recognized.

AVC profile IDCs are defined in ISO/IEC 14496-10. HEVC profile IDCs are defined in ISO/IEC 23008-2. AAC profile IDCs are Audio Object Type values from ISO/IEC 14496-3.

Types

type CodecInfo added in v1.30.0

type CodecInfo struct {
	// CodecID is the sample description entry 4-character code (in the MP4
	// "stsd" box) as registered by the MP4RA; e.g. "hvc1", "avc1", "ec-3"
	CodecID string `json:"codec_id"`

	// CodecParameter specifies the decoder requirements for a media stream, as
	// specified by RFC 6381; e.g. "hvc1.2.4.L120.90" or "avc1.640028"
	CodecParameter string `json:"codec_parameter,omitempty"`

	// ProfileIDC is the codec profile IDC. The value is defined separately by
	// each codec; e.g. 2 = HEVC Main 10, 100 = AVC High
	ProfileIDC int `json:"profile_idc,omitempty"`

	// LevelIDC is the codec level IDC. The value id defined separately by each
	// codec:
	//  * Divide by 30 for HEVC, e.g. 120 → 4.0
	//  * Divide by 10 for AVC, e.g. 40  → 4.0
	LevelIDC int `json:"level_idc,omitempty"`

	// AudioChannels is the number of audio channels
	AudioChannels int `json:"audio_channels,omitempty"`

	// EC3 is set only when the codec is ec-3
	EC3 *EC3Info `json:"ec3,omitempty"`
}

CodecInfo contains information about a media stream's codecs

func ExtractCodecInfo added in v1.30.0

func ExtractCodecInfo(r io.Reader) (infos []*CodecInfo, err error)

ExtractCodecInfo decodes an MP4 container and returns codec information for all tracks. Supports AVC (avc1/avc3) and HEVC (hvc1/hev1) video tracks, and E-AC-3 (ec-3) and AAC (mp4a) audio tracks.

func (CodecInfo) MarshalJSON added in v1.30.0

func (c CodecInfo) MarshalJSON() ([]byte, error)

MarshalJSON adds additional profile_name and level_name fields alongside the numeric profile_idc and level_idc

type CryptScheme added in v1.26.0

type CryptScheme string

CryptScheme identifies the encryption scheme for DecryptFile.

const (
	CryptCENC   CryptScheme = "cenc"
	CryptCBCS   CryptScheme = "cbcs"
	CryptAES128 CryptScheme = "aes-128"
)

type EC3Info added in v1.30.0

type EC3Info struct {
	// ChanMap is the custom channel map bitmask from the MP4 dec3 box
	// (ETSI TS 102 366 Table E.1.4)
	ChanMap uint16 `json:"chan_map"`

	// JOC indicates Joint Object Coding (Dolby Atmos). True when the
	// flag_ec3_extension_type_a bit is set in the MP4 dec3 box extension
	// (ETSI TS 103 420)
	JOC bool `json:"joc"`

	// ComplexityIndex is the Atmos object complexity index
	// (complexity_index_type_a from ETSI TS 103 420). Only meaningful when
	// JOC is true.
	ComplexityIndex int `json:"complexity_index,omitempty"`
}

EC3Info holds E-AC-3-specific fields (Dolby Digital Plus / Atmos)

func (EC3Info) ChanMapHex added in v1.30.0

func (e EC3Info) ChanMapHex() string

ChanMapHex returns ChanMap as an uppercase hex string; e.g. "F801"

func (EC3Info) ChanMapString added in v1.30.0

func (e EC3Info) ChanMapString() string

ChanMapString returns the channel names encoded in ChanMap as a space-separated string; e.g. "L C R Ls Rs LFE"

func (EC3Info) MarshalJSON added in v1.30.0

func (e EC3Info) MarshalJSON() ([]byte, error)

MarshalJSON adds an additional chan_map_hex field alongside the numeric chan_map

type InitInfo

type InitInfo struct {
}

type Mp4Info

type Mp4Info struct {
	Errors            []string      // problems found
	FragmentCount     uint64        // total number of fragments
	InitInfo          *InitInfo     // moov
	SampleCount       uint64        // total number of samples/frames
	SampleCountMax    uint64        // most number of samples in a segment
	SampleCountMin    uint64        // least number of samples in a segment
	SampleDurationMax uint64        // longest sample duration
	SampleDurationMin uint64        // shortest sample duration
	Segments          []SegmentInfo //
	Size              uint64        // file size
	Timescale         uint32        //
}

func ValidateFmp4

func ValidateFmp4(reader io.Reader) (file *mp4.File, info *Mp4Info, err error)

func (*Mp4Info) AddError

func (s *Mp4Info) AddError(err string, seg, frag int, pts *uint64)

AddError saves errors for handling at the end of validation. The seg, frag, and pts fields provide a way to conveniently add some context.

func (*Mp4Info) String

func (s *Mp4Info) String() string

type SampleInfo

type SampleInfo struct {
	Duration uint64
	Fragment int
	Pts      uint64
}

type SegmentInfo

type SegmentInfo struct {
	DtsEnd        uint64
	DtsStart      uint64
	FragmentCount uint64
	PtsEnd        uint64
	PtsStart      uint64
	SampleCount   uint64
	Samples       []*SampleInfo
	SeqEnd        uint32
	SeqStart      uint32
}

Jump to

Keyboard shortcuts

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