function __buildAudio() { $result = FALSE; $c = 0; $y = sizeof(array_keys($this->__mashData['cache_urls'])); foreach ($this->__mashData['cache_urls'] as $url => $true) { $this->_progressStep('CacheFiles', 1 + round(20 * ($c / $y)), 'Caching Media'); $result = cache_url($url, $this->_options['DirCache']); if (!$result) { throw new RuntimeException('Could not cache media file: ' . $url); } $file_path = $result; $ext = file_extension($file_path); switch ($ext) { //case 'mp3': // recent version of ecasound doesn't support seeking mp3s case 'wav': case 'aiff': case 'aif': break; default: // needs to be converted for ecasound $cached_wav = cache_file_wav($file_path, array(), $this->_options['PathFFmpeg']); if (!$cached_wav) { throw new RuntimeException('Could not determine path to audio wav file: ' . $file_path); } if (!empty($this->_options['Verbose'])) { $this->log($cached_wav['command']); } if (!$cached_wav['path']) { throw new RuntimeException('Could not build audio wav file: ' . $file_path); } $file_path = $cached_wav['path']; } $this->__mashData['cache_urls'][$url] = $file_path; $this->_progressStep('CacheFiles', 100, 'Cached Media'); } $this->_progressStep('BuildAudio', 25, 'Building Audio'); $audio_path = $this->_buildDir . 'build/audio.wav'; if ($this->__mashData['has_audio']) { $path = $this->_options['CoderBaseURL']; $cmd = $this->_options['PathEcasound']; $counter = 1; $last_sound = floatval(0); $one = floatval(1); foreach ($this->__mashData['clips'] as $clip) { if (!$clip['audio']) { continue; } // make sure we've got a locally cached file for this url $file_path = $this->__mashData['cache_urls'][$clip['audio']]; if (!$file_path) { throw new RuntimeException('No path for audio URL: ' . $clip['audio']); } $cmd .= ' -a:' . $counter++ . ' -i '; if (floatgtr($clip['loops'], $one)) { $cmd .= ' audioloop,'; } $cmd .= "playat,{$clip['start']},select,{$clip['trimstart']},{$clip['length']},{$file_path}"; if (floatgtr($clip['loops'], $one)) { $cmd .= ' -t:' . $clip['duration'] * $clip['loops']; } $volume = $clip['volume']; $volume = explode(',', $volume); $z = sizeof($volume) / 2; $cmd .= ' -ea:0 -klg:1,0,100,' . $z; for ($i = 0; $i < $z; $i++) { $p = ($i + 1) * 2; $pos = floatval($volume[$p - 2]); $val = floatval($volume[$p - 1]) / floatval(100); if ($pos) { $pos = $clip['length'] * $clip['loops'] * $pos / floatval(100); } $cmd .= ',' . ($clip['start'] + $pos) . ',' . $val; } $last_sound = floatmax($last_sound, $clip['start'] + $clip['length']); } // if there is space at the end, fill it with silence if (floatgtr($this->__mashData['duration'], $last_sound)) { //$this->log('duration = ' . $this->__mashData['duration'] . ' last_sound = ' . $last_sound); $cmd .= ' -a:' . $counter . ' -i '; $cmd .= 'playat,0,tone,sine,0,' . $this->__mashData['duration']; } $cmd .= ' -a:all -z:mixmode,sum'; $cmd .= ' -o ' . $audio_path; } if ($cmd) { $result = $this->_shellExecute($cmd); if (!file_exists($audio_path)) { throw new RuntimeException('Could not build audio: ' . $cmd); } $result = $audio_path; } return $result; }
function scale_switches($orig_dims, $dims, $fill) { $target_w = floatval($dims[0]); $target_h = floatval($dims[1]); $vf = ''; $scale = 'scale=' . $target_w . ':' . $target_h; if ($fill && $fill != 'stretch') { $orig_even_w = floatval($orig_dims[0]); $orig_dims1 = floatval($orig_dims[1]); $extra0 = $orig_even_w % 2; $extra1 = $orig_dims1 % 2; $orig_even_w -= $extra0; $orig_dims1 -= $extra1; $ratio_w = $target_w / $orig_even_w; $ratio_h = $target_h / $orig_dims1; if (!floatcmp($ratio_w, $ratio_h)) { $multiplier = $fill == 'scale' ? floatmin($ratio_w, $ratio_h) : floatmax($ratio_w, $ratio_h); $scaled_w = round($target_w / $multiplier); $scaled_h = round($target_h / $multiplier); if (!floatcmp($orig_even_w, $scaled_w)) { if (floatgtr($orig_even_w, $scaled_w)) { //$a['cropleft'] = $a['cropright'] = floor((($orig_even_w - $scaled_w) / 2)); $vf .= 'crop=' . floor(($orig_even_w - $scaled_w) / 2) . ':0:' . $scaled_w . ':' . $scaled_h; } else { /*$pad_x = $pad_width = floor(($scaled_w -$orig_even_w) / 2); $pad_x -= $extra0; $dims[0] -= 2 * $pad_width; $dims[0] += $extra0; $dims[1] += $extra1; */ $vf .= 'pad=' . $scaled_w . ':' . $scaled_h . ':' . (floor(($scaled_w - $orig_even_w) / 2) - $extra0) . ':0'; } } if (!floatcmp($orig_dims1, $scaled_h)) { if (floatgtr($orig_dims1, $scaled_h)) { $vf .= 'crop=0:' . floor(($orig_dims1 - $scaled_h) / 2) . ':' . $scaled_w . ':' . $scaled_h; } else { /* $pad_y = $pad_height = floor(($scaled_h - $orig_dims1) / 2); $pad_y -= $extra1; $dims[1] -= 2 * $pad_height; $dims[1] += $extra1; $dims[0] += $extra0; */ $vf .= 'pad=' . $scaled_w . ':' . $scaled_h . ':0:' . (floor(($scaled_h - $orig_dims1) / 2) - $extra1); } } } //$a['s'] = $dims[0] . 'x' . $dims[1]; } if ($vf) { $vf .= ','; } $vf .= $scale; $a = array(); $a['vf'] = $vf; return $a; }