Exemplo n.º 1
0
 /**
  * Convert media according to specifications in $this->outputInfo.
  *
  * @param string $filename - passed by reference because sometimes there is a need to change the filename,
  * 								or otherwise the backend will produce an error
  * @return Naf_Media_Info - information for the newly created
  * @throws Naf_Media_Exception
  */
 function convert(&$filename, $start = 0, $duration = null)
 {
     $c = new Naf_ShellCmd($this->command);
     $format = $this->outputInfo->getFormat();
     if ($format) {
         $ext = substr($filename, strrpos($filename, '.') + 1);
         if ($ext != $format) {
             $filename .= '.' . $format;
         }
     } else {
         $ext = substr($this->source, strrpos($this->source, '.') + 1);
         $filename .= '.' . $ext;
     }
     $c->addOption('-i', $this->source);
     $c->setTarget($filename);
     $c->addOptionIf($start, '-ss', $start);
     $c->addOptionIf($duration, '-t', $duration);
     if (($width = $this->outputInfo->getWidth()) && ($height = $this->outputInfo->getHeight())) {
         $c->addOption('-s', $width . 'x' . $height);
     }
     $bitrate = $this->outputInfo->getBitrate();
     $c->addOptionIf($bitrate, '-b', (int) $bitrate . "k");
     try {
         $c->exec();
     } catch (Naf_Exception $e) {
         throw new Naf_Media_Exception("Ffmpeg call failed: " . $e->getMessage() . "\nCommand: " . $c->getLastCommannd());
     }
     return Naf_Media::reader()->info($filename);
 }
Exemplo n.º 2
0
 /**
  * @param string $filename
  * @param int | string $start
  * @param int | string $duration
  * @return Naf_Media_Info
  * @throws Naf_Media_Exception
  */
 function convert(&$filename, $start = 0, $duration = null)
 {
     $c = new Naf_ShellCmd($this->command);
     if (($width = $this->outputInfo->getWidth()) && ($height = $this->outputInfo->getHeight())) {
         // We have to resize the movie.
         if (!$this->outputInfo->getFormat()) {
             /* Output format not specified. By default, we should use 'copy',
             			but we're not able actually, since if video-stream is copied (not encoded!), 
             			then no scaling will be applied. Force format. */
             $ext = substr($this->source, strrpos($this->source, '.') + 1);
             $this->outputInfo->setFormat($ext);
         }
         $c->addOption('-vf', 'scale=' . $width . ':' . $height);
     }
     $cfg = $this->createConfigurator();
     $filename = $cfg->filename($filename);
     $c->addOption('-o', $filename);
     $cfg->configure($c);
     $c->addOptionIf($start, '-ss', $start);
     $c->addOptionIf($duration, '-endpos', $duration);
     $c->setTarget($this->source);
     try {
         $c->exec();
     } catch (Naf_Exception $e) {
         throw new Naf_Media_Exception("Mplayer call failed: " . $e->getMessage() . "\nCommand: " . $c->getLastCommannd());
     }
     return Naf_Media::reader()->info($filename);
 }
Exemplo n.º 3
0
 protected function assertUnchangedSize(Naf_Media_Info $result)
 {
     $ir = Naf_Media::reader();
     $i = $ir->info($this->source);
     $this->assertEqual($i->getWidth(), $result->getWidth());
     $this->assertEqual($i->getHeight(), $result->getHeight());
 }