Documentation
¶
Index ¶
- func DecryptFile(src, dst string, scheme CryptScheme, key, iv []byte, initSeg ...string) error
- func DecryptReader(r io.Reader, scheme CryptScheme, key, iv []byte) (io.Reader, error)
- func LevelName(codecID string, levelIDC int) string
- func ProfileName(codecID string, profileIDC int) string
- type CodecInfo
- type CryptScheme
- type EC3Info
- type InitInfo
- type Mp4Info
- type SampleInfo
- type SegmentInfo
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
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
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
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
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
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
ChanMapHex returns ChanMap as an uppercase hex string; e.g. "F801"
func (EC3Info) ChanMapString ¶ added in v1.30.0
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
MarshalJSON adds an additional chan_map_hex field alongside the numeric chan_map
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 //
}