Ejemplo n.º 1
0
/**
 * Divine file format with getID3
 * @param $ps_path
 * @return bool|string
 */
function caGetID3GuessFileFormat($ps_path)
{
    if ($va_getid3_info = caExtractMetadataWithGetID3($ps_path)) {
        if ($va_getid3_info['mime_type']) {
            return $va_getid3_info["mime_type"];
        }
    }
    return false;
}
Ejemplo n.º 2
0
 public function read($filepath)
 {
     if (!file_exists($filepath)) {
         $this->postError(1650, _t("File %1 does not exist", $filepath), "WLPlugVideo->read()");
         $this->opa_media_metadata = array();
         $this->filepath = null;
         return false;
     }
     if (!($this->opa_media_metadata && $this->opa_media_metadata["filepath"] == $filepath)) {
         // first try mediainfo
         if ($vs_mimetype = caMediaInfoGuessFileFormat($filepath)) {
             $va_media_metadata = caExtractMetadataWithMediaInfo($filepath);
             $va_media_metadata['filepath'] = $filepath;
             $va_media_metadata['mime_type'] = $vs_mimetype;
             // Set properties for framerate and starting timecode
             $o_tc = new TimecodeParser();
             $o_tc->setTimebase($vn_framerate = trim(str_replace("fps", "", $va_media_metadata['VIDEO']['Frame rate'])));
             $o_tc->parse($va_media_metadata['OTHER']['Time code of first frame']);
             $this->properties['timecode_offset'] = (int) $o_tc->getSeconds();
             $this->properties['framerate'] = $vn_framerate;
             $this->opa_media_metadata = $va_media_metadata;
         } elseif ($vs_mimetype = caGetID3GuessFileFormat($filepath)) {
             // then try getid3
             $this->opa_media_metadata = caExtractMetadataWithGetID3($filepath);
             $this->properties['timecode_offset'] = 0;
             // getID3 doesn't return offsets
             $this->properties['framerate'] = (double) $this->opa_media_metadata['video']['frame_rate'];
         } else {
             // lastly, try ogg/ogv
             $this->opa_media_metadata = caExtractMediaMetadataWithOggParser($filepath);
             $this->properties['timecode_offset'] = 0;
             // OggParser doesn't return offsets
             $this->properties['framerate'] = (double) $this->opa_media_metadata['duration'] > 0 ? (double) $this->opa_media_metadata['framecount'] / (double) $this->opa_media_metadata['duration'] : 0;
         }
     }
     if (!$this->opa_media_metadata['mime_type']) {
         return false;
     }
     // divineFileFormat() should prevent that, but you never know
     $w = $h = null;
     if (!(isset($this->opa_media_metadata["error"]) && is_array($this->opa_media_metadata["error"]) && sizeof($this->opa_media_metadata["error"]) > 0)) {
         $this->filepath = $filepath;
         // getID3 sometimes reports the wrong width and height in the resolution_x and resolution_y indices for FLV files, but does
         // report correct values in the 'meta' block. So for FLV only we try to take values from the 'meta' block first.
         if ($this->opa_media_metadata["mime_type"] == 'video/x-flv' && is_array($this->opa_media_metadata['meta']) && is_array($this->opa_media_metadata['meta']['onMetaData'])) {
             $w = $this->opa_media_metadata['meta']['onMetaData']['width'];
             $h = $this->opa_media_metadata['meta']['onMetaData']['height'];
         } else {
             if ($this->opa_media_metadata['mime_type'] == 'video/ogg') {
                 $w = $this->opa_media_metadata['theora']['width'];
                 $h = $this->opa_media_metadata['theora']['height'];
             }
         }
         if (!$w || !$h) {
             $w = $this->opa_media_metadata["video"]["resolution_x"];
             $h = $this->opa_media_metadata["video"]["resolution_y"];
         }
         if (!$w || !$h) {
             // maybe it's stuck in a stream?
             if (is_array($this->opa_media_metadata["video"]["streams"])) {
                 foreach ($this->opa_media_metadata["video"]["streams"] as $vs_key => $va_stream_info) {
                     $w = $this->opa_media_metadata["video"]["streams"][$vs_key]["resolution_x"];
                     $h = $this->opa_media_metadata["video"]["streams"][$vs_key]["resolution_y"];
                     if ($w > 0 && $h > 0) {
                         break;
                     }
                 }
             }
         }
         // maybe it came from mediainfo?
         if (!$w || !$h) {
             if (isset($this->opa_media_metadata['VIDEO']['Width'])) {
                 $w = preg_replace("/[\\D]/", '', $this->opa_media_metadata['VIDEO']['Width']);
             }
             if (isset($this->opa_media_metadata['VIDEO']['Height'])) {
                 $h = preg_replace("/[\\D]/", '', $this->opa_media_metadata['VIDEO']['Height']);
             }
         }
         $this->properties["width"] = $w;
         $this->properties["height"] = $h;
         $this->properties["mimetype"] = $this->opa_media_metadata["mime_type"];
         $this->properties["typename"] = $this->typenames[$this->properties["mimetype"]] ? $this->typenames[$this->properties["mimetype"]] : "Unknown";
         $this->properties["duration"] = $this->opa_media_metadata["playtime_seconds"];
         // getID3 sometimes messes up the duration. mediainfo seems a little more reliable so use it if it's available
         if ($this->opb_mediainfo_available && ($vn_mediainfo_duration = caExtractVideoFileDurationWithMediaInfo($filepath))) {
             $this->properties['duration'] = $this->opa_media_metadata["playtime_seconds"] = $vn_mediainfo_duration;
         }
         $this->properties["filesize"] = filesize($filepath);
         # -- get bandwidth
         switch ($this->properties["mimetype"]) {
             // in this case $this->opa_media_metadata definitely came from mediainfo
             // so the array structure is a little different than getID3
             case 'video/x-dv':
                 $this->properties["has_video"] = isset($this->opa_media_metadata["VIDEO"]["Duration"]) ? 1 : 0;
                 $this->properties["has_audio"] = isset($this->opa_media_metadata["AUDIO"]["Duration"]) ? 1 : 0;
                 $this->properties["type_specific"] = array();
                 $this->properties["title"] = $this->opa_media_metadata["GENERAL"]["Complete name"];
                 $this->properties["author"] = "";
                 $this->properties["copyright"] = "";
                 $this->properties["description"] = "";
                 $vn_bitrate = preg_replace("/[\\D]/", '', $this->opa_media_metadata['VIDEO']['Bit rate']);
                 $this->properties["bandwidth"] = array("min" => 0, "max" => $vn_bitrate);
                 break;
             case 'video/x-ms-asf':
             case 'video/x-ms-wmv':
                 $this->properties["has_video"] = sizeof($this->opa_media_metadata["asf"]["video_media"]) ? 1 : 0;
                 $this->properties["has_audio"] = sizeof($this->opa_media_metadata["asf"]["audio_media"]) ? 1 : 0;
                 $this->properties["type_specific"] = array("asf" => $this->opa_media_metadata["asf"]);
                 $this->properties["title"] = $this->opa_media_metadata["asf"]["comments"]["title"];
                 $this->properties["author"] = $this->opa_media_metadata["asf"]["comments"]["artist"];
                 $this->properties["copyright"] = $this->opa_media_metadata["asf"]["comments"]["copyright"];
                 $this->properties["description"] = $this->opa_media_metadata["asf"]["comments"]["comment"];
                 $this->properties["bandwidth"] = array("min" => 0, "max" => $this->opa_media_metadata["bitrate"]);
                 break;
             case 'video/quicktime':
             case 'video/mp4':
                 $this->properties["has_video"] = isset($this->opa_media_metadata["video"]["bitrate"]) && sizeof($this->opa_media_metadata["video"]["bitrate"]) ? 1 : 0;
                 $this->properties["has_audio"] = isset($this->opa_media_metadata["audio"]["bitrate"]) && sizeof($this->opa_media_metadata["audio"]["bitrate"]) ? 1 : 0;
                 $this->properties["type_specific"] = array();
                 $this->properties["title"] = "";
                 $this->properties["author"] = "";
                 $this->properties["copyright"] = "";
                 $this->properties["description"] = "";
                 $this->properties["bandwidth"] = array("min" => (int) $this->opa_media_metadata["theora"]['nombitrate'] + (int) $this->opa_media_metadata["vorbis"]['bitrate'], "max" => (int) $this->opa_media_metadata["theora"]['nombitrate'] + (int) $this->opa_media_metadata["vorbis"]['bitrate']);
                 break;
             case 'video/ogg':
                 $this->properties["has_video"] = isset($this->opa_media_metadata["theora"]) ? 1 : 0;
                 $this->properties["has_audio"] = isset($this->opa_media_metadata["vorbis"]) ? 1 : 0;
                 $this->properties["type_specific"] = array();
                 $this->properties["title"] = "";
                 $this->properties["author"] = "";
                 $this->properties["copyright"] = "";
                 $this->properties["description"] = "";
                 $this->properties["bandwidth"] = array("min" => $this->opa_media_metadata["bitrate"], "max" => $this->opa_media_metadata["bitrate"]);
                 break;
             case 'application/x-shockwave-flash':
                 $this->properties["has_video"] = $this->opa_media_metadata["header"]["frame_width"] > 0 ? 1 : 0;
                 $this->properties["has_audio"] = 1;
                 $this->properties["type_specific"] = array("header" => $this->opa_media_metadata["header"]);
                 $this->properties["title"] = "";
                 $this->properties["author"] = "";
                 $this->properties["copyright"] = "";
                 $this->properties["description"] = "";
                 $this->properties["bandwidth"] = array("min" => $this->opa_media_metadata["filesize"] / $this->opa_media_metadata["playtime_seconds"], "max" => $this->opa_media_metadata["filesize"] / $this->opa_media_metadata["playtime_seconds"]);
                 break;
             case 'video/mpeg':
                 $this->properties["has_video"] = isset($this->opa_media_metadata["video"]["bitrate"]) && sizeof($this->opa_media_metadata["video"]["bitrate"]) ? 1 : 0;
                 $this->properties["has_audio"] = isset($this->opa_media_metadata["audio"]["bitrate"]) && sizeof($this->opa_media_metadata["audio"]["bitrate"]) ? 1 : 0;
                 $this->properties["type_specific"] = array();
                 $this->properties["title"] = "";
                 $this->properties["author"] = "";
                 $this->properties["copyright"] = "";
                 $this->properties["description"] = "";
                 $this->properties["bandwidth"] = array("min" => $this->opa_media_metadata["bitrate"], "max" => $this->opa_media_metadata["bitrate"]);
                 break;
             case 'video/x-flv':
                 $this->properties["has_video"] = sizeof($this->opa_media_metadata["header"]["hasVideo"]) ? 1 : 0;
                 $this->properties["has_audio"] = sizeof($this->opa_media_metadata["header"]["hasAudio"]) ? 1 : 0;
                 $this->properties["type_specific"] = array("header" => $this->opa_media_metadata["header"]);
                 $this->properties["title"] = "";
                 $this->properties["author"] = "";
                 $this->properties["copyright"] = "";
                 $this->properties["description"] = "";
                 $vn_bitrate = $this->opa_media_metadata["filesize"] / $this->opa_media_metadata["playtime_seconds"];
                 $this->properties["bandwidth"] = array("min" => $vn_bitrate, "max" => $vn_bitrate);
                 break;
         }
         $this->oproperties = $this->properties;
         return 1;
     } else {
         $this->postError(1650, join("; ", $this->opa_media_metadata["error"]), "WLPlugVideo->read()");
         $this->opa_media_metadata = "";
         $this->filepath = "";
         return false;
     }
 }