# danog\MadelineProto\Mp4: 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](https://core.telegram.org/api/group-calls#stream-mode) and by every live/DASH
encoder) and progressive files whose `moov` precedes the `mdat` are supported. A progressive file
with the `moov` at the end (like the chunks of an RTMP livestream) is only supported if small: its
`mdat` is buffered until the `moov` describes it.

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.


[Back to index](../../index.html)

> 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](https://core.telegram.org/api/group-calls#stream-mode) and by every live/DASH
encoder) and progressive files whose `moov` precedes the `mdat` are supported. A progressive file
with the `moov` at the end (like the chunks of an RTMP livestream) is only supported if small: its
`mdat` is buffered until the `moov` describes it.

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::MOOV_AT_END`: The error of a progressive file whose moov follows a big mdat, which can't be read sequentially.

* `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:
* [`__construct(\danog\MadelineProto\LocalFile|\danog\MadelineProto\RemoteUrl|\Amp\ByteStream\ReadableStream $stream, ?\Amp\Cancellation $cancellation = NULL)`](#__construct)
* [`hasCodec(string $codec): bool`](#hasCodec)

## Methods:
### <a name="__construct"></a> `__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: 
* [`\danog\MadelineProto\LocalFile`: Indicates a local file to upload.](../../danog/MadelineProto/LocalFile.html)
* [`\danog\MadelineProto\RemoteUrl`: Indicates a remote URL to upload.](../../danog/MadelineProto/RemoteUrl.html)
* `\Amp\ByteStream\ReadableStream`
* `\Amp\Cancellation`




### <a name="hasCodec"></a> `hasCodec(string $codec): bool`

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


Parameters:

* `$codec`: `string`   



---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
