Example #1
0
 public function register()
 {
     $this->opo_config = Configuration::load();
     $vs_external_app_config_path = $this->opo_config->get('external_applications');
     $this->opo_external_app_config = Configuration::load($vs_external_app_config_path);
     $this->ops_path_to_ffmpeg = $this->opo_external_app_config->get('ffmpeg_app');
     $this->ops_mediainfo_path = caGetExternalApplicationPath('mediainfo');
     $this->opb_mediainfo_available = caMediaInfoInstalled();
     $this->opb_ffmpeg_available = caMediaPluginFFmpegInstalled($this->ops_path_to_ffmpeg);
     $this->info["INSTANCE"] = $this;
     return $this->info;
 }
Example #2
0
 /** 
  *
  */
 public function writeClip($ps_filepath, $ps_start, $ps_end, $pa_options = null)
 {
     if (!caMediaPluginFFmpegInstalled()) {
         return false;
     }
     $o_tc = new TimecodeParser();
     $vn_start = $vn_end = null;
     if ($o_tc->parse($ps_start)) {
         $vn_start = $o_tc->getSeconds();
     }
     if ($o_tc->parse($ps_end)) {
         $vn_end = $o_tc->getSeconds();
     }
     if (!$vn_start || !$vn_end) {
         return null;
     }
     if ($vn_start >= $vn_end) {
         return null;
     }
     $vn_duration = $vn_end - $vn_start;
     exec(caGetExternalApplicationPath('ffmpeg') . " -i " . caEscapeShellArg($this->filepath) . " -f mp4 -vcodec libx264 -acodec mp3 -t {$vn_duration}  -y -ss {$vn_start} " . caEscapeShellArg($ps_filepath) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
     if ($vn_return != 0) {
         @unlink($ps_filepath);
         $this->postError(1610, _t("Error extracting clip from %1 to %2: %3", $ps_start, $ps_end, join("; ", $va_output)), "WLPlugVideo->writeClip()");
         return false;
     }
     return true;
 }
Example #3
0
 public function write($filepath, $mimetype, $pa_options = null)
 {
     if (!$this->handle) {
         return false;
     }
     if (!($ext = $this->info["EXPORT"][$mimetype])) {
         # this plugin can't write this mimetype
         return false;
     }
     # is mimetype valid?
     switch ($mimetype) {
         # ------------------------------------
         case 'image/jpeg':
             $vn_preview_width = $this->properties["width"];
             $vn_preview_height = $this->properties["height"];
             if (caMediaPluginFFmpegInstalled($this->ops_path_to_ffmpeg)) {
                 if (($vn_start_secs = $this->properties["duration"] / 8) > 120) {
                     $vn_start_secs = 120;
                     // always take a frame from the first two minutes to ensure performance (ffmpeg gets slow if it has to seek far into a movie to extract a frame)
                 }
                 exec($this->ops_path_to_ffmpeg . " -ss " . $vn_start_secs . " -i " . caEscapeShellArg($this->filepath) . " -f mjpeg -t 0.001 -y " . caEscapeShellArg($filepath . "." . $ext) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
                 if ($vn_return < 0 || $vn_return > 1 || !@filesize($filepath . "." . $ext)) {
                     @unlink($filepath . "." . $ext);
                     // don't throw error as ffmpeg cannot generate frame still from all files
                 } else {
                     // resize image to desired dimensions
                     $o_media = new Media();
                     $o_media->read($filepath . "." . $ext);
                     $o_media->transform('SCALE', array('width' => $vn_preview_width, 'height' => $vn_preview_height, 'mode' => 'bounding_box', 'antialiasing' => 0.5));
                     $o_media->write($filepath . "_tmp", 'image/jpeg', array());
                     if (!$o_media->numErrors()) {
                         rename($filepath . "_tmp." . $ext, $filepath . "." . $ext);
                     } else {
                         @unlink($filepath . "_tmp." . $ext);
                     }
                 }
             }
             // if output file doesn't exist, ffmpeg failed or isn't installed
             // so use default icons
             if (!file_exists($filepath . "." . $ext)) {
                 return __CA_MEDIA_VIDEO_DEFAULT_ICON__;
             }
             $this->properties["mimetype"] = $mimetype;
             $this->properties["typename"] = isset($this->typenames[$mimetype]) ? $this->typenames[$mimetype] : $mimetype;
             break;
             # ------------------------------------
         # ------------------------------------
         default:
             if ($mimetype != $this->handle["mime_type"]) {
                 # this plugin can't write this mimetype (no conversions allowed)
                 $this->postError(1610, _t("Can't convert '%1' to %2", $this->handle["mime_type"], $mimetype), "WLPlugQuicktimeVR->write()");
                 return false;
             }
             # write the file
             if (!copy($this->filepath, $filepath . "." . $ext)) {
                 $this->postError(1610, _t("Couldn't write file to '%1'", $filepath), "WLPlugQuicktimeVR->write()");
                 return false;
             }
             break;
             # ------------------------------------
     }
     return $filepath . "." . $ext;
 }