API / Minn\Media\Av / Mpeg

Mpeg final class

Minn\Media\Av\Mpeg · public/minn/src/Minn/Media/Av/Mpeg.php · 215 lines

MPEG audio (MP3, and layers 1 and 2) as the reference's audio reader measures it (probe media-meta). The first frame gives the version, layer, sample rate and channels. An Xing or Info frame (written by LAME and most encoders) gives the frame and byte counts: a variable bitrate is the bytes over the frames' duration, and the playing time is the audio's bytes less one average frame, at that bitrate. Without one the bitrate is the first frame's and the playing time is every byte at it.

Constants and properties

privateBITRATES = array ( '3-1' => '32 64 96 128 160 192 224 256 288 320 352 384 416 448', '3-2' => '32 48 56 64 80 96 112 128 160 192 224 256 320 384', '3-3' => '32 40 48 56 64 80 96 112 128 160 192 224 256 320', '2-1' => '32 48 56 64 80 96 112 128 144 160 176 192 224 256', '2-2' => '8 16 24 32 40 48 56 64 80 96 112 128 144 160', )
privateSAMPLE_RATES = array ( 3 => array ( 0 => 44100, 1 => 48000, 2 => 32000, ), 2 => array ( 0 => 22050, 1 => 24000, 2 => 16000, ), 0 => array ( 0 => 11025, 1 => 12000, 2 => 8000, ), )
privateCHANNEL_MODES = array ( 0 => 'stereo', 1 => 'joint stereo', 2 => 'dual channel', 3 => 'mono', )
privateSCAN = 131072
privateSYNC_RUN = 51

How many frames in a row make a place in the data the stream's start, and how many of one rate make it constant (probe media-meta).

Public

staticread(Minn\Media\Av\Source $source, int $start, int $end): ?array#

The audio from $start (after any ID3v2 tag) to $end (before any ID3v1 tag): the stream's description, its bitrate and playing time, and where its frames lie; null when no frame is found.

@return array{audio: array<string, mixed>, bitrate: int|float, playtime_seconds: int|float, avdataoffset: int, avdataend: int}|null
staticframeHeader(int $word): ?array#

A frame header's fields; null for one that is not valid MPEG audio: no sync, a reserved version or layer, a free or bad bitrate, or a reserved sample rate.

@return array{version: int, layer: int, bitrate: int, sampleRate: int, padding: int, mode: int, channels: int, samples: int, length: int}|null
staticscan(Minn\Media\Av\Source $source, int $start, int $end): ?array#

The frames of a stream from an offset to an end, as the reference measures them inside another container (probe media-meta): data that does not begin with a frame has none; the stream starts where 51 frames follow one another (or fewer that run to the end), the first of them its first; when those frames share a rate it is the stream's, and otherwise every frame to the end counts toward the mean, past any bytes between them. Null when no frame is found.

@return array{first: array<string, int>, bitrate: float, variable: bool}|null

Internals 4

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

privatefirstFrame(Minn\Media\Av\Source $source, int $start, int $end): ?int#

Where the first frame starts: a header the next one follows, at or after $start.

privaterun(Minn\Media\Av\Source $source, int $at, int $end, int $most): array#

The rates of the frames that follow one another from an offset, up to a number of them, and where the run stops.

@return array{list<int>, int}
privatenextFrame(Minn\Media\Av\Source $source, int $at, int $end): ?int#

Where the next frame header is from an offset (read a block at a time), or null before the end.

privateinfoFrame(Minn\Media\Av\Source $source, int $offset, array $frame): ?array#

The Xing or Info frame's counts and the LAME tag after them, read from the first frame; null when the first frame is audio.

$framearray<string, int>
@return array<string, mixed>|null