atoms = $this->get_atoms(self::atom_classes,Unknown::class,0,$this->filesize); } public function __get(string $key): mixed { switch ($key) { case 'audio_channels': case 'audio_codec': case 'audio_samplerate': return $this->getAudioAtoms() ->map(fn($item)=>$item->find_atoms(moov\trak\mdia\minf\stbl\stsd::class,1)) ->flatten() ->map(fn($item)=>$item->{$key}) ->join(','); // Signatures are calculated by the sha of the MDAT atom. case 'signature': if (! $this->cache->has('signature')) { $hash = NULL; foreach ($this->find_atoms(mdat::class) as $atom) $hash = $atom->signature('sha1',$hash,TRUE); $this->cache->put('signature',hash_final($hash)); } return $this->cache->get('signature'); // Creation Time is in the MOOV/MVHD atom case 'creation_date': case 'duration': case 'preferred_rate': case 'preferred_volume': // Height/Width is in the moov/trak/tkhd atom case 'height': case 'width': $atom = $this->find_atoms(moov::class,1); return $atom->{$key}; case 'gps_altitude': case 'gps_lat': case 'gps_lon': $atom = $this->find_atoms(moov::class,1) ->find_atoms(moov\meta::class,1); return $atom->{$key}; case 'make': case 'model': case 'software': return $this->find_atoms(moov\meta::class,1)->{$key}; case 'time_scale': $atom = $this->find_atoms(moov\mvhd::class,1); return $atom->{$key}; case 'fh': case 'type': return parent::__get($key); case 'video_codec': return $this->getVideoAtoms() ->map(fn($item)=>$item->find_atoms(moov\trak\mdia\minf\stbl\stsd::class,1)) ->flatten() ->map(fn($item)=>$item->{$key}) ->join(','); case 'video_framerate': $atom = $this->getVideoAtoms() ->map(fn($item)=>$item->find_atoms(moov\trak\mdia\minf\stbl\stts::class,1)) ->pop(); return $atom->frame_rate($this->time_scale); default: throw new \Exception('Unknown key: '.$key); } } /** * Find all the audio track atoms * * Audio atoms are in moov/trak/mdia/minf * * @return Collection * @throws \Exception */ public function getAudioAtoms(): Collection { return $this->find_atoms(moov\trak\mdia\minf::class) ->filter(fn($item)=>$item->type==='soun'); } /** * Find all the video track atoms * * Audio atoms are in moov/trak/mdia/minf * * @return Collection * @throws \Exception */ public function getVideoAtoms(): Collection { return $this->find_atoms(moov\trak\mdia\minf::class) ->filter(fn($item)=>$item->type==='vide'); } }