function cache_url_frames($vid_url, $fps, $start = 0, $duration = -1, $dir_path, $options = array(), $switches = array(), $ffmpeg = '') { $result = FALSE; $ext = file_extension($vid_url); if ($ext) { $vid_file_path = cache_url($vid_url, $dir_path); if ($vid_file_path) { $result = cache_file_frames($vid_file_path, $fps, $start, $duration, $options, $switches, $ffmpeg); } } return $result; }
function __cacheMedia() { $fps = floatval($this->_options['DecoderFPS']); // cache frames for all video files used in flash $z = sizeof($this->__mashData['timespans']); for ($i = 0; $i < $z; $i++) { $span = $this->__mashData['timespans'][$i]; $span_start = $span[0]; $span_end = $span[0] + $span[1]; $clips = MovieMasher_Coder_Decoder::videoBetween($this->__mashData['clips'], $span_start, $span_end); $this->_progressStep('CacheFiles', 1 + round(30 * ($i / $z)), 'Caching Frames'); foreach ($clips as $clip) { if (empty($clip['encode'])) { continue; } $clip_trim = $this->__clipTrim($clip, $span_start, $span_end, $fps); if (!$clip_trim) { throw new UnexpectedValueException('Could not get clip info: ' . $clip['id']); } $media_tag = $this->__mashData['media'][$clip['id']]; $url = (string) $media_tag['source']; $url = absolute_url(end_with_slash($this->_options['CoderBaseURL']), $url); $ext = file_extension($url); if (!$ext) { throw new UnexpectedValueException('Media source attributes must have a file extension: ' . $url); } $vid_file_path = cache_url($url, $this->_options['DirCache']); if (!$vid_file_path) { throw new UnexpectedValueException('Could not cache URL: ' . $url); } $options = array(); $orig_dimensions = get_file_info('dimensions', $vid_file_path, $this->_options['PathFFmpeg']); if (!$orig_dimensions) { throw new RuntimeException('Could not read dimensions: ' . $vid_file_path); } $target_dimensions = scale_proud($orig_dimensions, $this->_options['DecoderDimensions']); if (!$target_dimensions) { $target_dimensions = $this->_options['DecoderDimensions']; } $options['dimensions'] = $target_dimensions; $options['bitrate'] = 8000; // max? $options['dimensions_dir'] = $this->_options['DecoderDimensions']; $options['duration'] = $clip['duration']; $switches = array(); $fps_secs = floatval(1) / $this->__mashData['quantize']; // we need an extra frame in mash's fps if ($clip_trim['trimstart']) { $clip_trim['trimstart'] -= $fps_secs; $clip_trim['trimlength'] += $fps_secs; } $clip_trim['trimlength'] += $fps_secs; if ($clip['speed'] != 1 || !empty($this->_options['DecoderCacheAllVideoFrames'])) { // TODO: don't cache all the frames when speed isn't normal $clip_trim['trimstart'] = 0; $clip_trim['trimlength'] = -1; } //$this->log('Caching ' . ((string) $media_tag['label']) . ' @ ' . $this->_options['DecoderFPS'] . ' ' . $clip_trim['trimstart'] . ' -> ' . $clip_trim['trimlength']); $cached_frames = cache_file_frames($vid_file_path, $this->_options['DecoderFPS'], $clip_trim['trimstart'], $clip_trim['trimlength'], $options, $switches, $this->_options['PathFFmpeg']); if (!$cached_frames) { throw new RuntimeException('Could not prepare to cache image sequence: ' . $url); } if (!empty($this->_options['Verbose']) && !empty($cached_frames['command'])) { $this->log($cached_frames['command'] . "\n" . $cached_frames['result']); } if (!$cached_frames['files']) { throw new RuntimeException('Could not cache image sequence: ' . $url); } $media_tag['url'] = 'http://' . $this->getOption('HostLocal') . '/mm.' . $this->getVersion() . '/cache/' . frame_file_path(url_file_path($url), $this->_options['DecoderDimensions'], $this->_options['DecoderFPS']); } } // cache the non-flash video content $zero = floatval(0); $cur_time = $zero; $z = sizeof($this->__mashData['timespans']); for ($i = 0; $i < $z; $i++) { if (floatgtr($this->__mashData['timespans'][$i][0], $cur_time)) { // first timespan doesn't start where the last left off, so there is something between $this->__cacheVisuals($cur_time, $this->__mashData['timespans'][$i][0]); } $cur_time = $this->__mashData['timespans'][$i][1]; $this->_progressStep('CacheFiles', 30 + (1 + round(30 * ($i / $z))), 'Caching Visuals'); } if (!floatcmp($cur_time, $this->__mashData['duration'])) { // last timespan doesn't end the mash, so there is stuff after it $this->__cacheVisuals($cur_time, $this->__mashData['duration']); } // cache audio and video with audio files $i = 0; $z = sizeof(array_keys($this->__mashData['cache_urls'])); foreach ($this->__mashData['cache_urls'] as $url => $true) { $this->_progressStep('CacheFiles', 60 + (1 + round(30 * ($i++ / $z))), 'Caching Audio'); $result = cache_url($url, $this->_options['DirCache']); if (!$result) { throw new RuntimeException('Could not cache audio: ' . $url); } } $this->_progressStep('CacheFiles', 100, 'Cached Media'); }
function __buildSequence($file_path) { $this->_progressStep('EncodeVideo', 5, 'Encoding Video'); if (isset($this->_options['EncoderExtension'])) { $options = array(); $orig_dimensions = get_file_info('dimensions', $file_path); if (!$orig_dimensions) { throw new RuntimeException('Could not read dimensions: ' . $file_path); } $target_dimensions = scale_proud($orig_dimensions, $this->_options['EncoderDimensions']); if (!$target_dimensions) { $target_dimensions = $this->_options['EncoderDimensions']; } $target_size = explode('x', $target_dimensions); $options['bitrate'] = round($this->_options['EncoderImageQuality'] / 100 * ($target_size[0] * $target_size[1] * 3 * $this->_options['EncoderFPS'] / 1024)); $options['dimensions'] = $target_dimensions; $options['dimensions_dir'] = $this->_options['EncoderDimensions']; $switches = switchesFromString($this->_options['EncoderSwitches']); $cached_frames = cache_file_frames($file_path, $this->_options['EncoderFPS'], 0, -1, $options, $switches, $this->_options['PathFFmpeg']); if (!$cached_frames) { throw new RuntimeException('Could not prepare to cache image sequence: ' . $file_path); } if (!empty($this->_options['Verbose']) && !empty($cached_frames['command'])) { $this->log($cached_frames['command'] . "\n" . $cached_frames['result']); } if (!$cached_frames['files']) { throw new RuntimeException('Could not cache image sequence: ' . $file_path); } $this->_progressStep('EncodeVideo', 100, 'Encoded Video'); } }