Ejemplo n.º 1
0
 /**
  * Create a merged list of all allowed photo and movie extensions.
  */
 static function get_extensions()
 {
     $extensions = legal_file::get_photo_extensions();
     if (movie::find_ffmpeg()) {
         $extensions = array_merge($extensions, legal_file::get_movie_extensions());
     }
     return $extensions;
 }
Ejemplo n.º 2
0
 public function render()
 {
     $v = new View("form_uploadify.html");
     $v->album = $this->data["album"];
     $v->script_data = $this->data["script_data"];
     $v->simultaneous_upload_limit = module::get_var("gallery", "simultaneous_upload_limit");
     $v->movies_allowed = (bool) movie::find_ffmpeg();
     $v->suhosin_session_encrypt = (bool) ini_get("suhosin.session.encrypt");
     return $v;
 }
Ejemplo n.º 3
0
 private function _print_view($form)
 {
     list($ffmpeg_version, $ffmpeg_date) = movie::get_ffmpeg_version();
     $ffmpeg_version = $ffmpeg_date ? "{$ffmpeg_version} ({$ffmpeg_date})" : $ffmpeg_version;
     $ffmpeg_path = movie::find_ffmpeg();
     $ffmpeg_dir = substr($ffmpeg_path, 0, strrpos($ffmpeg_path, "/"));
     $view = new Admin_View("admin.html");
     $view->page_title = t("Movies settings");
     $view->content = new View("admin_movies.html");
     $view->content->form = $form;
     $view->content->ffmpeg_dir = $ffmpeg_dir;
     $view->content->ffmpeg_version = $ffmpeg_version;
     print $view;
 }
 static function get_movie_time($item)
 {
     $ffmpeg = movie::find_ffmpeg();
     if (empty($ffmpeg)) {
         return t("00:00");
     }
     $cmd = escapeshellcmd($ffmpeg) . " -i " . escapeshellarg($item->file_path()) . " 2>&1";
     $result = `{$cmd}`;
     if (preg_match("/Duration: (\\d+):(\\d+):(\\d+\\.\\d+)/", $result, $regs)) {
         return 3600 * $regs[1] + 60 * $regs[2] + $regs[3];
     } else {
         if (preg_match("/duration.*?:.*?(\\d+)/", $result, $regs)) {
             return $regs[1];
         } else {
             return '00';
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Return the width, height, mime_type and extension of the given movie file.
  */
 static function get_file_metadata($file_path)
 {
     $ffmpeg = movie::find_ffmpeg();
     if (empty($ffmpeg)) {
         throw new Exception("@todo MISSING_FFMPEG");
     }
     $cmd = escapeshellcmd($ffmpeg) . " -i " . escapeshellarg($file_path) . " 2>&1";
     $result = `{$cmd}`;
     if (preg_match("/Stream.*?Video:.*?, (\\d+)x(\\d+)/", $result, $regs)) {
         list($width, $height) = array($regs[1], $regs[2]);
     } else {
         list($width, $height) = array(0, 0);
     }
     $pi = pathinfo($file_path);
     $extension = isset($pi["extension"]) ? $pi["extension"] : "flv";
     // No extension?  Assume FLV.
     $mime_type = in_array(strtolower($extension), array("mp4", "m4v")) ? "video/mp4" : "video/x-flv";
     return array($width, $height, $mime_type, $extension);
 }
Ejemplo n.º 6
0
 /**
  * Return the width, height, mime_type, extension and duration of the given movie file.
  * Metadata is first generated using ffmpeg (or set to defaults if it fails),
  * then can be modified by other modules using movie_get_file_metadata events.
  *
  * This function and its use cases are symmetric to those of photo::get_file_metadata.
  *
  * @param  string $file_path
  * @return array  array($width, $height, $mime_type, $extension, $duration)
  *
  * Use cases in detail:
  *   Input is standard movie type (flv/mp4/m4v)
  *     -> return metadata from ffmpeg
  *   Input is *not* standard movie type that is supported by ffmpeg (e.g. avi, mts...)
  *     -> return metadata from ffmpeg
  *   Input is *not* standard movie type that is *not* supported by ffmpeg but is legal
  *     -> return zero width, height, and duration; mime type and extension according to legal_file
  *   Input is illegal, unidentifiable, unreadable, or does not exist
  *     -> throw exception
  * Note: movie_get_file_metadata events can change any of the above cases (except the last one).
  */
 static function get_file_metadata($file_path)
 {
     if (!is_readable($file_path)) {
         throw new Exception("@todo UNREADABLE_FILE");
     }
     $metadata = new stdClass();
     $ffmpeg = movie::find_ffmpeg();
     if (!empty($ffmpeg)) {
         // ffmpeg found - use it to get width, height, and duration.
         $cmd = escapeshellcmd($ffmpeg) . " -i " . escapeshellarg($file_path) . " 2>&1";
         $result = `{$cmd}`;
         if (preg_match("/Stream.*?Video:.*?, (\\d+)x(\\d+)/", $result, $matches_res)) {
             if (preg_match("/Stream.*?Video:.*? \\[.*?DAR (\\d+):(\\d+).*?\\]/", $result, $matches_dar) && $matches_dar[1] >= 1 && $matches_dar[2] >= 1) {
                 // DAR is defined - determine width based on height and DAR
                 // (should always be int, but adding round to be sure)
                 $matches_res[1] = round($matches_res[2] * $matches_dar[1] / $matches_dar[2]);
             }
             list($metadata->width, $metadata->height) = array($matches_res[1], $matches_res[2]);
         } else {
             list($metadata->width, $metadata->height) = array(0, 0);
         }
         if (preg_match("/Duration: (\\d+:\\d+:\\d+\\.\\d+)/", $result, $matches)) {
             $metadata->duration = movie::hhmmssdd_to_seconds($matches[1]);
         } else {
             if (preg_match("/duration.*?:.*?(\\d+)/", $result, $matches)) {
                 $metadata->duration = $matches[1];
             } else {
                 $metadata->duration = 0;
             }
         }
     } else {
         // ffmpeg not found - set width, height, and duration to zero.
         $metadata->width = 0;
         $metadata->height = 0;
         $metadata->duration = 0;
     }
     $extension = pathinfo($file_path, PATHINFO_EXTENSION);
     if (!$extension || !($metadata->mime_type = legal_file::get_movie_types_by_extension($extension))) {
         // Extension is empty or illegal.
         $metadata->extension = null;
         $metadata->mime_type = null;
     } else {
         // Extension is legal (and mime is already set above).
         $metadata->extension = strtolower($extension);
     }
     // Run movie_get_file_metadata events which can modify the class.
     module::event("movie_get_file_metadata", $file_path, $metadata);
     // If the post-events results are invalid, throw an exception.  Note that, unlike photos, having
     // zero width and height isn't considered invalid (as is the case when FFmpeg isn't installed).
     if (!$metadata->mime_type || !$metadata->extension || $metadata->mime_type != legal_file::get_movie_types_by_extension($metadata->extension)) {
         throw new Exception("@todo ILLEGAL_OR_UNINDENTIFIABLE_FILE");
     }
     return array($metadata->width, $metadata->height, $metadata->mime_type, $metadata->extension, $metadata->duration);
 }
Ejemplo n.º 7
0
 /**
  * Return the width, height, mime_type, extension and duration of the given movie file.
  */
 static function get_file_metadata($file_path)
 {
     $ffmpeg = movie::find_ffmpeg();
     if (empty($ffmpeg)) {
         throw new Exception("@todo MISSING_FFMPEG");
     }
     $cmd = escapeshellcmd($ffmpeg) . " -i " . escapeshellarg($file_path) . " 2>&1";
     $result = `{$cmd}`;
     if (preg_match("/Stream.*?Video:.*?, (\\d+)x(\\d+)/", $result, $matches_res)) {
         if (preg_match("/Stream.*?Video:.*? \\[.*?DAR (\\d+):(\\d+).*?\\]/", $result, $matches_dar) && $matches_dar[1] >= 1 && $matches_dar[2] >= 1) {
             // DAR is defined - determine width based on height and DAR
             // (should always be int, but adding round to be sure)
             $matches_res[1] = round($matches_res[2] * $matches_dar[1] / $matches_dar[2]);
         }
         list($width, $height) = array($matches_res[1], $matches_res[2]);
     } else {
         list($width, $height) = array(0, 0);
     }
     $extension = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
     $extension = $extension ? $extension : "flv";
     // No extension?  Assume FLV.
     $mime_type = legal_file::get_movie_types_by_extension($extension);
     $mime_type = $mime_type ? $mime_type : "video/x-flv";
     // No MIME found?  Default to video/x-flv.
     if (preg_match("/Duration: (\\d+):(\\d+):(\\d+\\.\\d+)/", $result, $matches)) {
         $duration = 3600 * $matches[1] + 60 * $matches[2] + $matches[3];
     } else {
         if (preg_match("/duration.*?:.*?(\\d+)/", $result, $matches)) {
             $duration = $matches[1];
         } else {
             $duration = 0;
         }
     }
     return array($width, $height, $mime_type, $extension, $duration);
 }