diff --git a/src/main/php/de/thekid/dialog/processing/Atoms.php b/src/main/php/de/thekid/dialog/processing/Atoms.php index b7e1660..2670d9a 100755 --- a/src/main/php/de/thekid/dialog/processing/Atoms.php +++ b/src/main/php/de/thekid/dialog/processing/Atoms.php @@ -5,52 +5,48 @@ /** @see https://developer.apple.com/documentation/quicktime-file-format/movie_atoms */ class Atoms { - private $parsers; + private $parsers= [ + 'moov.mvhd' => function($f, $atom) { - public function __construct() { - $this->parsers= [ - 'moov.mvhd' => function($f, $atom) { - - // See https://developer.apple.com/documentation/quicktime-file-format/movie_header_atom - return unpack('cversion/c3flags/Ncreated/Nmodified/Nscale/Nduration', $f->read(20)); - }, - 'moov.meta.keys' => function($f, $atom) { - $r= []; - $info= unpack('cversion/c3flags/Ncount', $f->read(8)); - for ($i= 0; $i < $info['count']; $i++) { - $entry= unpack('Nsize/a4ns', $f->read(8)); - $r[$i + 1]= $entry['ns'].':'.$f->read($entry['size'] - 8); - } - return $r; - }, - 'moov.meta.ilst' => function($f, $atom) { - $r= []; - foreach ($this->atoms($f, $atom) as $child) { - $index= unpack('N', $child['name'])[1]; - $r[$index]= []; - foreach ($this->atoms($f, $child) as $data) { - $entry= unpack('Ntype/a4locale', $f->read(8)); - $bytes= $f->read($data['length'] - 16); + // See https://developer.apple.com/documentation/quicktime-file-format/movie_header_atom + return unpack('cversion/c3flags/Ncreated/Nmodified/Nscale/Nduration', $f->read(20)); + }, + 'moov.meta.keys' => function($f, $atom) { + $r= []; + $info= unpack('cversion/c3flags/Ncount', $f->read(8)); + for ($i= 0; $i < $info['count']; $i++) { + $entry= unpack('Nsize/a4ns', $f->read(8)); + $r[$i + 1]= $entry['ns'].':'.$f->read($entry['size'] - 8); + } + return $r; + }, + 'moov.meta.ilst' => function($f, $atom) { + $r= []; + foreach ($this->atoms($f, $atom) as $child) { + $index= unpack('N', $child['name'])[1]; + $r[$index]= []; + foreach ($this->atoms($f, $child) as $data) { + $entry= unpack('Ntype/a4locale', $f->read(8)); + $bytes= $f->read($data['length'] - 16); - // See https://developer.apple.com/documentation/quicktime-file-format/value_atom - $r[$index][]= match ($entry['type']) { - 1 => $bytes, // yield utf-8 as-is - default => new Bytes($bytes) - }; - } + // See https://developer.apple.com/documentation/quicktime-file-format/value_atom + $r[$index][]= match ($entry['type']) { + 1 => $bytes, // yield utf-8 as-is + default => new Bytes($bytes) + }; } - return $r; - }, - "moov.udta.\251xyz" => function($f, $atom) { - $entry= unpack('nsize/ntype', $f->read(4)); - preg_match_all('/[+-][0-9.]+/', $f->read($entry['size'] - 1), $c); - return $c[0]; - }, - 'moov.udta.*' => function($f, $atom) { - return new Data($f, $atom['offset'] + 8, $atom['length'] - 8); - }, - ]; - } + } + return $r; + }, + "moov.udta.\251xyz" => function($f, $atom) { + $entry= unpack('nsize/ntype', $f->read(4)); + preg_match_all('/[+-][0-9.]+/', $f->read($entry['size'] - 1), $c); + return $c[0]; + }, + 'moov.udta.*' => function($f, $atom) { + return new Data($f, $atom['offset'] + 8, $atom['length'] - 8); + }, + ]; private function atom($f, $base= null) { $atom= ['offset' => $f->tell(), 'path' => $base] + unpack('Nlength/a4name', $f->read(8));