Example #1
0
 private function retrieveHelpOutput()
 {
     $id = 'help';
     if ($this->cache->contains($id)) {
         return $this->cache->fetch($id);
     }
     try {
         $output = $this->ffprobe->command(array('-help', '-loglevel', 'quiet'));
     } catch (ExecutionFailureException $e) {
         throw new RuntimeException('Your FFProbe version is too old and does not support `-help` option, please upgrade.', $e->getCode(), $e);
     }
     $this->cache->save($id, $output);
     return $output;
 }
Example #2
0
 private function probe($pathfile, $command, $type, $allowJson = true)
 {
     $id = sprintf('%s-%s', $command, $pathfile);
     if ($this->cache->contains($id)) {
         return $this->cache->fetch($id);
     }
     if (!$this->optionsTester->has($command)) {
         throw new RuntimeException(sprintf('This version of ffprobe is too old and ' . 'does not support `%s` option, please upgrade', $command));
     }
     $commands = array($pathfile, $command);
     $parseIsToDo = false;
     if ($allowJson && $this->optionsTester->has('-print_format')) {
         // allowed in latest PHP-FFmpeg version
         $commands[] = '-print_format';
         $commands[] = 'json';
     } elseif ($allowJson && $this->optionsTester->has('-of')) {
         // option has changed in avconv 9
         $commands[] = '-of';
         $commands[] = 'json';
     } else {
         $parseIsToDo = true;
     }
     try {
         $output = $this->ffprobe->command($commands);
     } catch (ExecutionFailureException $e) {
         throw new RuntimeException(sprintf('Unable to probe %s', $pathfile), $e->getCode(), $e);
     }
     if ($parseIsToDo) {
         $data = $this->parser->parse($type, $output);
     } else {
         try {
             // Malformed json may be retrieved
             $data = $this->parseJson($output);
         } catch (RuntimeException $e) {
             return $this->probe($pathfile, $command, $type, false);
         }
     }
     $ret = $this->mapper->map($type, $data);
     $this->cache->save($id, $ret);
     return $ret;
 }
 /**
  * @expectedException FFMpeg\Exception\ExecutableNotFoundException
  */
 public function testCreateFailureThrowsAnException()
 {
     FFProbeDriver::create(array('ffprobe.binaries' => '/path/to/nowhere'));
 }