Exemplo n.º 1
0
 /**
  * Decomposes a file into flv tags while reading. Searches for keyframes
  * 
  * @param string $filename
  * @return Yamdi_InputStream
  */
 protected function read($filename)
 {
     $stream = parent::read($filename);
     $this->filepositions = array();
     $this->times = array();
     $tag = new Yamdi_FlvTag();
     while (!$stream->isEnd()) {
         $tag_position = $stream->getPosition();
         /*
          * Tag
          */
         if (!$tag->read($stream)) {
             break;
         }
         if (!$tag->isValid()) {
             throw new Exception('Invalid tag found');
         }
         if ($tag->isVideo()) {
             if ($tag->checkIfKeyFrame($stream)) {
                 $this->filepositions[] = $tag_position;
                 $this->times[] = $tag->getTimestamp() / 1000.0;
             }
         }
         $tag->skipTagBody($stream);
         // wind forward to next tag
         /*
          * Previous tag size
          */
         $tagSize = new Yamdi_FlvTagSize();
         if (!$tagSize->read($stream)) {
             break;
         }
     }
     return null;
     //nothing else to read
 }
Exemplo n.º 2
0
 /**
  * @deprecated 
  */
 public function testFileRead()
 {
     /*
      * Here we need a real correct flv file
      */
     $stream = new Yamdi_InputStream(dirname(__FILE__) . '/../trailer_2.flv');
     /*
      * Constant header
      */
     $header = new Yamdi_FlvFileHeader();
     $header->read($stream);
     $this->assertEqual(true, $header->isValid());
     /*
      * Constant size of zero tag
      */
     $zeroTagSize = new Yamdi_FlvTagSize();
     $zeroTagSize->read($stream);
     $this->assertEqual(0, $zeroTagSize->size);
     // allways 0
     /*
      * First tag (should be meta)
      */
     $tag = new Yamdi_FlvTag();
     $tag->read($stream);
     $this->assertTrue($tag->isMeta());
     $metadata = new Yamdi_FlvMetadataBody();
     $metadata->read($tag->readTagBody($stream));
     /*
      * Previous tag size
      */
     $tagSize = new Yamdi_FlvTagSize();
     $tagSize->read($stream);
     while (!$stream->isEnd()) {
         $tag_position = $stream->getPosition();
         /*
          * Tag
          */
         if (!$tag->read($stream)) {
             break;
         }
         $this->assertTrue($tag->isValid());
         if ($tag->isVideo()) {
             if ($tag->checkIfKeyFrame($stream)) {
                 $new_filepositions[] = $tag_position;
                 $new_times[] = $tag->getTimestamp() / 1000.0;
             }
         }
         $tag->skipTagBody($stream);
         // wind forward to next tag
         /*
          * Previous tag size
          */
         $tagSize = new Yamdi_FlvTagSize();
         if (!$tagSize->read($stream)) {
             break;
         }
     }
     $this->assertTrue(is_array($new_filepositions));
     $this->assertTrue(count($new_filepositions) > 0);
     $this->assertTrue(is_array($new_times));
     $this->assertTrue(count($new_times) > 0);
     $this->assertEqual(count($new_times), count($new_filepositions));
     /*
      * Cleanup
      */
     $stream->close();
 }