API / Minn\Media\Av / IsoMedia

IsoMedia final class

Minn\Media\Av\IsoMedia · public/minn/src/Minn/Media/Av/IsoMedia.php · 364 lines

MPEG-4 and QuickTime files (MP4, M4A, M4V, MOV) as the reference's media reader measures them (probe media-meta). The movie header gives the playing time and the time it was made; each track's first sample entry gives its codec. Only AAC ("mp4a") is read as audio, and it alone makes a file audio/mp4 (or video/mp4 beside a video track); anything else is video/quicktime. A video entry with a vendor is read the QuickTime way (its compressor's name, lossless false); one without, the ISO way (a named codec, and "mp4" as the format for the codecs it knows). Only H.264 and MPEG-4 video have the bitrate the audio leaves.

Uses 1
Used by 1

Constants and properties

privateVIDEO = 'avc1=H.264/MPEG-4 AVC|cvid=Cinepak|dvc =DVC-NTSC|dvcp=DVC-PAL|gif =GIF|h263=H263|hvc1=H.265/HEVC|jpeg=JPEG|kpcd=PhotoCD|mjpa=Motion JPEG-A|mjpb=Motion JPEG-B|mp4v=|png =PNG|raw =RAW|rle =|rpza=Video|smc =Graphics|SVQ1=Sorenson Video 3|SVQ3=Sorenson Video 3 (Apple Quicktime 5)|tiff=TIFF|v216=|v308=|v408=|v410=|yuv2=ComponentVideo'

Video codecs the ISO way names, and makes a file "mp4" for (code => name, empty for none).

privateDATAFORMATS = array ( 'mp4v' => 'mpeg4', '3IV1' => '3ivx', '3IV2' => '3ivx', '3ivx' => '3ivx', 'DIVX' => 'divx', 'divx' => 'divx', 'DIV3' => 'divx', 'div3' => 'divx', 'XVID' => 'xvid', 'xvid' => 'xvid', )
privateCONTAINERS = array ( 0 => 'moov', 1 => 'trak', 2 => 'mdia', 3 => 'minf', 4 => 'stbl', 5 => 'udta', 6 => 'ilst', 7 => 'covr', )
privateEPOCH = 2082844800

Seconds between 1904, where the movie's clock starts, and 1970.

privateMOOV_LIMIT = 67108864
privateBOX_LIMIT = 4096

The most boxes read at one level (the file's, or a container's).

Public

staticdetects(string $head): bool#

Whether a file's first bytes are an MPEG-4 or QuickTime box.

staticread(Minn\Media\Av\Source $source): array#

The file's analysis: format, type, playing time and bitrate, the audio and video streams, the movie header for its creation time and the cover.

@return array<string, mixed>

Internals 13

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatemovie(Minn\Media\Av\Source $source): array#

The movie box's bytes (null when there is none, or it is too large to read) and where the first media data begins.

@return array{moov: ?string, dataStart: ?int}
privateboxHeader(string $bytes, int $room): array#

A box's size, type and header length from its first bytes; a size of 0 runs to $room, a size of 1 is the 64-bit size that follows.

@return array{0: int, 1: string, 2: int}
privatechildren(string $bytes, int $start, int $end): array#

The boxes inside a run of bytes, each with its body's place.

@return list<array{type: string, start: int, end: int}>
privatefind(string $bytes, array $boxes, array $path): ?array#

The first box of a type along a path of containers, or null.

$boxeslist<array{type: string, start: int, end: int}>
$pathlist<string>
@return array{type: string, start: int, end: int}|null
privatemovieHeader(string $bytes, array $moov): ?array#

The movie header's timescale, duration and creation time.

$moovlist<array{type: string, start: int, end: int}>
@return array{timescale: int, duration: int, created: int}|null
privatetrack(string $bytes, array $trak): array#

A track's size (from its header) and its first sample entry, read as audio or video.

$trakarray{type: string, start: int, end: int}
@return array{entry: array<string, mixed>|null}
privateaac(string $entry): array#

An AAC sample entry's stream: its rate and channels as the version 0 layout places them (whatever the version), and the average bitrate an elementary stream descriptor directly inside it gives.

@return array<string, mixed>
privateaverageBitrate(string $esds): ?int#

The average bitrate an elementary stream descriptor's decoder configuration gives; null without one.

privateafterLength(string $bytes, int $at): int#

Where a descriptor's body starts, after its length of one to four bytes.

privatevideoEntry(string $entry, array $trackSize): array#

A video sample entry read the QuickTime way (it names a vendor) or the ISO way.

$trackSizearray{0: float, 1: float}
@return array<string, mixed>
privatecover(string $bytes, array $moov): ?array#

The cover an iTunes tag list holds: its bytes and type.

$moovlist<array{type: string, start: int, end: int}>
@return array<string, mixed>|null
privateordered(array $video): array#

A video stream's fields in the order the reference keeps them.

$videoarray<string, mixed>
@return array<string, mixed>
privatevideoCodecs(): array#
@return array<string, string> code => name