Implement our own quicktime parser

This commit is contained in:
2024-09-16 22:10:19 +10:00
parent a3013078e0
commit f9cdc8f9d2
42 changed files with 1367 additions and 62 deletions

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Media\QuickTime\Atoms\moov\meta;
// Unused space available in file.
use App\Media\QuickTime\Atoms\SubAtom;
class free extends SubAtom
{
}

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Media\QuickTime\Atoms\moov\meta;
// Item LiST container atom
use App\Media\QuickTime\Atoms\SubAtom;
class ilst extends SubAtom
{
public function __construct(int $offset,int $size,string $filename,?string $data)
{
parent::__construct($offset,$size,$filename);
$ptr = 0;
while ($ptr < strlen($data)) {
$key_size = unpack('Nsize',substr($data,$ptr,4));
// Sometimes atoms are terminated with a 0
if ($key_size['size'] === 0) {
$ptr += 4;
continue;
}
$a = unpack(sprintf('a4name/a%ddata',$key_size['size']-8),substr($data,$ptr+4,4+$key_size['size']-8));
$ptr += $key_size['size'];
// If we didnt get the right amount of data, something is wrong.
if (strlen($a['data']) < $key_size['size']-8)
break;
$b = unpack(sprintf('Nsize/a4name/a%ddata',strlen($a['data'])-8),$a['data']);
if ($b['name'] !== 'data')
throw new \Exception('Parsing of ILST got data that wasnt expected');
$c = unpack(sprintf('a4language/a4unknown/a%ddata',strlen($b['data'])-8),$b['data']);
// heirachy, name, size, offset
$this->cache = $this->cache->push($c['data']);
}
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Media\QuickTime\Atoms\moov\meta;
// The metadata item keys atom holds a list of the metadata keys that may be present in the metadata atom.
// This list is indexed starting with 1; 0 is a reserved index value. The metadata item keys atom is a full atom with an atom type of "keys".
use App\Media\QuickTime\Atoms\SubAtom;
class keys extends SubAtom
{
public function __construct(int $offset,int $size,string $filename,?string $data)
{
parent::__construct($offset,$size,$filename);
$this->keys = collect();
$read = unpack($this->unpack(self::atom_record),substr($data,0,$ptr=$this->unpack_size(self::atom_record)));
for ($i=0; $i<$read['count']; $i++) {
$key_size = unpack('Nsize',substr($data,$ptr,4));
$keys = unpack(sprintf('a4namespace/a%dname',$key_size['size']-8),substr($data,$ptr+4,4+$key_size['size']-8));
$ptr += $key_size['size'];
$this->cache = $this->cache->push(sprintf('%s.%s',$keys['namespace'],$keys['name']));
}
}
}