photo/app/Media/QuickTime/Atom.php

63 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2024-09-16 12:10:19 +00:00
<?php
namespace App\Media\QuickTime;
use Illuminate\Support\Collection;
use App\Media\QuickTime;
2024-09-16 12:10:19 +00:00
use App\Media\QuickTime\Atoms\moov\{mvhd,trak};
abstract class Atom extends QuickTime
2024-09-16 12:10:19 +00:00
{
use FindQuicktimeAtoms;
protected int $offset;
protected int $size;
protected string $filename;
protected Collection $atoms;
public function __construct(int $offset,int $size,string $filename)
{
$this->offset = $offset;
// Quick validation
if ($size < 0)
throw new \Exception(sprintf('Atom cannot be negative. (%d)',$size));
$this->size = $size;
$this->filename = $filename;
$this->cache = collect();
}
public function __get(string $key): mixed
{
switch ($key) {
// Create time is in the MOOV/MVHD atom
case 'creation_date':
case 'duration':
case 'preferred_rate':
case 'preferred_volume':
$subatom = $this->find_atoms(mvhd::class,1);
return $subatom->{$key};
// Height is in the moov/trak/tkhd atom
2024-09-16 12:10:19 +00:00
case 'height':
// Width is in the moov/trak/tkhd atom
2024-09-16 12:10:19 +00:00
case 'width':
$atom = $this->find_atoms(trak::class);
return $atom->map(fn($item)=>$item->{$key})
->filter()
->max();
2024-09-16 12:10:19 +00:00
// We need to pass our file handle requests to our parent
case 'fh':
return parent::__get($key);
2024-09-16 12:10:19 +00:00
default:
throw new \Exception('Unknown key: '.$key);
}
}
}