function _codeFile() { $file_name = ''; $file_path = cache_url($this->_options['EncoderURL'], $this->_options['DirCache']); if (!$file_path) { throw new RuntimeException('Could not cache: ' . $this->_options['EncoderURL']); } $ext = file_extension($file_path); if (!set_file_info($file_path, 'extension', $ext)) { throw new RuntimeException('Could not set extension cache info: ' . $file_path); } switch ($ext) { case 'jpeg': case 'jpg': case 'png': case 'ping': case 'wbmp': case 'bmp': case 'gif': case 'giff': $this->__buildImage($file_path); break; default: // encode audio if (empty($this->_options['CoderNoAudio'])) { $this->__buildAudio($file_path); } else { $duration = get_file_info('duration', $file_path, $this->_options['PathFFmpeg']); if (!$duration) { throw new RuntimeException('Could not determine audio duration'); } } // encode images and video if (!$this->_options['CoderNoVideo']) { $this->__buildSequence($file_path); } } if (empty($this->_options['EncoderIncludeOriginal'])) { $this->_ignore[] = $file_path; } $file_name = dir_path($file_path); return $file_name; }
function __buildVisuals($start, $stop) { $path = $this->_options['CoderBaseURL']; $result = array(); $clips = MovieMasher_Coder_Decoder::videoBetween($this->__mashData['clips'], $start, $stop); $fps = floatval($this->_options['DecoderFPS']); $z = sizeof($clips); for ($i = 0; $i < $z; $i++) { $clip = $clips[$i]; // id, type, tag, start, stop, duration (as floats) $clip_trim = $this->__clipTrim($clip, $start, $stop, $fps); if (!$clip_trim) { throw new UnexpectedValueException('Could not determine clip trim: ' . $clip['id']); } $media_tag = $this->__mashData['media'][$clip['id']]; $cmd = ''; $cmd .= $this->_options['PathFFmpeg']; $dims = explode('x', $this->_options['DecoderDimensions']); $url = (string) $media_tag['source']; if (!$url) { $url = (string) $media_tag['url']; } $url = absolute_url(end_with_slash($this->_options['CoderBaseURL']), $url); $url = MovieMasher_Coder::cleanURL($url); switch ($clip['type']) { case 'image': $file_path = cache_url($url, $this->_options['DirCache']); if (!$file_path) { throw new RuntimeException('Could not cache image: ' . $url); } $orig_dims = get_file_info('dimensions', $file_path, $this->_options['PathFFmpeg']); if (!$orig_dims) { throw new RuntimeException('Could not determine image dimensions: ' . $url); } $orig_dims = explode('x', $orig_dims); $switches = scale_switches($orig_dims, $dims, $clip['fill']); $cmd .= ' -loop_input -vframes ' . floor($fps * $clip_trim['trimlength']); $cmd .= ' -s ' . $orig_dims[0] . 'x' . $orig_dims[1]; $cmd .= ' -i ' . $file_path; if ($switches) { $cmd .= ' ' . stringFromSwitches($switches); } else { $cmd .= ' -s ' . $this->_options['DecoderDimensions']; } break; case 'video': $video = (string) $media_tag['source']; $video = MovieMasher_Coder::cleanURL($video); if ($video) { $url = absolute_url(end_with_slash($this->_options['CoderBaseURL']), $video); } $ext = file_extension($url); if ($ext) { // grab the video file $input_path = $file_path = cache_url($url, $this->_options['DirCache']); if (!$file_path) { throw new RuntimeException('Could not cache video: ' . $url); } } else { // grab image sequence - very untested $clip_fps = floatval((string) $media_tag['fps']); $fps_secs = floatval(1) / $clip_fps; $clip_trim['trimstart'] = floor($clip_trim['trimstart'] / $fps_secs) * $fps_secs; $cmd .= ' -r ' . $clip_fps; $file_path = url_file_path($url, $this->_options['DirCache']); $orig_dims = get_file_info('dimensions', $file_path, $this->_options['PathFFmpeg']); if (!$orig_dims) { throw new RuntimeException('Could not determine image sequence dimensions: ' . $url); } $input_path = frame_file_path($file_path, $orig_dims, $clip_fps); $input_path .= '%' . intval($media_tag['zeropadding']) . 'd.jpg'; $fps = $clip_fps; } $orig_dims = get_file_info('dimensions', $file_path, $this->_options['PathFFmpeg']); if (!$orig_dims) { throw new RuntimeException('Could not determine dimensions: ' . $file_path . ' ' . $this->_options['PathFFmpeg']); } $orig_dims = explode('x', $orig_dims); $switches = scale_switches($orig_dims, $dims, $clip['fill']); $cmd .= ' -vframes ' . floor($fps * $clip_trim['trimlength']); $cmd .= ' -s ' . $orig_dims[0] . 'x' . $orig_dims[1]; $cmd .= ' -i ' . $input_path; if ($clip_trim['trimstart']) { $cmd .= ' -ss ' . $clip_trim['trimstart']; } $cmd .= ' -an'; // no audio if ($switches) { $cmd .= ' ' . stringFromSwitches($switches); } else { $cmd .= ' -s ' . $this->_options['DecoderDimensions']; } break; } $cmd .= ' -t ' . $clip_trim['trimlength']; $result[] = $cmd; } return $result; }
function get_url_info($type, $url, $dir_path, $ffmpeg = '') { $result = FALSE; $file_path = cache_url($url, $dir_path); if ($file_path) { $result = get_file_info($type, $file_path, $ffmpeg); } return $result; }
function get_cached_page($length = 0) { if (CACHE_PAGE && empty($_POST)) { if (intval($length) <= 0) { $length = CACHE_LENGTH; } $file = ROOT . 'cache/pages/' . md5(cache_url()) . '.php'; if (file_exists($file) && TIME - filemtime($file) <= $length) { $data = unserialize(file_get_contents($file)); $content = $data['content']; $content .= "\n<!-- From Cache: " . serve_time() . " seconds -->"; if ($data['Content-Type'] != '') { header('Content-Type: ' . $data['Content-Type']); } # header('HTTP/1.1 304 Not Modified'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($file)) . ' GMT'); header('Content-Length: ' . strlen($content)); echo $content; exit; } } return false; }