Link Search Menu Expand Document

danog\MadelineProto\Mp4

Back to index

Author: Daniil Gentili daniil@daniil.it

A pure PHP MP4 (ISO base media file format) demuxer, with the same shape as {@see Matroska}: it

reads the file sequentially and yields its encoded frames, one at a time, with their track, codec (as a Matroska codec ID, so they can be muxed by {@see MatroskaWriter} as they are), type, timestamp and keyframe flag.

Both fragmented files (moov with mvex, then moof+mdat pairs, as served for group calls in stream mode and by every live/DASH encoder) and progressive files whose moov precedes the mdat are supported. Progressive files with the moov at the end cannot be demuxed sequentially.

Supported codecs: H.264 (avc1/avc3), H.265 (hvc1/hev1), VP9 (vp09), AV1 (av01), AAC (mp4a) and Opus (Opus). Video samples keep the length-prefixed NAL units of the file, which is also what Matroska expects.

Constants

  • danog\MadelineProto\Mp4::TRACK_TYPE_VIDEO:

  • danog\MadelineProto\Mp4::TRACK_TYPE_AUDIO:

Properties

  • $frames: iterable<array{track: int, codec: string, type: int, data: string, timestamp: int, keyframe: bool}> The frames of the file, in file order.

Each entry is ['track' => int, 'codec' => string, 'type' => int, 'data' => string, 'timestamp' => int (ms), 'keyframe' => bool], like {@see Matroska::$frames}.

  • $tracks: array<int, array{codec: string, type: int, private: ?string, width: int, height: int, rate: int, channels: int, timescale: int}> The tracks of the file, by track ID: codec (a Matroska codec ID), type, private (the Matroska CodecPrivate: avcC/hvcC/vpcC/av1C, the AAC AudioSpecificConfig, or an OpusHead), the video width/height, the audio rate/channels, and the media timescale.

Method list:

Methods:

__construct(\danog\MadelineProto\LocalFile|\danog\MadelineProto\RemoteUrl|\Amp\ByteStream\ReadableStream $stream, ?\Amp\Cancellation $cancellation = NULL)

Parameters:

  • $stream: \danog\MadelineProto\LocalFile|\danog\MadelineProto\RemoteUrl|\Amp\ByteStream\ReadableStream
  • $cancellation: ?\Amp\Cancellation

See also:

hasCodec(string $codec): bool

Whether the file has a track with the given (Matroska) codec ID.

Parameters:

  • $codec: string

Generated by danog/phpdoc