Пример #1
0
	function getMetadata( $image, $path ) {
		$metadata = array( 'version' => self::METADATA_VERSION );

		if ( !class_exists( 'File_Ogg' ) ) {
			require( 'File/Ogg.php' );
		}
		try {
			$f = new File_Ogg( $path );
			$streams = array();
			foreach ( $f->listStreams() as $streamIDs ) {
				foreach ( $streamIDs as $streamID ) {
					$stream = $f->getStream( $streamID );
					$streams[$streamID] = array(
						'serial' => $stream->getSerial(),
						'group' => $stream->getGroup(),
						'type' => $stream->getType(),
						'vendor' => $stream->getVendor(),
						'length' => $stream->getLength(),
						'size' => $stream->getSize(),
						'header' => $stream->getHeader(),
						'comments' => $stream->getComments()
					);
				}
			}
			$metadata['streams'] = $streams;
			$metadata['length'] = $f->getLength();
			// Get the offset of the file (in cases where the file is a segment copy)
			$metadata['offset'] = $f->getStartOffset();
		} catch ( PEAR_Exception $e ) {
			// File not found, invalid stream, etc.
			$metadata['error'] = array(
				'message' => $e->getMessage(),
				'code' => $e->getCode()
			);
		}
		return serialize( $metadata );
	}
Пример #2
0
 function loadMeta()
 {
     //load from the file:
     if (is_file($this->oggPath . OGGCHOP_META_EXT)) {
         $oggMeta = file_get_contents($this->oggPath . OGGCHOP_META_EXT);
         //check if a separate request is working on generating the file:
         if (trim($oggMeta) == 'loading') {
             if ($this->loadWaitCount >= 24) {
                 //we have waited 2 min with no luck..
                 //@@todo we should flag that ogg file as broken?
                 // and just redirect to normal output? (for now just set meta to false)
                 $this->meta = false;
                 //fail:
                 return false;
             } else {
                 //some other request is "loading" metadata sleep for 5 seconds and try again
                 sleep(5);
                 $this->loadWaitCount++;
                 return $this->loadMeta();
             }
         } else {
             $this->meta = unserialize($oggMeta);
             if ($this->meta['version'] == 'OGGCHOP_META_VERSION') {
                 //we have a good version of the metadata return true:
                 return true;
             } else {
                 $this->meta = false;
             }
         }
     }
     //if the file does not exist or $this->meta is still false::
     if (!is_file($this->oggPath . OGGCHOP_META_EXT) || $this->meta === false) {
         //set the meta file to "loading" (avoids multiple indexing requests)
         file_put_contents($this->oggPath . OGGCHOP_META_EXT, 'loading');
         //load up the File/Ogg Pear module
         if (!class_exists('File_Ogg')) {
             require 'File/Ogg.php';
         }
         $f = new File_Ogg($this->oggPath);
         $streams = array();
         $this->meta = array('version' => OGGCHOP_META_VERSION);
         foreach ($f->listStreams() as $streamType => $streamIDs) {
             foreach ($streamIDs as $streamID) {
                 $stream = $f->getStream($streamID);
                 //for now only support a fist theora stream we find:
                 if (strtolower($stream->getType()) == 'theora') {
                     $this->meta['theoraKeyFrameInx'] = $stream->getKeyFrameIndex();
                     //set the width and height:
                     $head = $stream->getHeader();
                     $this->meta['width'] = $head['PICW'];
                     $this->meta['height'] = $head['PICH'];
                     break;
                 }
                 /* more detailed per-stream metadata::
                 			 * $this->meta['streams'][$streamID] = array(
                 				'serial' => $stream->getSerial(),
                 				'group' => $stream->getGroup(),
                 				'type' => $stream->getType(),
                 				'vendor' => $stream->getVendor(),
                 				'length' => $stream->getLength(),
                 				'size' => $stream->getSize(),
                 				'header' => $stream->getHeader(),
                 				'comments' => $stream->getComments()
                 			);*/
             }
         }
         $this->meta['duration'] = $f->getLength();
         //cache the metadata::
         file_put_contents($this->oggPath . OGGCHOP_META_EXT, serialize($this->meta));
         return true;
     }
 }