/** * swaps the index from end to beginning * * swaps the index from end to beginning * * @return mixed True if everything wents fine, otherwise error-message as string * @author Benjamin Carl <*****@*****.**> * @version 0.1 * @since Method available since Release 0.1 * @access private */ private function _swapIndex() { $moovSize = $this->_moovBytes->bytesAvailable(); $moovAType = ''; $moovASize = 0; $offsetCount = 0; $compressionCheck = $this->_moovBytes->readBytes(12, 4); if ($compressionCheck == Atom::CMOV_ATOM) { throw new Exception('compressed MP4/QT-file can\'t do this file: ' . $file); } // begin of metadata $metaDataOffsets = array(); $metaDataStrings = array(); $metaDataCurrentLevel = 0; $moovStartOffset = 12; for ($i = $moovStartOffset; $i < $moovSize - $moovStartOffset; $i++) { $moovAType = $this->_moovBytes->readUTFBytes($i, 4); if (Atom::isValidAtom($moovAType)) { $moovASize = $this->_moovBytes->readUnsignedInt($i - 4); if ($moovASize > 8 && $moovASize + $i < $moovSize - $moovStartOffset) { try { $containerLength = 0; $containerString = $moovAType; for ($mi = count($metaDataOffsets) - 1; $mi > -1; $mi--) { $containerLength = $metaDataOffsets[$mi]; if ($i - $moovStartOffset < $containerLength && $i - $moovStartOffset + $moovASize > $containerLength) { throw new Exception('bad atom nested size'); } if ($i - $moovStartOffset == $containerLength) { array_pop($metaDataOffsets); array_pop($metaDataStrings); } else { $containerString = $metaDataStrings[$mi] . "." . $containerString; } } if ($i - $moovStartOffset <= $containerLength) { array_push($metaDataOffsets, $i - $moovStartOffset + $moovASize); array_push($metaDataStrings, $moovAType); } if ($moovAType != Atom::STCO_ATOM && $moovAType != Atom::CO64_ATOM) { $i += 4; } elseif ($moovAType == Atom::URL_ATOM || $moovAType == Atom::XML_ATOM) { $i += $moovASize - 4; } } catch (Exception $e) { echo 'EXCEPTION: ' . $e->getMessage(); } } } if ($moovAType == Atom::STCO_ATOM) { $moovASize = $this->_moovBytes->readUnsignedInt($i - 4); if ($i + $moovASize - $moovStartOffset > $moovSize) { throw new Exception('bad atom size'); return; } $offsetCount = $this->_moovBytes->readUnsignedInt($i + 8); for ($j = 0; $j < $offsetCount; $j++) { $position = $i + 12 + $j * 4; $currentOffset = $this->_moovBytes->readUnsignedInt($position); // cause of mooving the moov-atom right before the rest of data // (behind ftyp) the new offset is caluclated: // current-offset + size of moov atom (box) = new offset $currentOffset += $moovSize; $this->_moovBytes->writeBytes(Transform::toUInt32BE($currentOffset), $position + 1); } $i += $moovASize - 4; } else { if ($moovAType == Atom::CO64_ATOM) { $moovASize = $this->_moovBytes->readUnsignedInt($i - 4); if ($i + $moovASize - $moovStartOffset > $moovSize) { throw new Exception('bad atom size'); return; } $offsetCount = $this->_moovBytes->readDouble($i + 8); for ($j2 = 0; $j2 < $offsetCount; $j2++) { $position = $i + 12 + $j * 8; $currentOffset = $this->_moovBytes->readUnsignedInt($position); // cause of mooving the moov-atom right before the rest of data // (behind ftyp) the new offset is caluclated: // current-offset + size of moov atom (box) = new offset $currentOffset += $moovSize; // TODO implement! //$this->_moovBytes->writeBytes(Transform::toUInt64BE($currentOffset), $position+1); } $i += $moovASize - 4; } } } return true; }